| Index: test/snippets.js | 
| =================================================================== | 
| --- a/test/snippets.js | 
| +++ b/test/snippets.js | 
| @@ -131,8 +131,62 @@ | 
| compareRules( | 
| "Return no filters after clearing", | 
| "www.example.com", | 
| [] | 
| ); | 
| test.done(); | 
| }; | 
| + | 
| +exports.testScriptParsing = function(test) | 
| +{ | 
| + function checkParsedScript(description, script, expectedTree) | 
| + { | 
| + let tree = Snippets.parseScript(script); | 
| + test.deepEqual(tree, expectedTree, description); | 
| + } | 
| + | 
| + checkParsedScript("Script with no arguments", "foo", [["foo"]]); | 
| + checkParsedScript("Script with one argument", "foo 1", [["foo", "1"]]); | 
| + checkParsedScript("Script with two arguments", "foo 1 Hello", | 
| + [["foo", "1", "Hello"]]); | 
| + checkParsedScript("Script with argument containing an escaped space", | 
| 
 
Manish Jethani
2018/04/26 13:27:34
Also note that a single backslash in fact has to b
 
 | 
| + "foo Hello\\ world", | 
| + [["foo", "Hello world"]]); | 
| + checkParsedScript("Script with argument containing a quoted space", | 
| + "foo 'Hello world'", | 
| + [["foo", "Hello world"]]); | 
| + checkParsedScript("Script with argument containing a quoted escaped quote", | 
| + "foo 'Hello \\'world\\''", | 
| + [["foo", "Hello 'world'"]]); | 
| + checkParsedScript("Script with argument containing an escaped semicolon", | 
| + "foo TL\\;DR", | 
| + [["foo", "TL;DR"]]); | 
| + checkParsedScript("Script with argument containing a quoted semicolon", | 
| + "foo 'TL;DR'", | 
| + [["foo", "TL;DR"]]); | 
| + checkParsedScript("Script with multiple commands", "foo; bar", | 
| + [["foo"], ["bar"]]); | 
| + checkParsedScript("Script with multiple commands and multiple arguments each", | 
| + "foo 1 Hello; bar world! #", | 
| + [["foo", "1", "Hello"], ["bar", "world!", "#"]]); | 
| + checkParsedScript( | 
| 
 
Manish Jethani
2018/04/26 13:25:17
ESLint would not let me format this like the other
 
 | 
| + "Script with multiple commands and multiple " + | 
| + "escaped and quoted arguments each", | 
| + "foo 1 'Hello, \\'Tommy\\'!' ;" + | 
| + "bar Hi!\\ How\\ are\\ you? http://example.com", | 
| + [["foo", "1", "Hello, 'Tommy'!"], | 
| + ["bar", "Hi! How are you?", "http://example.com"]] | 
| + ); | 
| + checkParsedScript("Script with command names containing " + | 
| + "whitespace (spaces, tabs, newlines, etc.), " + | 
| + "quotes, and semicolons", | 
| + "fo\\'\\ \\ \\\t\\\n\\;o 1 2 3; 'b a r' 1 2", | 
| + [["fo' \t\n;o", "1", "2", "3"], ["b a r", "1", "2"]]); | 
| + checkParsedScript("Script containing Unicode composite characters", | 
| + "f\ud83d\ude42\ud83d\ude42 b\ud83d\ude02r", | 
| + [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]); | 
| + checkParsedScript("Script with no-op commands", "foo; ;;; ; ; bar 1", | 
| + [["foo"], ["bar", "1"]]); | 
| + | 
| + test.done(); | 
| +}; |