js/src/tests/js1_2/regexp/special_characters.js

branch
TOR_BUG_9701
changeset 12
7540298fafa1
equal deleted inserted replaced
-1:000000000000 0:2358939b526a
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: special_characters.js
9 Description: 'Tests regular expressions containing special characters'
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: special_charaters';
19
20 writeHeaderToLog('Executing script: special_characters.js');
21 writeHeaderToLog( SECTION + " "+ TITLE);
22
23
24 // testing backslash '\'
25 new TestCase ( SECTION, "'^abcdefghi'.match(/\^abc/)", String(["^abc"]), String('^abcdefghi'.match(/\^abc/)));
26
27 // testing beginning of line '^'
28 new TestCase ( SECTION, "'abcdefghi'.match(/^abc/)", String(["abc"]), String('abcdefghi'.match(/^abc/)));
29
30 // testing end of line '$'
31 new TestCase ( SECTION, "'abcdefghi'.match(/fghi$/)", String(["ghi"]), String('abcdefghi'.match(/ghi$/)));
32
33 // testing repeat '*'
34 new TestCase ( SECTION, "'eeeefghi'.match(/e*/)", String(["eeee"]), String('eeeefghi'.match(/e*/)));
35
36 // testing repeat 1 or more times '+'
37 new TestCase ( SECTION, "'abcdeeeefghi'.match(/e+/)", String(["eeee"]), String('abcdeeeefghi'.match(/e+/)));
38
39 // testing repeat 0 or 1 time '?'
40 new TestCase ( SECTION, "'abcdefghi'.match(/abc?de/)", String(["abcde"]), String('abcdefghi'.match(/abc?de/)));
41
42 // testing any character '.'
43 new TestCase ( SECTION, "'abcdefghi'.match(/c.e/)", String(["cde"]), String('abcdefghi'.match(/c.e/)));
44
45 // testing remembering ()
46 new TestCase ( SECTION, "'abcewirjskjdabciewjsdf'.match(/(abc).+\\1'/)",
47 String(["abcewirjskjdabc","abc"]), String('abcewirjskjdabciewjsdf'.match(/(abc).+\1/)));
48
49 // testing or match '|'
50 new TestCase ( SECTION, "'abcdefghi'.match(/xyz|def/)", String(["def"]), String('abcdefghi'.match(/xyz|def/)));
51
52 // testing repeat n {n}
53 new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3}/)", String(["eee"]), String('abcdeeeefghi'.match(/e{3}/)));
54
55 // testing min repeat n {n,}
56 new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3,}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{3,}/)));
57
58 // testing min/max repeat {min, max}
59 new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{2,8}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{2,8}/)));
60
61 // testing any in set [abc...]
62 new TestCase ( SECTION, "'abcdefghi'.match(/cd[xey]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[xey]fgh/)));
63
64 // testing any in set [a-z]
65 new TestCase ( SECTION, "'netscape inc'.match(/t[r-v]ca/)", String(["tsca"]), String('netscape inc'.match(/t[r-v]ca/)));
66
67 // testing any not in set [^abc...]
68 new TestCase ( SECTION, "'abcdefghi'.match(/cd[^xy]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[^xy]fgh/)));
69
70 // testing any not in set [^a-z]
71 new TestCase ( SECTION, "'netscape inc'.match(/t[^a-c]ca/)", String(["tsca"]), String('netscape inc'.match(/t[^a-c]ca/)));
72
73 // testing backspace [\b]
74 new TestCase ( SECTION, "'this is b\ba test'.match(/is b[\b]a test/)",
75 String(["is b\ba test"]), String('this is b\ba test'.match(/is b[\b]a test/)));
76
77 // testing word boundary \b
78 new TestCase ( SECTION, "'today is now - day is not now'.match(/\bday.*now/)",
79 String(["day is not now"]), String('today is now - day is not now'.match(/\bday.*now/)));
80
81 // control characters???
82
83 // testing any digit \d
84 new TestCase ( SECTION, "'a dog - 1 dog'.match(/\d dog/)", String(["1 dog"]), String('a dog - 1 dog'.match(/\d dog/)));
85
86 // testing any non digit \d
87 new TestCase ( SECTION, "'a dog - 1 dog'.match(/\D dog/)", String(["a dog"]), String('a dog - 1 dog'.match(/\D dog/)));
88
89 // testing form feed '\f'
90 new TestCase ( SECTION, "'a b a\fb'.match(/a\fb/)", String(["a\fb"]), String('a b a\fb'.match(/a\fb/)));
91
92 // testing line feed '\n'
93 new TestCase ( SECTION, "'a b a\nb'.match(/a\nb/)", String(["a\nb"]), String('a b a\nb'.match(/a\nb/)));
94
95 // testing carriage return '\r'
96 new TestCase ( SECTION, "'a b a\rb'.match(/a\rb/)", String(["a\rb"]), String('a b a\rb'.match(/a\rb/)));
97
98 // testing whitespace '\s'
99 new TestCase ( SECTION, "'xa\f\n\r\t\vbz'.match(/a\s+b/)", String(["a\f\n\r\t\vb"]), String('xa\f\n\r\t\vbz'.match(/a\s+b/)));
100
101 // testing non whitespace '\S'
102 new TestCase ( SECTION, "'a\tb a b a-b'.match(/a\Sb/)", String(["a-b"]), String('a\tb a b a-b'.match(/a\Sb/)));
103
104 // testing tab '\t'
105 new TestCase ( SECTION, "'a\t\tb a b'.match(/a\t{2}/)", String(["a\t\t"]), String('a\t\tb a b'.match(/a\t{2}/)));
106
107 // testing vertical tab '\v'
108 new TestCase ( SECTION, "'a\v\vb a b'.match(/a\v{2}/)", String(["a\v\v"]), String('a\v\vb a b'.match(/a\v{2}/)));
109
110 // testing alphnumeric characters '\w'
111 new TestCase ( SECTION, "'%AZaz09_$'.match(/\w+/)", String(["AZaz09_"]), String('%AZaz09_$'.match(/\w+/)));
112
113 // testing non alphnumeric characters '\W'
114 new TestCase ( SECTION, "'azx$%#@*4534'.match(/\W+/)", String(["$%#@*"]), String('azx$%#@*4534'.match(/\W+/)));
115
116 // testing back references '\<number>'
117 new TestCase ( SECTION, "'test'.match(/(t)es\\1/)", String(["test","t"]), String('test'.match(/(t)es\1/)));
118
119 // testing hex excaping with '\'
120 new TestCase ( SECTION, "'abcdef'.match(/\x63\x64/)", String(["cd"]), String('abcdef'.match(/\x63\x64/)));
121
122 // testing oct excaping with '\'
123 new TestCase ( SECTION, "'abcdef'.match(/\\143\\144/)", String(["cd"]), String('abcdef'.match(/\143\144/)));
124
125 test();
126

mercurial