JE

 view release on metacpan or  search on metacpan

t/15.10-regexp-objects.t  view on Meta::CPAN

ok(!RegExp.prototype.propertyIsEnumerable('constructor'),
	'RegExp.prototype.constructor is not enumerable')

// ===================================================
// 15.10.6.2 exec
// ===================================================

// 10 tests
method_boilerplate_tests(RegExp.prototype,'exec',1)

// 4 tests for misc this values
0,function(){
	var f = RegExp.prototype.exec;
	var testname='exec with number for this';
	try{f.call(8); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
	var testname='exec with non-re object for this';
	try{f.call({}); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
	var testname='exec with string for this';
	try{f.call('true'); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
	var testname='exec with bool for this';
	try{f.call('true'); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
}()

// 1 test: Make sure exec can be called */

try{is(/a/.exec('a'), 'a', 'exec doesn\'t simply die')}
catch(e){fail('exec doesn\'t simply die')}

// 6 tests: various types for the arg
is(/..o/i.exec({}), 't O', 'exec with object arg')
is(/T/i.exec(true), 't', 'exec with boolean arg')
is(/[89]/i.exec(78), '8', 'exec with numeric arg')
is(/U/i.exec(null), 'u', 'exec with null arg')
is(/U./i.exec(void 0), 'un', 'exec with undefined arg')
is(/U./i.exec(), 'un', 'exec with no arg')

// 19 tests: exec and lastIndex
r = /a./
r.lastIndex=2
is(r.exec("the abacus"), 'ab', 'exec ignores lastIndex without /g')
rg = /a./g
rg.lastIndex=6
is(rg.exec("the abacus"), "ac", 'exec respects lastIndex with /g')
is(typeof rg.lastIndex + ': ' + rg.lastIndex, 'number: 8',
  'exec sets lastIndex')
rg.lastIndex=1.9
is(rg.exec('aah'), 'ah', 'exec with fractional lastIndex')
rg.lastIndex=57
is(rg.exec('abc'), null, 'exec with large lastIndex')
is(rg.lastIndex, 0,'exec with large lastIndex resets index to 0')
r.lastIndex=57
r.exec('the')
is(r.lastIndex, 0,'exec failure resets lastIndex even without /g')
rg.lastIndex=-5
is(rg.exec('abc'), null, 'exec with negative lastIndex')
is(rg.lastIndex, 0,'exec with negative lastIndex resets index to 0')
rg.lastIndex=NaN
is(rg.exec('abc'), 'ab', 'exec with NaN lastIndex')
;(rg2=/./g).lastIndex=Infinity
is(rg2.exec('abc'), null, 'exec with infinite lastIndex')
;(rg2=/(?:)/g).lastIndex=4
is(rg2.exec('abc'), null, 'exec with large lastIndex and null pattern')
r.lastIndex="57"
is(r.exec("abc"), "ab", 'exec ignores lastIndex without /g')
is(typeof r.lastIndex + ': ' + r.lastIndex, "string: 57",
  'successful exec without /g leaves lastIndex untouched');
rg.lastIndex="1"; is(rg.exec('abac'), 'ac', 'exec with string lastIndex')
rg.lastIndex=true; is(rg.exec('abac'), 'ac', 'exec with bool lastIndex')
rg.lastIndex=null; is(rg.exec('abac'), 'ab', 'exec with null lastIndex')
rg.lastIndex={}; is(rg.exec('abac'), 'ab', 'exec w/ objective lastIndex')
rg.lastIndex=void 0; is(rg.exec('abac'), 'ab', 'exec with undef lastIndex')

// 9 tests for the return value
r = /(u)(.)(.)/.exec(new String("squow"))
ok(r.constructor === Array, 'exec retval is an array')
is(r.length, 4, 'exec retval is one more than the number of captures')
ok(r.input === 'squow', 'exec retval .input is a plain string')
ok(r.index === 2, 'index property of exec retval')
is(r[0], 'uow', 'first elem of exec retval')
is(r[1], 'u', 'Subsequent elements of the return value of')
is(r[2], 'o', 'exec contain the  captured')
is(r[3], 'w', 'substrings.')
ok(!(4 in r), 'only as many positive int props as there are captures')

// 2 tests: function-style call (implicit exec)
is(
  /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/("11.12.13.14"),
 "11.12.13.14,11,12,13,14",
 'regexp()'
)
is(
  {foo:/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/}.foo("11.12.13.14"), 
 "11.12.13.14,11,12,13,14",
 'object.regexp()'
)

// 1 test
error = false
try{RegExp.prototype.exec.apply([])}
catch(e){error = e}
ok(error instanceof TypeError, 'exec death')


// ===================================================
// 15.10.6.3 test
// 2 tests
// ===================================================

// 10 tests
method_boilerplate_tests(RegExp.prototype,'test',1)

// 4 tests for misc this values
0,function(){
	var f = RegExp.prototype.test;
	var testname='test with number for this';
	try{f.call(8); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
	var testname='test with non-re object for this';



( run in 0.985 second using v1.01-cache-2.11-cpan-5a3173703d6 )