diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2013-12-20 15:30:48 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2013-12-20 15:30:48 +0900 |
commit | 159dd7f06926441f6476ab86bd673281b67f5fe4 (patch) | |
tree | 5fccdce34352679044f33b9c096572bbc4e880c4 /test | |
parent | b30f21e07416e20a41e00ef5e55b8e22ef006eb4 (diff) |
Implement smart-case match (#12)
Diffstat (limited to 'test')
-rw-r--r-- | test/test_fzf.rb | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/test/test_fzf.rb b/test/test_fzf.rb index 98818d75..8133c22c 100644 --- a/test/test_fzf.rb +++ b/test/test_fzf.rb @@ -9,10 +9,10 @@ load 'fzf' class TestFZF < MiniTest::Unit::TestCase def test_default_options fzf = FZF.new [] - assert_equal 1000, fzf.sort + assert_equal 1000, fzf.sort assert_equal false, fzf.multi - assert_equal true, fzf.color - assert_equal Regexp::IGNORECASE, fzf.rxflag + assert_equal true, fzf.color + assert_equal nil, fzf.rxflag begin ENV['FZF_DEFAULT_SORT'] = '1500' @@ -152,15 +152,59 @@ class TestFZF < MiniTest::Unit::TestCase # TODO : partial_cache end + def test_fuzzy_matcher_rxflag + assert_equal nil, FZF::FuzzyMatcher.new(nil).rxflag + assert_equal 0, FZF::FuzzyMatcher.new(0).rxflag + assert_equal 1, FZF::FuzzyMatcher.new(1).rxflag + + assert_equal 1, FZF::FuzzyMatcher.new(nil).rxflag_for('abc') + assert_equal 0, FZF::FuzzyMatcher.new(nil).rxflag_for('Abc') + assert_equal 0, FZF::FuzzyMatcher.new(0).rxflag_for('abc') + assert_equal 0, FZF::FuzzyMatcher.new(0).rxflag_for('Abc') + assert_equal 1, FZF::FuzzyMatcher.new(1).rxflag_for('abc') + assert_equal 1, FZF::FuzzyMatcher.new(1).rxflag_for('Abc') + end + def test_fuzzy_matcher_case_sensitive + # Smart-case match (Uppercase found) + assert_equal [['Fruit', [[0, 5]]]], + FZF::FuzzyMatcher.new(nil).match(%w[Fruit Grapefruit], 'Fruit', '', '').sort + + # Smart-case match (Uppercase not-found) + assert_equal [["Fruit", [[0, 5]]], ["Grapefruit", [[5, 10]]]], + FZF::FuzzyMatcher.new(nil).match(%w[Fruit Grapefruit], 'fruit', '', '').sort + + # Case-sensitive match (-i) assert_equal [['Fruit', [[0, 5]]]], FZF::FuzzyMatcher.new(0).match(%w[Fruit Grapefruit], 'Fruit', '', '').sort + # Case-insensitive match (+i) assert_equal [["Fruit", [[0, 5]]], ["Grapefruit", [[5, 10]]]], FZF::FuzzyMatcher.new(Regexp::IGNORECASE). match(%w[Fruit Grapefruit], 'Fruit', '', '').sort end + def test_extended_fuzzy_matcher_case_sensitive + %w['Fruit Fruit$].each do |q| + # Smart-case match (Uppercase found) + assert_equal [['Fruit', [[0, 5]]]], + FZF::ExtendedFuzzyMatcher.new(nil).match(%w[Fruit Grapefruit], q, '', '').sort + + # Smart-case match (Uppercase not-found) + assert_equal [["Fruit", [[0, 5]]], ["Grapefruit", [[5, 10]]]], + FZF::ExtendedFuzzyMatcher.new(nil).match(%w[Fruit Grapefruit], q.downcase, '', '').sort + + # Case-sensitive match (-i) + assert_equal [['Fruit', [[0, 5]]]], + FZF::ExtendedFuzzyMatcher.new(0).match(%w[Fruit Grapefruit], q, '', '').sort + + # Case-insensitive match (+i) + assert_equal [["Fruit", [[0, 5]]], ["Grapefruit", [[5, 10]]]], + FZF::ExtendedFuzzyMatcher.new(Regexp::IGNORECASE). + match(%w[Fruit Grapefruit], q, '', '').sort + end + end + def test_extended_fuzzy_matcher matcher = FZF::ExtendedFuzzyMatcher.new Regexp::IGNORECASE list = %w[ |