]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
23 Filename: RegExp_multiline.js
24 Description: 'Tests RegExps multiline property'
30 var SECTION
= 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION
= 'no version';
33 var TITLE
= 'RegExp: multiline';
35 writeHeaderToLog('Executing script: RegExp_multiline.js');
36 writeHeaderToLog( SECTION
+ " "+ TITLE
);
39 var testcases
= new Array();
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(**).
44 testcases
[count
++] = new TestCase ( SECTION
, "RegExp.multiline",
45 false, RegExp
.multiline
);
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../));
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)));
55 // (multiline == false) 'a11\na22'.match(/^.+^./)
56 testcases
[count
++] = new TestCase ( SECTION
, "(multiline == false) 'a11\na22'.match(/^.+^./)",
57 null, 'a11\na22'.match(/^.+^./));
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$/));
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)));
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$...$/));
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'))));
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$...$')));
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
);
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../)));
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)));
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(/^.+^./)));
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$/)));
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)));
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'))));
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$.+$/)));
113 RegExp
.multiline
= false;
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 ";
126 return ( testcases
);