Debian Codegraph @

rhino/testsrc/tests/js1_7/regexp/yflag.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 var gTestfile = 'yflag.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 371932;
9 var summary = 'ES4 Regular Expression /y flag';
10 var actual = '';
11 var expect = '';
12
13 print('See http://developer.mozilla.org/es4/proposals/extend_regexps.html#y_flag');
14
15 //-----------------------------------------------------------------------------
16 test();
17 //-----------------------------------------------------------------------------
18
19 function test()
20 {
21 enterFunc ('test');
22 printBugNumber(BUGNUMBER);
23 printStatus (summary);
24
25 var c;
26 var s = '123456';
27
28 print('Test global flag.');
29
30 var g = /(1)/g;
31 expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
32 actual = 'captures: ' + g.exec('1234561') +
33 '; RegExp.leftContext: "' + RegExp.leftContext +
34 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
35 reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") first call');
36
37 expect = 'captures: 1,1; RegExp.leftContext: "123456"; RegExp.rightContext: ""';
38 actual = 'captures: ' + g.exec('1234561') +
39 '; RegExp.leftContext: "' + RegExp.leftContext +
40 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
41 reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") second call');
42 var y = /(1)/y;
43
44 print('Test sticky flag.');
45
46 var y = /(1)/y;
47 expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
48 actual = 'captures: ' + y.exec('1234561') +
49 '; RegExp.leftContext: "' + RegExp.leftContext +
50 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
51 reportCompare(expect, actual, summary + ' - /(1)/y.exec("1234561") first call');
52
53 expect = 'captures: null; RegExp.leftContext: ""; RegExp.rightContext: "234561"';
54 actual = 'captures: ' + y.exec('1234561') +
55 '; RegExp.leftContext: "' + RegExp.leftContext +
56 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
57 reportCompare(expect, actual, summary + ' - /(1)/y.exec("1234561") second call');
58 var y = /(1)/y;
59
60 reportCompare(expect, actual, summary);
61
62 y = /(1)/y;
63 expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "123456"';
64 actual = 'captures: ' + y.exec('1123456') +
65 '; RegExp.leftContext: "' + RegExp.leftContext +
66 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
67 reportCompare(expect, actual, summary + ' - /(1)/y.exec("1123456") first call');
68
69 expect = 'captures: 1,1; RegExp.leftContext: "1"; RegExp.rightContext: "23456"';
70 actual = 'captures: ' + y.exec('1123456') +
71 '; RegExp.leftContext: "' + RegExp.leftContext +
72 '"; RegExp.rightContext: "' + RegExp.rightContext + '"';
73 reportCompare(expect, actual, summary + ' - /(1)/y.exec("1123456") second call');
74 var y = /(1)/y;
75
76 reportCompare(expect, actual, summary);
77
78 exitFunc ('test');
79 }