Debian Codegraph @

rhino/testsrc/tests/js1_2/regexp/character_class.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 = 'character_class.js';
7
8 /**
9 Filename: character_class.js
10 Description: 'Tests regular expressions containing []'
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: []';
20
21 writeHeaderToLog('Executing script: character_class.js');
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24
25 // 'abcde'.match(new RegExp('ab[ercst]de'))
26 new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[ercst]de'))",
27 String(["abcde"]), String('abcde'.match(new RegExp('ab[ercst]de'))));
28
29 // 'abcde'.match(new RegExp('ab[erst]de'))
30 new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[erst]de'))",
31 null, 'abcde'.match(new RegExp('ab[erst]de')));
32
33 // 'abcdefghijkl'.match(new RegExp('[d-h]+'))
34 new TestCase ( SECTION, "'abcdefghijkl'.match(new RegExp('[d-h]+'))",
35 String(["defgh"]), String('abcdefghijkl'.match(new RegExp('[d-h]+'))));
36
37 // 'abc6defghijkl'.match(new RegExp('[1234567].{2}'))
38 new TestCase ( SECTION, "'abc6defghijkl'.match(new RegExp('[1234567].{2}'))",
39 String(["6de"]), String('abc6defghijkl'.match(new RegExp('[1234567].{2}'))));
40
41 // '\n\n\abc324234\n'.match(new RegExp('[a-c\d]+'))
42 new TestCase ( SECTION, "'\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))",
43 String(["abc324234"]), String('\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))));
44
45 // 'abc'.match(new RegExp('ab[.]?c'))
46 new TestCase ( SECTION, "'abc'.match(new RegExp('ab[.]?c'))",
47 String(["abc"]), String('abc'.match(new RegExp('ab[.]?c'))));
48
49 // 'abc'.match(new RegExp('a[b]c'))
50 new TestCase ( SECTION, "'abc'.match(new RegExp('a[b]c'))",
51 String(["abc"]), String('abc'.match(new RegExp('a[b]c'))));
52
53 // 'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))
54 new TestCase ( SECTION, "'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))",
55 String(["def"]), String('a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))));
56
57 // '123*&$abc'.match(new RegExp('[*&$]{3}'))
58 new TestCase ( SECTION, "'123*&$abc'.match(new RegExp('[*&$]{3}'))",
59 String(["*&$"]), String('123*&$abc'.match(new RegExp('[*&$]{3}'))));
60
61 // 'abc'.match(new RegExp('a[^1-9]c'))
62 new TestCase ( SECTION, "'abc'.match(new RegExp('a[^1-9]c'))",
63 String(["abc"]), String('abc'.match(new RegExp('a[^1-9]c'))));
64
65 // 'abc'.match(new RegExp('a[^b]c'))
66 new TestCase ( SECTION, "'abc'.match(new RegExp('a[^b]c'))",
67 null, 'abc'.match(new RegExp('a[^b]c')));
68
69 // 'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))
70 new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))",
71 String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))));
72
73 // 'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)
74 new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)",
75 String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)));
76
77 test();