js/src/tests/js1_2/regexp/word_boundary.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:7183b7a348a7
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/. */
5
6
7 /**
8 Filename: word_boundary.js
9 Description: 'Tests regular expressions containing \b and \B'
10
11 Author: Nick Lerissa
12 Date: March 10, 1998
13 */
14
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';
19
20 writeHeaderToLog('Executing script: word_boundary.js');
21 writeHeaderToLog( SECTION + " "+ TITLE);
22
23
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'))));
27
28 var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
29 var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
30 var s = '';
31 var i;
32
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);
37
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 }
42
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);
47
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 }
52
53 s = '';
54
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";
61
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'))));
65
66 new TestCase ( SECTION,
67 "'" + s + "'.match(/\\Ba\\d+b\\B/)",
68 String(["a1111b"]), String(s.match(/\Ba\d+b\B/)));
69
70 s = '';
71
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)";
78
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'))));
82
83 new TestCase ( SECTION,
84 "'" + s + "'.match(/\\ba\\d+b\\b/)",
85 String(["a1111b"]), String(s.match(/\ba\d+b\b/)));
86
87 test();

mercurial