Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/snippets.js

Issue 29761597: Issue 6538, 6781 - Implement script parsing for snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Support Unicode escape sequences Created April 26, 2018, 4:16 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/snippets.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/snippets.js
===================================================================
--- a/test/snippets.js
+++ b/test/snippets.js
@@ -16,26 +16,27 @@
*/
"use strict";
const {createSandbox} = require("./_common");
let SnippetFilter = null;
let Snippets = null;
+let parseScript = null;
let ElemHide = null;
let Filter = null;
exports.setUp = function(callback)
{
let sandboxedRequire = createSandbox();
(
{Filter, SnippetFilter} = sandboxedRequire("../lib/filterClasses"),
{ElemHide} = sandboxedRequire("../lib/elemHide"),
- {Snippets} = sandboxedRequire("../lib/snippets")
+ {Snippets, parseScript} = sandboxedRequire("../lib/snippets")
);
callback();
};
exports.testDomainRestrictions = function(test)
{
function testSelectorMatches(description, filters, domain, expectedMatches)
@@ -131,8 +132,70 @@
compareRules(
"Return no filters after clearing",
"www.example.com",
[]
);
test.done();
};
+
+exports.testScriptParsing = function(test)
+{
+ function checkParsedScript(description, script, expectedTree)
+ {
+ let tree = 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",
+ "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 argument containing single character " +
+ "escape sequences",
+ "foo yin\\tyang\\n",
+ [["foo", "yin\tyang\n"]]);
+ checkParsedScript("Script with argument containing Unicode escape sequences",
+ "foo \\u0062\\ud83d\\ude42r " +
+ "'l\\ud83d\\ude02mbd\\ud83d\\ude02'", [
+ ["foo", "b\ud83d\ude42r", "l\ud83d\ude02mbd\ud83d\ude02"]
+ ]);
+ 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("Script with multiple commands and multiple " +
Manish Jethani 2018/04/26 16:22:09 Unrelated indentation update.
+ "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();
+};
« no previous file with comments | « lib/snippets.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld