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

Side by Side Diff: test/snippets.js

Issue 29927555: Issue 6812 - Implement parsing of named arguments to snippets Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Oct. 28, 2018, 11:11 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
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]); 205 [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]);
206 checkParsedScript("Script with no-op commands", "foo; ;;; ; ; bar 1", 206 checkParsedScript("Script with no-op commands", "foo; ;;; ; ; bar 1",
207 [["foo"], ["bar", "1"]]); 207 [["foo"], ["bar", "1"]]);
208 checkParsedScript("Script with blank argument in the middle", "foo '' Hello", 208 checkParsedScript("Script with blank argument in the middle", "foo '' Hello",
209 [["foo", "", "Hello"]]); 209 [["foo", "", "Hello"]]);
210 checkParsedScript("Script with blank argument at the end", "foo Hello ''", 210 checkParsedScript("Script with blank argument at the end", "foo Hello ''",
211 [["foo", "Hello", ""]]); 211 [["foo", "Hello", ""]]);
212 checkParsedScript("Script with consecutive blank arguments", "foo '' ''", 212 checkParsedScript("Script with consecutive blank arguments", "foo '' ''",
213 [["foo", "", ""]]); 213 [["foo", "", ""]]);
214 214
215 // Most tests now repeated with named arguments.
216 checkParsedScript("Script with one named argument", "foo one=1",
217 [{0: "foo", one: "1"}]);
218 checkParsedScript("Script with two named arguments", "foo one=1 hello=Hello",
219 [{0: "foo", one: "1", hello: "Hello"}]);
220 checkParsedScript("Script with named argument containing an escaped space",
221 "foo hello-world=Hello\\ world",
222 [{"0": "foo", "hello-world": "Hello world"}]);
223 checkParsedScript("Script with name containing an escaped space",
224 "foo hello\\ world=Hello\\ world",
225 [{"0": "foo", "hello world": "Hello world"}]);
226 checkParsedScript("Script with named argument containing a quoted space",
227 "foo hello-world='Hello world'",
228 [{"0": "foo", "hello-world": "Hello world"}]);
229 checkParsedScript("Script with name containing a quoted space",
230 "foo 'hello world'='Hello world'",
231 [{"0": "foo", "hello world": "Hello world"}]);
232 checkParsedScript("Script with named argument containing a quoted escaped quot e",
233 "foo hello-world='Hello \\'world\\''",
234 [{"0": "foo", "hello-world": "Hello 'world'"}]);
235 checkParsedScript("Script with name containing a quoted escaped quote",
236 "foo 'hello \\'world\\''='Hello \\'world\\''",
237 [{"0": "foo", "hello 'world'": "Hello 'world'"}]);
238 checkParsedScript("Script with named argument containing an escaped semicolon" ,
239 "foo tldr=TL\\;DR",
240 [{0: "foo", tldr: "TL;DR"}]);
241 checkParsedScript("Script with name containing an escaped semicolon",
242 "foo tl\\;dr=TL\\;DR",
243 [{"0": "foo", "tl;dr": "TL;DR"}]);
244 checkParsedScript("Script with named argument containing a quoted semicolon",
245 "foo tldr='TL;DR'",
246 [{0: "foo", tldr: "TL;DR"}]);
247 checkParsedScript("Script with name containing a quoted semicolon",
248 "foo 'tl;dr'='TL;DR'",
249 [{"0": "foo", "tl;dr": "TL;DR"}]);
250 checkParsedScript("Script with named argument containing single character " +
251 "escape sequences",
252 "foo yin-yang=yin\\tyang\\n",
253 [{"0": "foo", "yin-yang": "yin\tyang\n"}]);
254 checkParsedScript("Script with name containing single character " +
255 "escape sequences",
256 "foo yin\\tyang\\n=yin\\tyang\\n",
257 [{"0": "foo", "yin\tyang\n": "yin\tyang\n"}]);
258 checkParsedScript("Script with named argument containing Unicode " +
259 "escape sequences",
260 "foo bar=\\u0062\\ud83d\\ude42r " +
261 "lambda='l\\ud83d\\ude02mbd\\ud83d\\ude02'", [{
262 0: "foo", bar: "b\ud83d\ude42r",
263 lambda: "l\ud83d\ude02mbd\ud83d\ude02"
264 }]);
265 checkParsedScript("Script with name containing Unicode " +
266 "escape sequences",
267 "foo \\u0062\\ud83d\\ude42r=\\u0062\\ud83d\\ude42r " +
268 "'l\\ud83d\\ude02mbd\\ud83d\\ude02'=" +
269 "'l\\ud83d\\ude02mbd\\ud83d\\ude02'", [{
270 "0": "foo", "b\ud83d\ude42r": "b\ud83d\ude42r",
271 "l\ud83d\ude02mbd\ud83d\ude02":
272 "l\ud83d\ude02mbd\ud83d\ude02"
273 }]);
274
275 checkParsedScript("Script with multiple commands and multiple " +
276 "named arguments each",
277 "foo 1=1 hello=Hello; bar world=world! hash=#", [
278 {0: "foo", 1: "1", hello: "Hello"},
279 {0: "bar", world: "world!", hash: "#"}
280 ]);
281 checkParsedScript("Script with multiple commands and multiple " +
282 "escaped and quoted named arguments each",
283 "foo 1=1 'Hello, \\'Tommy\\'!'='Hello, \\'Tommy\\'!' ;" +
284 "bar Hi!\\ How\\ are\\ you?=Hi!\\ How\\ are\\ you? " +
285 "http://example.com=http://example.com", [{
286 "0": "foo", "1": "1",
287 "Hello, 'Tommy'!": "Hello, 'Tommy'!"
288 }, {
289 "0": "bar", "Hi! How are you?": "Hi! How are you?",
290 "http://example.com": "http://example.com"
291 }]);
292
293 // Some more tests specific to named arguments.
294 checkParsedScript("Script with blank named argument", "foo blank=",
295 [{0: "foo", blank: ""}]);
296 checkParsedScript("Script with blank and non-blank named arguments",
297 "foo blank= non-blank=non-blank",
298 [{"0": "foo", "blank": "", "non-blank": "non-blank"}]);
299 checkParsedScript("Script with quoted blank named argument",
300 "foo blank=''",
301 [{0: "foo", blank: ""}]);
302 checkParsedScript("Script with quoted blank and non-blank named arguments",
303 "foo blank='' non-blank='non-blank'",
304 [{"0": "foo", "blank": "", "non-blank": "non-blank"}]);
305 checkParsedScript("Script with multiple commands and blank named arguments",
306 "foo blank=; bar blank=",
307 [{0: "foo", blank: ""}, {0: "bar", blank: ""}]);
308 checkParsedScript("Script with multiple commands and " +
309 "quoted blank named arguments",
310 "foo blank=''; bar blank=''",
311 [{0: "foo", blank: ""}, {0: "bar", blank: ""}]);
312 checkParsedScript("Script with multiple commands and " +
313 "quoted blank named arguments ending with a semicolon",
314 "foo blank=''; bar blank='';",
315 [{0: "foo", blank: ""}, {0: "bar", blank: ""}]);
316 checkParsedScript("Script with blank name", "foo =blank",
317 [{"0": "foo", "": "blank"}]);
318 checkParsedScript("Script with quoted blank name", "foo ''=blank",
319 [{"0": "foo", "": "blank"}]);
320 checkParsedScript("Script with quoted blank name and blank named argument",
321 "foo ''=''", [{"0": "foo", "": ""}]);
322 checkParsedScript("Script with command name containing an " +
323 "assignment operator",
324 "foo=bar", [["foo=bar"]]);
325 checkParsedScript("Script with argument containing a quoted " +
326 "assignment operator",
327 "foo 'name=bar'", [["foo", "name=bar"]]);
328 checkParsedScript("Script with argument containing an escaped " +
329 "assignment operator",
330 "foo name\\=bar", [["foo", "name=bar"]]);
331 checkParsedScript("Script with named argument containing assignment operator",
332 "foo name=bar=one", [{0: "foo", name: "bar=one"}]);
333 checkParsedScript("Script with named argument starting with " +
334 "assignment operator",
335 "foo name==bar", [{0: "foo", name: "=bar"}]);
336 checkParsedScript("Script with named argument ending with " +
337 "assignment operator",
338 "foo name=bar=", [{0: "foo", name: "bar="}]);
339 checkParsedScript("Script with name containing a quoted " +
340 "assignment operator",
341 "foo 'name=one'=bar", [{"0": "foo", "name=one": "bar"}]);
342 checkParsedScript("Script with name containing an escaped " +
343 "assignment operator",
344 "foo name\\=one=bar", [{"0": "foo", "name=one": "bar"}]);
345
215 // Undocumented quirks (#6853). 346 // Undocumented quirks (#6853).
216 checkParsedScript("Script with quotes within an argument", "foo Hello''world", 347 checkParsedScript("Script with quotes within an argument", "foo Hello''world",
217 [["foo", "Helloworld"]]); 348 [["foo", "Helloworld"]]);
218 checkParsedScript("Script with quotes within an argument containing whitespace ", 349 checkParsedScript("Script with quotes within an argument containing whitespace ",
219 "foo Hello' 'world", 350 "foo Hello' 'world",
220 [["foo", "Hello world"]]); 351 [["foo", "Hello world"]]);
221 checkParsedScript("Script with quotes within an argument containing non-whites pace", 352 checkParsedScript("Script with quotes within an argument containing non-whites pace",
222 "foo Hello','world", 353 "foo Hello','world",
223 [["foo", "Hello,world"]]); 354 [["foo", "Hello,world"]]);
224 checkParsedScript("Script with quotes within an argument containing whitespace and non-whitespace", 355 checkParsedScript("Script with quotes within an argument containing whitespace and non-whitespace",
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // between executions. In the example below, assertFoo does not find 456 but 436 // between executions. In the example below, assertFoo does not find 456 but
306 // it doesn't find 123 either. It's the initial value 0. 437 // it doesn't find 123 either. It's the initial value 0.
307 new Function( 438 new Function(
308 compileScript("setFoo 456; assertFoo 0", [ 439 compileScript("setFoo 456; assertFoo 0", [
309 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };" 440 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };"
310 ]) 441 ])
311 )(); 442 )();
312 443
313 test.done(); 444 test.done();
314 }; 445 };
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