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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/snippets.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 21
22 let SnippetFilter = null; 22 let SnippetFilter = null;
23 let Snippets = null; 23 let Snippets = null;
24 let parseScript = null;
24 let ElemHide = null; 25 let ElemHide = null;
25 let Filter = null; 26 let Filter = null;
26 27
27 exports.setUp = function(callback) 28 exports.setUp = function(callback)
28 { 29 {
29 let sandboxedRequire = createSandbox(); 30 let sandboxedRequire = createSandbox();
30 ( 31 (
31 {Filter, SnippetFilter} = sandboxedRequire("../lib/filterClasses"), 32 {Filter, SnippetFilter} = sandboxedRequire("../lib/filterClasses"),
32 {ElemHide} = sandboxedRequire("../lib/elemHide"), 33 {ElemHide} = sandboxedRequire("../lib/elemHide"),
33 {Snippets} = sandboxedRequire("../lib/snippets") 34 {Snippets, parseScript} = sandboxedRequire("../lib/snippets")
34 ); 35 );
35 36
36 callback(); 37 callback();
37 }; 38 };
38 39
39 exports.testDomainRestrictions = function(test) 40 exports.testDomainRestrictions = function(test)
40 { 41 {
41 function testSelectorMatches(description, filters, domain, expectedMatches) 42 function testSelectorMatches(description, filters, domain, expectedMatches)
42 { 43 {
43 for (let filter of filters) 44 for (let filter of filters)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 130
130 Snippets.clear(); 131 Snippets.clear();
131 compareRules( 132 compareRules(
132 "Return no filters after clearing", 133 "Return no filters after clearing",
133 "www.example.com", 134 "www.example.com",
134 [] 135 []
135 ); 136 );
136 137
137 test.done(); 138 test.done();
138 }; 139 };
140
141 exports.testScriptParsing = function(test)
142 {
143 function checkParsedScript(description, script, expectedTree)
144 {
145 let tree = parseScript(script);
146 test.deepEqual(tree, expectedTree, description);
147 }
148
149 checkParsedScript("Script with no arguments", "foo", [["foo"]]);
150 checkParsedScript("Script with one argument", "foo 1", [["foo", "1"]]);
151 checkParsedScript("Script with two arguments", "foo 1 Hello",
152 [["foo", "1", "Hello"]]);
153 checkParsedScript("Script with argument containing an escaped space",
154 "foo Hello\\ world",
155 [["foo", "Hello world"]]);
156 checkParsedScript("Script with argument containing a quoted space",
157 "foo 'Hello world'",
158 [["foo", "Hello world"]]);
159 checkParsedScript("Script with argument containing a quoted escaped quote",
160 "foo 'Hello \\'world\\''",
161 [["foo", "Hello 'world'"]]);
162 checkParsedScript("Script with argument containing an escaped semicolon",
163 "foo TL\\;DR",
164 [["foo", "TL;DR"]]);
165 checkParsedScript("Script with argument containing a quoted semicolon",
166 "foo 'TL;DR'",
167 [["foo", "TL;DR"]]);
168 checkParsedScript("Script with argument containing single character " +
169 "escape sequences",
170 "foo yin\\tyang\\n",
171 [["foo", "yin\tyang\n"]]);
172 checkParsedScript("Script with argument containing Unicode escape sequences",
173 "foo \\u0062\\ud83d\\ude42r " +
174 "'l\\ud83d\\ude02mbd\\ud83d\\ude02'", [
175 ["foo", "b\ud83d\ude42r", "l\ud83d\ude02mbd\ud83d\ude02"]
176 ]);
177 checkParsedScript("Script with multiple commands", "foo; bar",
178 [["foo"], ["bar"]]);
179 checkParsedScript("Script with multiple commands and multiple arguments each",
180 "foo 1 Hello; bar world! #",
181 [["foo", "1", "Hello"], ["bar", "world!", "#"]]);
182 checkParsedScript("Script with multiple commands and multiple " +
Manish Jethani 2018/04/26 16:22:09 Unrelated indentation update.
183 "escaped and quoted arguments each",
184 "foo 1 'Hello, \\'Tommy\\'!' ;" +
185 "bar Hi!\\ How\\ are\\ you? http://example.com", [
186 ["foo", "1", "Hello, 'Tommy'!"],
187 ["bar", "Hi! How are you?", "http://example.com"]
188 ]);
189 checkParsedScript("Script with command names containing " +
190 "whitespace (spaces, tabs, newlines, etc.), " +
191 "quotes, and semicolons",
192 "fo\\'\\ \\ \\\t\\\n\\;o 1 2 3; 'b a r' 1 2",
193 [["fo' \t\n;o", "1", "2", "3"], ["b a r", "1", "2"]]);
194 checkParsedScript("Script containing Unicode composite characters",
195 "f\ud83d\ude42\ud83d\ude42 b\ud83d\ude02r",
196 [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]);
197 checkParsedScript("Script with no-op commands", "foo; ;;; ; ; bar 1",
198 [["foo"], ["bar", "1"]]);
199
200 test.done();
201 };
OLDNEW
« 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