Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_2 / regexp / RegExp_multiline.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    Filename:     RegExp_multiline.js
42    Description:  'Tests RegExps multiline property'
43
44    Author:       Nick Lerissa
45    Date:         March 12, 1998
46 */
47
48 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
49 var VERSION = 'no version';
50 startTest();
51 var TITLE   = 'RegExp: multiline';
52
53 writeHeaderToLog('Executing script: RegExp_multiline.js');
54 writeHeaderToLog( SECTION + " "+ TITLE);
55
56 // First we do a series of tests with RegExp.multiline set to false (default value)
57 // Following this we do the same tests with RegExp.multiline set true(**).
58 // RegExp.multiline
59 new TestCase ( SECTION, "RegExp.multiline",
60                false, RegExp.multiline);
61
62 // (multiline == false) '123\n456'.match(/^4../)
63 new TestCase ( SECTION, "(multiline == false) '123\\n456'.match(/^4../)",
64                null, '123\n456'.match(/^4../));
65
66 // (multiline == false) 'a11\na22\na23\na24'.match(/^a../g)
67 new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(/^a../g)",
68                String(['a11']), String('a11\na22\na23\na24'.match(/^a../g)));
69
70 // (multiline == false) 'a11\na22'.match(/^.+^./)
71 new TestCase ( SECTION, "(multiline == false) 'a11\na22'.match(/^.+^./)",
72                null, 'a11\na22'.match(/^.+^./));
73
74 // (multiline == false) '123\n456'.match(/.3$/)
75 new TestCase ( SECTION, "(multiline == false) '123\\n456'.match(/.3$/)",
76                null, '123\n456'.match(/.3$/));
77
78 // (multiline == false) 'a11\na22\na23\na24'.match(/a..$/g)
79 new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
80                String(['a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
81
82 // (multiline == false) 'abc\ndef'.match(/c$...$/)
83 new TestCase ( SECTION, "(multiline == false) 'abc\ndef'.match(/c$...$/)",
84                null, 'abc\ndef'.match(/c$...$/));
85
86 // (multiline == false) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
87 new TestCase ( SECTION, "(multiline == false) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
88                String(['a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
89
90 // (multiline == false) 'abc\ndef'.match(new RegExp('c$...$'))
91 new TestCase ( SECTION, "(multiline == false) 'abc\ndef'.match(new RegExp('c$...$'))",
92                null, 'abc\ndef'.match(new RegExp('c$...$')));
93
94 // **Now we do the tests with RegExp.multiline set to true
95 // RegExp.multiline = true; RegExp.multiline
96 RegExp.multiline = true;
97 new TestCase ( SECTION, "RegExp.multiline = true; RegExp.multiline",
98                true, RegExp.multiline);
99
100 // (multiline == true) '123\n456'.match(/^4../)
101 new TestCase ( SECTION, "(multiline == true) '123\\n456'.match(/^4../)",
102                String(['456']), String('123\n456'.match(/^4../)));
103
104 // (multiline == true) 'a11\na22\na23\na24'.match(/^a../g)
105 new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(/^a../g)",
106                String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/^a../g)));
107
108 // (multiline == true) 'a11\na22'.match(/^.+^./)
109 //new TestCase ( SECTION, "(multiline == true) 'a11\na22'.match(/^.+^./)",
110 //                                    String(['a11\na']), String('a11\na22'.match(/^.+^./)));
111
112 // (multiline == true) '123\n456'.match(/.3$/)
113 new TestCase ( SECTION, "(multiline == true) '123\\n456'.match(/.3$/)",
114                String(['23']), String('123\n456'.match(/.3$/)));
115
116 // (multiline == true) 'a11\na22\na23\na24'.match(/a..$/g)
117 new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(/a..$/g)",
118                String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(/a..$/g)));
119
120 // (multiline == true) 'a11\na22\na23\na24'.match(new RegExp('a..$','g'))
121 new TestCase ( SECTION, "(multiline == true) 'a11\\na22\\na23\\na24'.match(new RegExp('a..$','g'))",
122                String(['a11','a22','a23','a24']), String('a11\na22\na23\na24'.match(new RegExp('a..$','g'))));
123
124 // (multiline == true) 'abc\ndef'.match(/c$....$/)
125 //new TestCase ( SECTION, "(multiline == true) 'abc\ndef'.match(/c$.+$/)",
126 //                                    'c\ndef', String('abc\ndef'.match(/c$.+$/)));
127
128 RegExp.multiline = false;
129
130 test();