From bc2f5e0f52179e915ed7a439fc6bfa03525156ee Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 17 Oct 2016 08:02:20 +0100 Subject: Better line parsing. 1. Explicitly remove comments. 2. A trailing backslash means the current line continues on the next line. E.g. a \ b \ c is a single line `a b c`. This helps alleviate the fact that configuration lines can be very long, whereas the *Custom key mappings* input is quite narrow. TODO: We should use the same line parser in the custom-search-engines input. --- tests/unit_tests/commands_test.coffee | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/unit_tests/commands_test.coffee b/tests/unit_tests/commands_test.coffee index 2c2e9542..12f4496a 100644 --- a/tests/unit_tests/commands_test.coffee +++ b/tests/unit_tests/commands_test.coffee @@ -1,5 +1,6 @@ require "./test_helper.js" extend global, require "./test_chrome_stubs.js" +extend global, require "../../background_scripts/bg_utils.js" global.Settings = {postUpdateHooks: {}, get: (-> ""), set: ->} {Commands} = require "../../background_scripts/commands.js" -- cgit v1.2.3 From 4486be1f40c582bf159e034f590cb82cb84caafc Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 23 Oct 2016 16:00:08 +0100 Subject: Better line parsing (add tests). --- tests/unit_tests/commands_test.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/unit_tests/commands_test.coffee b/tests/unit_tests/commands_test.coffee index 12f4496a..0e0be1d6 100644 --- a/tests/unit_tests/commands_test.coffee +++ b/tests/unit_tests/commands_test.coffee @@ -98,6 +98,22 @@ context "Validate advanced commands", for command in Commands.advancedCommands assert.isTrue 0 <= @allCommands.indexOf command +context "Parse commands", + should "omit whitespace", -> + assert.equal 0, BgUtils.parseLines(" \n \n ").length + + should "omit comments", -> + assert.equal 0, BgUtils.parseLines(" # comment \n \" comment \n ").length + + should "join lines", -> + assert.equal 1, BgUtils.parseLines("a\\\nb").length + assert.equal "ab", BgUtils.parseLines("a\\\nb")[0] + + should "trim lines", -> + assert.equal 2, BgUtils.parseLines(" a \n b").length + assert.equal "a", BgUtils.parseLines(" a \n b")[0] + assert.equal "b", BgUtils.parseLines(" a \n b")[1] + # TODO (smblott) More tests: # - Ensure each background command has an implmentation in BackgroundCommands # - Ensure each foreground command has an implmentation in vimium_frontent.coffee -- cgit v1.2.3