|
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 var BUGNUMBER = 371932; |
|
8 var summary = 'ES4 Regular Expression /y flag'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 print('See http://developer.mozilla.org/es4/proposals/extend_regexps.html#y_flag'); |
|
13 |
|
14 //----------------------------------------------------------------------------- |
|
15 test(); |
|
16 //----------------------------------------------------------------------------- |
|
17 |
|
18 function test() |
|
19 { |
|
20 enterFunc ('test'); |
|
21 printBugNumber(BUGNUMBER); |
|
22 printStatus (summary); |
|
23 |
|
24 var c; |
|
25 var s = '123456'; |
|
26 |
|
27 print('Test global flag.'); |
|
28 |
|
29 var g = /(1)/g; |
|
30 expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"'; |
|
31 actual = 'captures: ' + g.exec('1234561') + |
|
32 '; RegExp.leftContext: "' + RegExp.leftContext + |
|
33 '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; |
|
34 reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") first call'); |
|
35 |
|
36 expect = 'captures: 1,1; RegExp.leftContext: "123456"; RegExp.rightContext: ""'; |
|
37 actual = 'captures: ' + g.exec('1234561') + |
|
38 '; RegExp.leftContext: "' + RegExp.leftContext + |
|
39 '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; |
|
40 reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") second call'); |
|
41 var y = /(1)/y; |
|
42 |
|
43 print('Test sticky flag.'); |
|
44 |
|
45 /* |
|
46 * calls to reportCompare invoke regular expression matches which interfere |
|
47 * with the test of the sticky flag. Collect expect and actual values prior |
|
48 * to calling reportCompare. Note setting y = /(1)/y resets the lastIndex etc. |
|
49 */ |
|
50 |
|
51 var y = /(1)/y; |
|
52 var expect4 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"'; |
|
53 var actual4 = 'captures: ' + y.exec('1234561') + |
|
54 '; RegExp.leftContext: "' + RegExp.leftContext + |
|
55 '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; |
|
56 |
|
57 var expect5 = 'captures: null; RegExp.leftContext: ""; RegExp.rightContext: "234561"'; |
|
58 var actual5 = 'captures: ' + y.exec('1234561') + |
|
59 '; RegExp.leftContext: "' + RegExp.leftContext + |
|
60 '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; |
|
61 |
|
62 reportCompare(expect4, actual4, summary + ' - /(1)/y.exec("1234561") first call'); |
|
63 reportCompare(expect5, actual5, summary + ' - /(1)/y.exec("1234561") second call'); |
|
64 |
|
65 var y = /(1)/y; |
|
66 |
|
67 reportCompare(expect5, actual5, summary); |
|
68 |
|
69 y = /(1)/y; |
|
70 var expect6 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "123456"'; |
|
71 var actual6 = 'captures: ' + y.exec('1123456') + |
|
72 '; RegExp.leftContext: "' + RegExp.leftContext + |
|
73 '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; |
|
74 |
|
75 var expect7 = 'captures: 1,1; RegExp.leftContext: "1"; RegExp.rightContext: "23456"'; |
|
76 var actual7 = 'captures: ' + y.exec('1123456') + |
|
77 '; RegExp.leftContext: "' + RegExp.leftContext + |
|
78 '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; |
|
79 |
|
80 reportCompare(expect6, actual6, summary + ' - /(1)/y.exec("1123456") first call'); |
|
81 reportCompare(expect7, actual7, summary + ' - /(1)/y.exec("1123456") second call'); |
|
82 |
|
83 var y = /(1)/y; |
|
84 |
|
85 reportCompare(expect, actual, summary); |
|
86 |
|
87 exitFunc ('test'); |
|
88 } |