Add tests for return value: 'get RegExp.p.source'

This commit is contained in:
Mike Pennisi 2016-06-28 19:05:08 -04:00
parent e1cd1e7f85
commit b9587262d4
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,25 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.source
es6id: 21.2.5.10
description: >
Return value can be used to create an equivalent RegExp when the
[[OriginalSource]] internal slot is the empty string
21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
[...] the internal procedure that would result from evaluating S as a
Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
internal procedure given by the constructed object's [[RegExpMatcher]]
internal slot.
info: |
[...]
5. Let src be R.[[OriginalSource]].
6. Let flags be R.[[OriginalFlags]].
7. Return EscapeRegExpPattern(src, flags).
---*/
var re = eval('/' + new RegExp('').source + '/');
assert.sameValue(re.test(''), true);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.source
es6id: 21.2.5.10
description: >
Return value can be used to create an equivalent RegExp when the
[[OriginalSource]] internal slot contains a LineTerminator
info: |
[...]
5. Let src be R.[[OriginalSource]].
6. Let flags be R.[[OriginalFlags]].
7. Return EscapeRegExpPattern(src, flags).
21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
[...] the internal procedure that would result from evaluating S as a
Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
internal procedure given by the constructed object's [[RegExpMatcher]]
internal slot.
---*/
var re = eval('/' + new RegExp('\n').source + '/');
assert.sameValue(re.test('\n'), true, 'input: "\\n"');
assert.sameValue(re.test('_\n_'), true, 'input: "_\\n_"');
assert.sameValue(re.test('\\n'), false, 'input: "\\\\n"');
assert.sameValue(re.test('\r'), false, 'input: "\\r"');
assert.sameValue(re.test('n'), false, 'input: "n"');

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.source
es6id: 21.2.5.10
description: >
Return value can be used to create an equivalent RegExp when the
[[OriginalFlags]] internal slot contains the `u` flag
info: |
[...]
5. Let src be R.[[OriginalSource]].
6. Let flags be R.[[OriginalFlags]].
7. Return EscapeRegExpPattern(src, flags).
21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
[...] the internal procedure that would result from evaluating S as a
Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
internal procedure given by the constructed object's [[RegExpMatcher]]
internal slot.
---*/
var re;
re = eval('/' + /\ud834\udf06/u.source + '/u');
assert.sameValue(re.test('\ud834\udf06'), true);
assert.sameValue(re.test('𝌆'), true);
re = eval('/' + /\u{1d306}/u.source + '/u');
assert.sameValue(re.test('\ud834\udf06'), true);
assert.sameValue(re.test('𝌆'), true);

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.source
es6id: 21.2.5.10
description: Return value can be used to create an equivalent RegExp
info: |
[...]
5. Let src be R.[[OriginalSource]].
6. Let flags be R.[[OriginalFlags]].
7. Return EscapeRegExpPattern(src, flags).
21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern
[...] the internal procedure that would result from evaluating S as a
Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the
internal procedure given by the constructed object's [[RegExpMatcher]]
internal slot.
---*/
var re = eval('/' + /ab{2,4}c$/.source + '/');
assert(re.test('abbc'), 'input: abbc');
assert(re.test('abbbc'), 'input: abbbc');
assert(re.test('abbbbc'), 'input: abbbbc');
assert(re.test('xabbc'), 'input: xabbc');
assert(re.test('xabbbc'), 'input: xabbbc');
assert(re.test('xabbbbc'), 'input: xabbbbc');
assert.sameValue(re.test('ac'), false, 'input: ac');
assert.sameValue(re.test('abc'), false, 'input: abc');
assert.sameValue(re.test('abbcx'), false, 'input: abbcx');
assert.sameValue(re.test('bbc'), false, 'input: bbc');
assert.sameValue(re.test('abb'), false, 'input: abb');
assert.sameValue(re.test('abbbbbc'), false, 'input: abbbbbc');