diff options
| author | Stephen Blott | 2016-10-02 12:33:00 +0100 | 
|---|---|---|
| committer | GitHub | 2016-10-02 12:33:00 +0100 | 
| commit | c370855afd2f9f4123de3e9d2d8492c036a605b6 (patch) | |
| tree | cfb34113abb44bb8745828c7d932efe497d9b7c9 /tests | |
| parent | d439a13afd1569548e62def33278f31b258984db (diff) | |
| parent | 54139c11231bf7e7a3a9f4c98fb688d2d0fe22c9 (diff) | |
| download | vimium-c370855afd2f9f4123de3e9d2d8492c036a605b6.tar.bz2 | |
Merge pull request #2289 from smblott-github/rework-key-parsing
Rework key-sequence parsing.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit_tests/commands_test.coffee | 44 | 
1 files changed, 39 insertions, 5 deletions
| diff --git a/tests/unit_tests/commands_test.coffee b/tests/unit_tests/commands_test.coffee index f501a960..c8ded6a9 100644 --- a/tests/unit_tests/commands_test.coffee +++ b/tests/unit_tests/commands_test.coffee @@ -4,12 +4,46 @@ global.Settings = {postUpdateHooks: {}, get: (-> ""), set: ->}  {Commands} = require "../../background_scripts/commands.js"  context "Key mappings", +  setup -> +    @testKeySequence = (key, expectedKeyText, expectedKeyLength) -> +      keySequence = Commands.parseKeySequence 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 +    @testKeySequence "<C->>", "<c->>", 1  context "Validate commands and options",    should "have either noRepeat or repeatLimit, but not both", -> | 
