Fix test failure on Ruby 1.8.7

Hashes are unordered on Ruby 1.8
This commit is contained in:
Junegunn Choi 2014-11-04 19:32:31 +09:00
parent da03a66e69
commit 7571baadb4

View File

@ -33,6 +33,7 @@ class MockTTY
end end
def getc def getc
sleep 0.1
while true while true
@mutex.synchronize do @mutex.synchronize do
if char = take(1) if char = take(1)
@ -627,6 +628,10 @@ class TestFZF < MiniTest::Unit::TestCase
stream = stream_for given stream = stream_for given
output = stream_for '' output = stream_for ''
def sorted_lines line
line.split($/).sort
end
begin begin
tty = MockTTY.new tty = MockTTY.new
$stdout = output $stdout = output
@ -637,7 +642,7 @@ class TestFZF < MiniTest::Unit::TestCase
thr && thr.join thr && thr.join
rescue SystemExit => e rescue SystemExit => e
assert_equal 0, e.status assert_equal 0, e.status
assert_equal expected, output.string.chomp assert_equal sorted_lines(expected), sorted_lines(output.string)
ensure ensure
$stdout = STDOUT $stdout = STDOUT
end end
@ -775,37 +780,29 @@ class TestFZF < MiniTest::Unit::TestCase
end end
def test_with_nth_mock_tty def test_with_nth_mock_tty
d = 0.1
# Manual selection with input # Manual selection with input
assert_fzf_output ["--with-nth=2,1"], "hello world", "hello world" do |tty| assert_fzf_output ["--with-nth=2,1"], "hello world", "hello world" do |tty|
tty << "world" tty << "world"
tty << "hell" tty << "hell"
sleep d
tty << "\r" tty << "\r"
end end
# Manual selection without input # Manual selection without input
assert_fzf_output ["--with-nth=2,1"], "hello world", "hello world" do |tty| assert_fzf_output ["--with-nth=2,1"], "hello world", "hello world" do |tty|
sleep d
tty << "\r" tty << "\r"
end end
# Manual selection with input and --multi # Manual selection with input and --multi
lines = "hello world\ngoodbye world" lines = "hello world\ngoodbye world"
assert_fzf_output %w[-m --with-nth=2,1], lines, lines do |tty| assert_fzf_output %w[-m --with-nth=2,1], lines, lines do |tty|
sleep d
tty << "o" tty << "o"
sleep d
tty << "\e[Z\e[Z" tty << "\e[Z\e[Z"
sleep d
tty << "\r" tty << "\r"
end end
# Manual selection without input and --multi # Manual selection without input and --multi
assert_fzf_output %w[-m --with-nth=2,1], lines, lines do |tty| assert_fzf_output %w[-m --with-nth=2,1], lines, lines do |tty|
sleep d
tty << "\e[Z\e[Z" tty << "\e[Z\e[Z"
sleep d
tty << "\r" tty << "\r"
end end
end end