Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_3 / RegExp / regress-78156.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.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   pschwartau@netscape.com
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  * Date: 06 February 2001
41  *
42  * SUMMARY:  Arose from Bugzilla bug 78156:
43  * "m flag of regular expression does not work with $"
44  *
45  * See http://bugzilla.mozilla.org/show_bug.cgi?id=78156
46  *
47  * The m flag means a regular expression should search strings
48  * across multiple lines, i.e. across '\n', '\r'.
49  */
50 //-----------------------------------------------------------------------------
51 var i = 0;
52 var BUGNUMBER = 78156;
53 var summary = 'Testing regular expressions with  ^, $, and the m flag -';
54 var status = '';
55 var statusmessages = new Array();
56 var pattern = '';
57 var patterns = new Array();
58 var string = '';
59 var strings = new Array();
60 var actualmatch = '';
61 var actualmatches = new Array();
62 var expectedmatch = '';
63 var expectedmatches = new Array();
64
65 /*
66  * All patterns have an m flag; all strings are multiline.
67  * Looking for digit characters at beginning/end of lines.
68  */
69
70 string = 'aaa\n789\r\nccc\r\n345';
71 status = inSection(1);
72 pattern = /^\d/gm;
73 actualmatch = string.match(pattern);
74 expectedmatch = ['7','3'];
75 addThis();
76
77 status = inSection(2);
78 pattern = /\d$/gm;
79 actualmatch = string.match(pattern);
80 expectedmatch = ['9','5'];
81 addThis();
82
83 string = 'aaa\n789\r\nccc\r\nddd';
84 status = inSection(3);
85 pattern = /^\d/gm;
86 actualmatch = string.match(pattern);
87 expectedmatch = ['7'];
88 addThis();
89
90 status = inSection(4);
91 pattern = /\d$/gm;
92 actualmatch = string.match(pattern);
93 expectedmatch = ['9'];
94 addThis();
95
96
97
98 //-------------------------------------------------------------------------------------------------
99 test();
100 //-------------------------------------------------------------------------------------------------
101
102
103
104 function addThis()
105 {
106   statusmessages[i] = status;
107   patterns[i] = pattern;
108   strings[i] = string;
109   actualmatches[i] = actualmatch;
110   expectedmatches[i] = expectedmatch;
111   i++;
112 }
113
114
115 function test()
116 {
117   enterFunc ('test');
118   printBugNumber(BUGNUMBER);
119   printStatus (summary);
120   testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
121   exitFunc ('test');
122 }