1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_7/regexp/yflag.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 371932; 1.11 +var summary = 'ES4 Regular Expression /y flag'; 1.12 +var actual = ''; 1.13 +var expect = ''; 1.14 + 1.15 +print('See http://developer.mozilla.org/es4/proposals/extend_regexps.html#y_flag'); 1.16 + 1.17 +//----------------------------------------------------------------------------- 1.18 +test(); 1.19 +//----------------------------------------------------------------------------- 1.20 + 1.21 +function test() 1.22 +{ 1.23 + enterFunc ('test'); 1.24 + printBugNumber(BUGNUMBER); 1.25 + printStatus (summary); 1.26 + 1.27 + var c; 1.28 + var s = '123456'; 1.29 + 1.30 + print('Test global flag.'); 1.31 + 1.32 + var g = /(1)/g; 1.33 + expect = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"'; 1.34 + actual = 'captures: ' + g.exec('1234561') + 1.35 + '; RegExp.leftContext: "' + RegExp.leftContext + 1.36 + '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; 1.37 + reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") first call'); 1.38 + 1.39 + expect = 'captures: 1,1; RegExp.leftContext: "123456"; RegExp.rightContext: ""'; 1.40 + actual = 'captures: ' + g.exec('1234561') + 1.41 + '; RegExp.leftContext: "' + RegExp.leftContext + 1.42 + '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; 1.43 + reportCompare(expect, actual, summary + ' - /(1)/g.exec("1234561") second call'); 1.44 + var y = /(1)/y; 1.45 + 1.46 + print('Test sticky flag.'); 1.47 + 1.48 + /* 1.49 + * calls to reportCompare invoke regular expression matches which interfere 1.50 + * with the test of the sticky flag. Collect expect and actual values prior 1.51 + * to calling reportCompare. Note setting y = /(1)/y resets the lastIndex etc. 1.52 + */ 1.53 + 1.54 + var y = /(1)/y; 1.55 + var expect4 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "234561"'; 1.56 + var actual4 = 'captures: ' + y.exec('1234561') + 1.57 + '; RegExp.leftContext: "' + RegExp.leftContext + 1.58 + '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; 1.59 + 1.60 + var expect5 = 'captures: null; RegExp.leftContext: ""; RegExp.rightContext: "234561"'; 1.61 + var actual5 = 'captures: ' + y.exec('1234561') + 1.62 + '; RegExp.leftContext: "' + RegExp.leftContext + 1.63 + '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; 1.64 + 1.65 + reportCompare(expect4, actual4, summary + ' - /(1)/y.exec("1234561") first call'); 1.66 + reportCompare(expect5, actual5, summary + ' - /(1)/y.exec("1234561") second call'); 1.67 + 1.68 + var y = /(1)/y; 1.69 + 1.70 + reportCompare(expect5, actual5, summary); 1.71 + 1.72 + y = /(1)/y; 1.73 + var expect6 = 'captures: 1,1; RegExp.leftContext: ""; RegExp.rightContext: "123456"'; 1.74 + var actual6 = 'captures: ' + y.exec('1123456') + 1.75 + '; RegExp.leftContext: "' + RegExp.leftContext + 1.76 + '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; 1.77 + 1.78 + var expect7 = 'captures: 1,1; RegExp.leftContext: "1"; RegExp.rightContext: "23456"'; 1.79 + var actual7 = 'captures: ' + y.exec('1123456') + 1.80 + '; RegExp.leftContext: "' + RegExp.leftContext + 1.81 + '"; RegExp.rightContext: "' + RegExp.rightContext + '"'; 1.82 + 1.83 + reportCompare(expect6, actual6, summary + ' - /(1)/y.exec("1123456") first call'); 1.84 + reportCompare(expect7, actual7, summary + ' - /(1)/y.exec("1123456") second call'); 1.85 + 1.86 + var y = /(1)/y; 1.87 + 1.88 + reportCompare(expect, actual, summary); 1.89 + 1.90 + exitFunc ('test'); 1.91 +}