]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/regexp/RegExp_multiline.js
JavaScriptCore-576.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_2 / regexp / RegExp_multiline.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22 /**
23 Filename: RegExp_multiline.js
24 Description: 'Tests RegExps multiline property'
25
26 Author: Nick Lerissa
27 Date: March 12, 1998
28 */
29
30 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION = 'no version';
32 startTest();
33 var TITLE = 'RegExp: multiline';
34
35 writeHeaderToLog('Executing script: RegExp_multiline.js');
36 writeHeaderToLog( SECTION + " "+ TITLE);
37
38 var count = 0;
39 var testcases = new Array();
40
41 // First we do a series of tests with RegExp.multiline set to false (default value)
42 // Following this we do the same tests with RegExp.multiline set true(**).
43 // RegExp.multiline
44 testcases[count++] = new TestCase ( SECTION, "RegExp.multiline",
45 false, RegExp.multiline);
46
47 // (multiline == false) '123\n456'.match(/^4../)
48 testcases[count++] = new TestCase ( SECTION, "(multiline == false) '123\\n456'.match(/^4../)",
49 null, '123\n456'.match(/^4../));
50
51 // (multiline == false) 'a11\na22\na23\na24'.match(/^a../g)
52 testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(/^a../g)",
53 String(['a11']), String('a11\na22\na23\na24'.match(/^a../g)));
54
55 // (multiline == false) 'a11\na22'.match(/^.+^./)
56 testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\na22'.match(/^.+^./)",
57 null, 'a11\na22'.match(/^.+^./));
58
59 // (multiline == false) '123\n456'.match(/.3$/)
60 testcases[count++] = new TestCase ( SECTION, "(multiline == false) '123\\n456'.match(/.3$/)",
61 null, '123\n456'.match(/.3$/));
62
63 // (multiline == false) 'a11\na22\na23\na24'.match(/a..$/g)
64 testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
65 String(['a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
66
67 // (multiline == false) 'abc\ndef'.match(/c$...$/)
68 testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'abc\ndef'.match(/c$...$/)",
69 null, 'abc\ndef'.match(/c$...$/));
70
71 // (multiline == false) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
72 testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
73 String(['a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
74
75 // (multiline == false) 'abc\ndef'.match(new RegExp('c$...$'))
76 testcases[count++] = new TestCase ( SECTION, "(multiline == false) 'abc\ndef'.match(new RegExp('c$...$'))",
77 null, 'abc\ndef'.match(new RegExp('c$...$')));
78
79 // **Now we do the tests with RegExp.multiline set to true
80 // RegExp.multiline = true; RegExp.multiline
81 RegExp.multiline = true;
82 testcases[count++] = new TestCase ( SECTION, "RegExp.multiline = true; RegExp.multiline",
83 true, RegExp.multiline);
84
85 // (multiline == true) '123\n456'.match(/^4../)
86 testcases[count++] = new TestCase ( SECTION, "(multiline == true) '123\\n456'.match(/^4../)",
87 String(['456']), String('123\n456'.match(/^4../)));
88
89 // (multiline == true) 'a11\na22\na23\na24'.match(/^a../g)
90 testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(/^a../g)",
91 String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/^a../g)));
92
93 // (multiline == true) 'a11\na22'.match(/^.+^./)
94 //testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\na22'.match(/^.+^./)",
95 // String(['a11\na']), String('a11\na22'.match(/^.+^./)));
96
97 // (multiline == true) '123\n456'.match(/.3$/)
98 testcases[count++] = new TestCase ( SECTION, "(multiline == true) '123\\n456'.match(/.3$/)",
99 String(['23']), String('123\n456'.match(/.3$/)));
100
101 // (multiline == true) 'a11\na22\na23\na24'.match(/a..$/g)
102 testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
103 String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
104
105 // (multiline == true) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
106 testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
107 String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
108
109 // (multiline == true) 'abc\ndef'.match(/c$....$/)
110 //testcases[count++] = new TestCase ( SECTION, "(multiline == true) 'abc\ndef'.match(/c$.+$/)",
111 // 'c\ndef', String('abc\ndef'.match(/c$.+$/)));
112
113 RegExp.multiline = false;
114
115 function test()
116 {
117 for ( tc=0; tc < testcases.length; tc++ ) {
118 testcases[tc].passed = writeTestCaseResult(
119 testcases[tc].expect,
120 testcases[tc].actual,
121 testcases[tc].description +" = "+
122 testcases[tc].actual );
123 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
124 }
125 stopTest();
126 return ( testcases );
127 }
128
129 test();