Debian Codegraph @

js/src/tests/non262/RegExp/yflag.js

raw
1 /* -*- indent-tabs-mode: nil; js-indent-level: 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 printBugNumber(BUGNUMBER);
21 printStatus (summary);
22
23 var c;
24 var s = '123456';
25
26 print('Test global flag.');
27
28 var g = /(1)/g;
29 expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
30 actual = 'captures: ' + g.exec('1234561') +
31 '; RegExp.leftContext: "' + RegExp.leftContext +
32 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
33 reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") first call');
34
35 expect = 'captures: 1,1; RegExp.leftContext: "123456"; RegExp.rightContext: ""';
36 actual = 'captures: ' + g.exec('1234561') +
37 '; RegExp.leftContext: "' + RegExp.leftContext +
38 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
39 reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") second call');
40 var y = /(1)/y;
41
42 print('Test sticky flag.');
43
44 /*
45 * calls to reportCompare invoke regular expression matches which interfere
46 * with the test of the sticky flag. Collect expect and actual values prior
47 * to calling reportCompare. Note setting y = /(1)/y resets the lastIndex etc.
48 */
49
50 var y = /(1)/y;
51 var expect4 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
52 var actual4 = 'captures: ' + y.exec('1234561') +
53 '; RegExp.leftContext: "' + RegExp.leftContext +
54 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
55
56 var expect5 = 'captures: null; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
57 var actual5 = 'captures: ' + y.exec('1234561') +
58 '; RegExp.leftContext: "' + RegExp.leftContext +
59 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
60
61 reportCompare(expect4, actual4, summary + ' - /(1)/y.exec("1234561") first call');
62 reportCompare(expect5, actual5, summary + ' - /(1)/y.exec("1234561") second call');
63
64 var y = /(1)/y;
65
66 reportCompare(expect5, actual5, summary);
67
68 y = /(1)/y;
69 var expect6 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "123456"';
70 var actual6 = 'captures: ' + y.exec('1123456') +
71 '; RegExp.leftContext: "' + RegExp.leftContext +
72 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
73
74 var expect7 = 'captures: 1,1; RegExp.leftContext: "1"; RegExp.rightContext: "23456"';
75 var actual7 = 'captures: ' + y.exec('1123456') +
76 '; RegExp.leftContext: "' + RegExp.leftContext +
77 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
78
79 reportCompare(expect6, actual6, summary + ' - /(1)/y.exec("1123456") first call');
80 reportCompare(expect7, actual7, summary + ' - /(1)/y.exec("1123456") second call');
81
82 var y = /(1)/y;
83
84 reportCompare(expect, actual, summary);
85 }