summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-04-16 14:19:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-04-16 14:19:28 +0900
commitb8904a8c3e8f6d8c00c8d69b153c0d1897b1ade2 (patch)
tree7fd46744a6fd3d9f63657634d6d32a4ba09b140c /test
parent48ab87294bb2df5ff32ff35a16231991a2e0887b (diff)
Add --tiebreak option for customizing sort criteria
Close #191
Diffstat (limited to 'test')
-rw-r--r--test/test_go.rb61
1 files changed, 54 insertions, 7 deletions
diff --git a/test/test_go.rb b/test/test_go.rb
index a9284b66..abf0496e 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -476,18 +476,65 @@ class TestGoFZF < TestBase
def test_unicode_case
tempname = TEMPNAME + Time.now.to_f.to_s
- File.open(tempname, 'w') do |f|
- f << %w[строКА1 СТРОКА2 строка3 Строка4].join($/)
+ writelines tempname, %w[строКА1 СТРОКА2 строка3 Строка4]
+ assert_equal %w[СТРОКА2 Строка4], `cat #{tempname} | #{FZF} -fС`.split($/)
+ assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `cat #{tempname} | #{FZF} -fс`.split($/)
+ rescue
+ File.unlink tempname
+ end
+
+ def test_tiebreak
+ tempname = TEMPNAME + Time.now.to_f.to_s
+ input = %w[
+ --foobar--------
+ -----foobar---
+ ----foobar--
+ -------foobar-
+ ]
+ writelines tempname, input
+
+ assert_equal input, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=index`.split($/)
+
+ by_length = %w[
+ ----foobar--
+ -----foobar---
+ -------foobar-
+ --foobar--------
+ ]
+ assert_equal by_length, `cat #{tempname} | #{FZF} -ffoobar`.split($/)
+ assert_equal by_length, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=length`.split($/)
+
+ by_begin = %w[
+ --foobar--------
+ ----foobar--
+ -----foobar---
+ -------foobar-
+ ]
+ assert_equal by_begin, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=begin`.split($/)
+ assert_equal by_begin, `cat #{tempname} | #{FZF} -f"!z foobar" -x --tiebreak begin`.split($/)
+
+ assert_equal %w[
+ -------foobar-
+ ----foobar--
+ -----foobar---
+ --foobar--------
+ ], `cat #{tempname} | #{FZF} -ffoobar --tiebreak end`.split($/)
+
+ assert_equal input, `cat #{tempname} | #{FZF} -f"!z" -x --tiebreak end`.split($/)
+ rescue
+ File.unlink tempname
+ end
+
+private
+ def writelines path, lines, timeout = 10
+ File.open(path, 'w') do |f|
+ f << lines.join($/)
f.sync
end
since = Time.now
- while `cat #{tempname}`.split($/).length != 4 && (Time.now - since) < 10
+ while `cat #{path}`.split($/).length != lines.length && (Time.now - since) < 10
sleep 0.1
end
- assert_equal %w[СТРОКА2 Строка4], `cat #{tempname} | #{FZF} -fС`.split($/)
- assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `cat #{tempname} | #{FZF} -fс`.split($/)
- rescue
- File.unlink tempname
end
end