diff options
| author | Stephen Blott | 2016-10-02 09:01:29 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-10-02 09:22:09 +0100 | 
| commit | 967aa7bf31998f667616f19f9b83e409340b66d1 (patch) | |
| tree | 590b3fde8de04a9e29ccdd84eff7015c169dcf37 /tests/unit_tests/commands_test.coffee | |
| parent | d439a13afd1569548e62def33278f31b258984db (diff) | |
| download | vimium-967aa7bf31998f667616f19f9b83e409340b66d1.tar.bz2 | |
Rework key-sequence parsing.
This reworks the parsing of key sequences like `<c-a-Z>x`:
Advantages over the status quo:
- Parses key sequences in one only place (previously two),
- Removes two hideous regular expression.
- Admits multi-modifier bindings (like `<c-a-Z>`).
- Adds more (and better) tests.
- (And it should be easier to maintain.)
Replaces #2210 (this also simplifies key parsing substantially).
Diffstat (limited to 'tests/unit_tests/commands_test.coffee')
| -rw-r--r-- | tests/unit_tests/commands_test.coffee | 43 | 
1 files changed, 38 insertions, 5 deletions
| diff --git a/tests/unit_tests/commands_test.coffee b/tests/unit_tests/commands_test.coffee index f501a960..1915e062 100644 --- a/tests/unit_tests/commands_test.coffee +++ b/tests/unit_tests/commands_test.coffee @@ -4,12 +4,45 @@ global.Settings = {postUpdateHooks: {}, get: (-> ""), set: ->}  {Commands} = require "../../background_scripts/commands.js"  context "Key mappings", +  setup -> +    @testKeySequence = (key, expectedKeyText, expectedKeyLength) -> +      keySequence = Commands.normalizeKey key +      assert.equal expectedKeyText, keySequence.join "/" +      assert.equal expectedKeyLength, keySequence.length +    should "lowercase keys correctly", -> -    assert.equal (Commands.normalizeKey '<c-a>'), '<c-a>' -    assert.equal (Commands.normalizeKey '<C-a>'), '<c-a>' -    assert.equal (Commands.normalizeKey '<C-A>'), '<c-A>' -    assert.equal (Commands.normalizeKey '<F12>'), '<f12>' -    assert.equal (Commands.normalizeKey '<C-F12>'), '<c-f12>' +    @testKeySequence "a", "a", 1 +    @testKeySequence "A", "A", 1 +    @testKeySequence "ab", "a/b", 2 + +  should "parse keys with modifiers", -> +    @testKeySequence "<c-a>", "<c-a>", 1 +    @testKeySequence "<c-A>", "<c-A>", 1 +    @testKeySequence "<c-a><a-b>", "<c-a>/<a-b>", 2 +    @testKeySequence "<m-a>", "<m-a>", 1 + +  should "normalize with modifiers", -> +    # Modifiers should be in alphabetical order. +    @testKeySequence "<m-c-a-A>", "<a-c-m-A>", 1 + +  should "parse and normalize named keys", -> +    @testKeySequence "<space>", "<space>", 1 +    @testKeySequence "<Space>", "<space>", 1 +    @testKeySequence "<C-Space>", "<c-space>", 1 +    @testKeySequence "<f12>", "<f12>", 1 +    @testKeySequence "<F12>", "<f12>", 1 + +  should "handle angle brackets", -> +    @testKeySequence "<", "<", 1 +    @testKeySequence ">", ">", 1 + +    @testKeySequence "<<", "</<", 2 +    @testKeySequence ">>", ">/>", 2 + +    @testKeySequence "<>", "</>", 2 +    @testKeySequence "<>", "</>", 2 + +    @testKeySequence "<<space>", "</<space>", 2  context "Validate commands and options",    should "have either noRepeat or repeatLimit, but not both", -> | 
