Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/regress-57572.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 /*
7 * Date: 28 December 2000
8 *
9 * SUMMARY: Testing regular expressions containing the ? character.
10 * Arose from Bugzilla bug 57572: "RegExp with ? matches incorrectly"
11 *
12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=57572
13 *
14 */
15 //-----------------------------------------------------------------------------
16 var gTestfile = 'regress-57572.js';
17 var i = 0;
18 var BUGNUMBER = 57572;
19 var summary = 'Testing regular expressions containing "?"';
20 var cnEmptyString = ''; var cnSingleSpace = ' ';
21 var status = '';
22 var statusmessages = new Array();
23 var pattern = '';
24 var patterns = new Array();
25 var string = '';
26 var strings = new Array();
27 var actualmatch = '';
28 var actualmatches = new Array();
29 var expectedmatch = '';
30 var expectedmatches = new Array();
31
32
33 status = inSection(1);
34 pattern = /(\S+)?(.*)/;
35 string = 'Test this';
36 actualmatch = string.match(pattern);
37 expectedmatch = Array(string, 'Test', ' this'); //single space in front of 'this'
38 addThis();
39
40 status = inSection(2);
41 pattern = /(\S+)? ?(.*)/; //single space between the ? characters
42 string= 'Test this';
43 actualmatch = string.match(pattern);
44 expectedmatch = Array(string, 'Test', 'this'); //NO space in front of 'this'
45 addThis();
46
47 status = inSection(3);
48 pattern = /(\S+)?(.*)/;
49 string = 'Stupid phrase, with six - (short) words';
50 actualmatch = string.match(pattern);
51 expectedmatch = Array(string, 'Stupid', ' phrase, with six - (short) words'); //single space in front of 'phrase'
52 addThis();
53
54 status = inSection(4);
55 pattern = /(\S+)? ?(.*)/; //single space between the ? characters
56 string = 'Stupid phrase, with six - (short) words';
57 actualmatch = string.match(pattern);
58 expectedmatch = Array(string, 'Stupid', 'phrase, with six - (short) words'); //NO space in front of 'phrase'
59 addThis();
60
61
62 // let's add an extra back-reference this time - three instead of two -
63 status = inSection(5);
64 pattern = /(\S+)?( ?)(.*)/; //single space before second ? character
65 string = 'Stupid phrase, with six - (short) words';
66 actualmatch = string.match(pattern);
67 expectedmatch = Array(string, 'Stupid', cnSingleSpace, 'phrase, with six - (short) words');
68 addThis();
69
70 status = inSection(6);
71 pattern = /^(\S+)?( ?)(B+)$/; //single space before second ? character
72 string = 'AAABBB';
73 actualmatch = string.match(pattern);
74 expectedmatch = Array(string, 'AAABB', cnEmptyString, 'B');
75 addThis();
76
77 status = inSection(7);
78 pattern = /(\S+)?(!?)(.*)/;
79 string = 'WOW !!! !!!';
80 actualmatch = string.match(pattern);
81 expectedmatch = Array(string, 'WOW', cnEmptyString, ' !!! !!!');
82 addThis();
83
84 status = inSection(8);
85 pattern = /(.+)?(!?)(!+)/;
86 string = 'WOW !!! !!!';
87 actualmatch = string.match(pattern);
88 expectedmatch = Array(string, 'WOW !!! !!', cnEmptyString, '!');
89 addThis();
90
91
92
93 //-----------------------------------------------------------------------------
94 test();
95 //-----------------------------------------------------------------------------
96
97
98
99 function addThis()
100 {
101 statusmessages[i] = status;
102 patterns[i] = pattern;
103 strings[i] = string;
104 actualmatches[i] = actualmatch;
105 expectedmatches[i] = expectedmatch;
106 i++;
107 }
108
109
110 function test()
111 {
112 enterFunc ('test');
113 printBugNumber(BUGNUMBER);
114 printStatus (summary);
115 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
116 exitFunc ('test');
117 }