Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 Filename: word_boundary.js
9 Description: 'Tests regular expressions containing \b and \B'
11 Author: Nick Lerissa
12 Date: March 10, 1998
13 */
15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
16 var VERSION = 'no version';
17 startTest();
18 var TITLE = 'RegExp: \\b and \\B';
20 writeHeaderToLog('Executing script: word_boundary.js');
21 writeHeaderToLog( SECTION + " "+ TITLE);
24 // 'cowboy boyish boy'.match(new RegExp('\bboy\b'))
25 new TestCase ( SECTION, "'cowboy boyish boy'.match(new RegExp('\\bboy\\b'))",
26 String(["boy"]), String('cowboy boyish boy'.match(new RegExp('\\bboy\\b'))));
28 var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
29 var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
30 var s = '';
31 var i;
33 // testing whether all boundary characters are matched when they should be
34 for (i = 0; i < boundary_characters.length; ++i)
35 {
36 s = '123ab' + boundary_characters.charAt(i) + '123c' + boundary_characters.charAt(i);
38 new TestCase ( SECTION,
39 "'" + s + "'.match(new RegExp('\\b123[a-z]\\b'))",
40 String(["123c"]), String(s.match(new RegExp('\\b123[a-z]\\b'))));
41 }
43 // testing whether all non-boundary characters are matched when they should be
44 for (i = 0; i < non_boundary_characters.length; ++i)
45 {
46 s = '123ab' + non_boundary_characters.charAt(i) + '123c' + non_boundary_characters.charAt(i);
48 new TestCase ( SECTION,
49 "'" + s + "'.match(new RegExp('\\B123[a-z]\\B'))",
50 String(["123c"]), String(s.match(new RegExp('\\B123[a-z]\\B'))));
51 }
53 s = '';
55 // testing whether all boundary characters are not matched when they should not be
56 for (i = 0; i < boundary_characters.length; ++i)
57 {
58 s += boundary_characters[i] + "a" + i + "b";
59 }
60 s += "xa1111bx";
62 new TestCase ( SECTION,
63 "'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))",
64 String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B'))));
66 new TestCase ( SECTION,
67 "'" + s + "'.match(/\\Ba\\d+b\\B/)",
68 String(["a1111b"]), String(s.match(/\Ba\d+b\B/)));
70 s = '';
72 // testing whether all non-boundary characters are not matched when they should not be
73 for (i = 0; i < non_boundary_characters.length; ++i)
74 {
75 s += non_boundary_characters[i] + "a" + i + "b";
76 }
77 s += "(a1111b)";
79 new TestCase ( SECTION,
80 "'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))",
81 String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b'))));
83 new TestCase ( SECTION,
84 "'" + s + "'.match(/\\ba\\d+b\\b/)",
85 String(["a1111b"]), String(s.match(/\ba\d+b\b/)));
87 test();