diff options
| author | Stephen Blott | 2012-11-05 09:01:39 +0000 |
|---|---|---|
| committer | Stephen Blott | 2012-11-05 09:01:39 +0000 |
| commit | d0157d93d24c8c7f1a86289efe29e203d98bb072 (patch) | |
| tree | aaaab07f3951dde1d8ab74f57b4a7bfdea0a98f1 /tests/unit_tests/completion_test.coffee | |
| parent | e5aa0993b7353b16308f7dbfd0a1e217264c2cae (diff) | |
| download | vimium-d0157d93d24c8c7f1a86289efe29e203d98bb072.tar.bz2 | |
Factor pushMatchingRanges, improve comments/tests
1. Factor out `pushMatchingRanges`:
This then allows us to ...
2. Add unit tests for `pushMatchingRanges`
In effect, these tests verify where matches are highlighted in suggestions.
3. Added Utils.zip. This helps simplify `pushMatchingRanges` unit tests.
4. Improve comments.
Diffstat (limited to 'tests/unit_tests/completion_test.coffee')
| -rw-r--r-- | tests/unit_tests/completion_test.coffee | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee index f978c57b..3de1d716 100644 --- a/tests/unit_tests/completion_test.coffee +++ b/tests/unit_tests/completion_test.coffee @@ -152,6 +152,34 @@ context "suggestions", suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords", returns(1)) assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com") + should "extract ranges matching term (simple case, two matches)", -> + ranges = [] + [ one, two, three ] = [ "one", "two", "three" ] + suggestion = new Suggestion([], "", "", "", returns(1)) + suggestion.pushMatchingRanges("#{one}#{two}#{three}#{two}#{one}", two, ranges) + assert.equal 2, Utils.zip([ ranges, [ [3,6], [11,14] ] ]).filter((pair) -> pair[0][0] == pair[1][0] and pair[0][1] == pair[1][1]).length + + should "extract ranges matching term (two matches, one at start of string)", -> + ranges = [] + [ one, two, three ] = [ "one", "two", "three" ] + suggestion = new Suggestion([], "", "", "", returns(1)) + suggestion.pushMatchingRanges("#{two}#{three}#{two}#{one}", two, ranges) + assert.equal 2, Utils.zip([ ranges, [ [0,3], [8,11] ] ]).filter((pair) -> pair[0][0] == pair[1][0] and pair[0][1] == pair[1][1]).length + + should "extract ranges matching term (two matches, one at end of string)", -> + ranges = [] + [ one, two, three ] = [ "one", "two", "three" ] + suggestion = new Suggestion([], "", "", "", returns(1)) + suggestion.pushMatchingRanges("#{one}#{two}#{three}#{two}", two, ranges) + assert.equal 2, Utils.zip([ ranges, [ [3,6], [11,14] ] ]).filter((pair) -> pair[0][0] == pair[1][0] and pair[0][1] == pair[1][1]).length + + should "extract ranges matching term (no matches)", -> + ranges = [] + [ one, two, three ] = [ "one", "two", "three" ] + suggestion = new Suggestion([], "", "", "", returns(1)) + suggestion.pushMatchingRanges("#{one}#{two}#{three}#{two}#{one}", "does-not-match", ranges) + assert.equal 0, ranges.length + context "RankingUtils", should "do a case insensitive match", -> assert.isTrue RankingUtils.matches(["aRi"], "MARIO", "MARio") |
