Debian Codegraph @

rhino/testsrc/tests/js1_2/regexp/word_boundary.js

raw symbols SCIP
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 gTestfile = 'word_boundary.js';
7
8 /**
9 Filename: word_boundary.js
10 Description: 'Tests regular expressions containing \b and \B'
11
12 Author: Nick Lerissa
13 Date: March 10, 1998
14 */
15
16 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
17 var VERSION = 'no version';
18 startTest();
19 var TITLE = 'RegExp: \\b and \\B';
20
21 writeHeaderToLog('Executing script: word_boundary.js');
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24
25 // 'cowboy boyish boy'.match(new RegExp('\bboy\b'))
26 new TestCase ( SECTION, "'cowboy boyish boy'.match(new RegExp('\\bboy\\b'))",
27 String(["boy"]), String('cowboy boyish boy'.match(new RegExp('\\bboy\\b'))));
28
29 var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
30 var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
31 var s = '';
32 var i;
33
34 // testing whether all boundary characters are matched when they should be
35 for (i = 0; i < boundary_characters.length; ++i)
36 {
37 s = '123ab' + boundary_characters.charAt(i) + '123c' + boundary_characters.charAt(i);
38
39 new TestCase ( SECTION,
40 "'" + s + "'.match(new RegExp('\\b123[a-z]\\b'))",
41 String(["123c"]), String(s.match(new RegExp('\\b123[a-z]\\b'))));
42 }
43
44 // testing whether all non-boundary characters are matched when they should be
45 for (i = 0; i < non_boundary_characters.length; ++i)
46 {
47 s = '123ab' + non_boundary_characters.charAt(i) + '123c' + non_boundary_characters.charAt(i);
48
49 new TestCase ( SECTION,
50 "'" + s + "'.match(new RegExp('\\B123[a-z]\\B'))",
51 String(["123c"]), String(s.match(new RegExp('\\B123[a-z]\\B'))));
52 }
53
54 s = '';
55
56 // testing whether all boundary characters are not matched when they should not be
57 for (i = 0; i < boundary_characters.length; ++i)
58 {
59 s += boundary_characters[i] + "a" + i + "b";
60 }
61 s += "xa1111bx";
62
63 new TestCase ( SECTION,
64 "'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))",
65 String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B'))));
66
67 new TestCase ( SECTION,
68 "'" + s + "'.match(/\\Ba\\d+b\\B/)",
69 String(["a1111b"]), String(s.match(/\Ba\d+b\B/)));
70
71 s = '';
72
73 // testing whether all non-boundary characters are not matched when they should not be
74 for (i = 0; i < non_boundary_characters.length; ++i)
75 {
76 s += non_boundary_characters[i] + "a" + i + "b";
77 }
78 s += "(a1111b)";
79
80 new TestCase ( SECTION,
81 "'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))",
82 String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b'))));
83
84 new TestCase ( SECTION,
85 "'" + s + "'.match(/\\ba\\d+b\\b/)",
86 String(["a1111b"]), String(s.match(/\ba\d+b\b/)));
87
88 test();