mirror of https://github.com/tc39/test262.git
Tests for RegExp dotAll proposal (#997)
Proposal from @mathiasbynens at https://github.com/tc39/proposal-regexp-dotall-flag and https://tc39.github.io/proposal-regexp-dotall-flag/
This commit is contained in:
parent
91c53231d0
commit
bfc9020d51
|
@ -1,21 +0,0 @@
|
||||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
info: >
|
|
||||||
If F contains any character other than 'g', 'i', or 'm', or if it
|
|
||||||
contains the same one more than once, then throw a SyntaxError exception
|
|
||||||
es5id: 15.10.4.1_A5_T2
|
|
||||||
description: >
|
|
||||||
Checking if using "migg" as F leads to throwing the correct
|
|
||||||
exception
|
|
||||||
---*/
|
|
||||||
|
|
||||||
//CHECK#1
|
|
||||||
try {
|
|
||||||
$ERROR('#1.1: new RegExp(null,"migg") throw SyntaxError. Actual: ' + (new RegExp(null,"migg")));
|
|
||||||
} catch (e) {
|
|
||||||
if ((e instanceof SyntaxError) !== true) {
|
|
||||||
$ERROR('#1.2: new RegExp(null,"migg") throw SyntaxError. Actual: ' + (e));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the characters included by . in dotAll and unicode mode
|
||||||
|
info: |
|
||||||
|
21.2.2.8 Atom
|
||||||
|
The production Atom::. evaluates as follows:
|
||||||
|
1. If DotAll is true, then
|
||||||
|
a. Let A be the set of all characters.
|
||||||
|
2. Otherwise, let A be the set of all characters except LineTerminator.
|
||||||
|
3. Call CharacterSetMatcher(A, false) and return its Matcher result.
|
||||||
|
|
||||||
|
esid: sec-atom
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// The behavior is the same regardless of the m flag
|
||||||
|
for (let re of [/^.$/su, /^.$/sum]) {
|
||||||
|
assert(re.test("a"));
|
||||||
|
assert(re.test("3"));
|
||||||
|
assert(re.test("π"));
|
||||||
|
assert(re.test("\u2027"));
|
||||||
|
assert(re.test("\u0085"));
|
||||||
|
assert(re.test("\v"));
|
||||||
|
assert(re.test("\f"));
|
||||||
|
assert(re.test("\u180E"));
|
||||||
|
assert(re.test("\u{10300}"), "Supplementary plane matched by a single .");
|
||||||
|
assert(re.test("\n"));
|
||||||
|
assert(re.test("\r"));
|
||||||
|
assert(re.test("\u2028"));
|
||||||
|
assert(re.test("\u2029"));
|
||||||
|
assert(re.test("\uD800"));
|
||||||
|
assert(re.test("\uDFFF"));
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the characters included by . in dotAll and non-unicode mode
|
||||||
|
info: |
|
||||||
|
21.2.2.8 Atom
|
||||||
|
The production Atom::. evaluates as follows:
|
||||||
|
1. If DotAll is true, then
|
||||||
|
a. Let A be the set of all characters.
|
||||||
|
2. Otherwise, let A be the set of all characters except LineTerminator.
|
||||||
|
3. Call CharacterSetMatcher(A, false) and return its Matcher result.
|
||||||
|
|
||||||
|
esid: sec-atom
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// The behavior is the same regardless of the m flag
|
||||||
|
for (let re of [/^.$/s, /^.$/sm]) {
|
||||||
|
assert(re.test("a"));
|
||||||
|
assert(re.test("3"));
|
||||||
|
assert(re.test("π"));
|
||||||
|
assert(re.test("\u2027"));
|
||||||
|
assert(re.test("\u0085"));
|
||||||
|
assert(re.test("\v"));
|
||||||
|
assert(re.test("\f"));
|
||||||
|
assert(re.test("\u180E"));
|
||||||
|
assert(!re.test("\u{10300}"), "Supplementary plane not matched by a single .");
|
||||||
|
assert(re.test("\n"));
|
||||||
|
assert(re.test("\r"));
|
||||||
|
assert(re.test("\u2028"));
|
||||||
|
assert(re.test("\u2029"));
|
||||||
|
assert(re.test("\uD800"));
|
||||||
|
assert(re.test("\uDFFF"));
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Without the dotAll flag, . does not match newlines in Unicode mode
|
||||||
|
info: |
|
||||||
|
21.2.2.8 Atom
|
||||||
|
The production Atom::. evaluates as follows:
|
||||||
|
1. If DotAll is true, then
|
||||||
|
a. Let A be the set of all characters.
|
||||||
|
2. Otherwise, let A be the set of all characters except LineTerminator.
|
||||||
|
3. Call CharacterSetMatcher(A, false) and return its Matcher result.
|
||||||
|
|
||||||
|
esid: sec-atom
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// The behavior is the same regardless of the m flag
|
||||||
|
for (let re of [/^.$/u, /^.$/um]) {
|
||||||
|
assert(re.test("a"));
|
||||||
|
assert(re.test("3"));
|
||||||
|
assert(re.test("π"));
|
||||||
|
assert(re.test("\u2027"));
|
||||||
|
assert(re.test("\u0085"));
|
||||||
|
assert(re.test("\v"));
|
||||||
|
assert(re.test("\f"));
|
||||||
|
assert(re.test("\u180E"));
|
||||||
|
assert(re.test("\u{10300}"), "Supplementary plane matched by a single .");
|
||||||
|
assert(!re.test("\n"));
|
||||||
|
assert(!re.test("\r"));
|
||||||
|
assert(!re.test("\u2028"));
|
||||||
|
assert(!re.test("\u2029"));
|
||||||
|
assert(re.test("\uD800"));
|
||||||
|
assert(re.test("\uDFFF"));
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Without the dotAll flag, . does not match newlines
|
||||||
|
info: |
|
||||||
|
21.2.2.8 Atom
|
||||||
|
The production Atom::. evaluates as follows:
|
||||||
|
1. If DotAll is true, then
|
||||||
|
a. Let A be the set of all characters.
|
||||||
|
2. Otherwise, let A be the set of all characters except LineTerminator.
|
||||||
|
3. Call CharacterSetMatcher(A, false) and return its Matcher result.
|
||||||
|
|
||||||
|
esid: sec-atom
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// The behavior is the same regardless of the m flag
|
||||||
|
for (let re of [/^.$/, /^.$/m]) {
|
||||||
|
assert(re.test("a"));
|
||||||
|
assert(re.test("3"));
|
||||||
|
assert(re.test("π"));
|
||||||
|
assert(re.test("\u2027"));
|
||||||
|
assert(re.test("\u0085"));
|
||||||
|
assert(re.test("\v"));
|
||||||
|
assert(re.test("\f"));
|
||||||
|
assert(re.test("\u180E"));
|
||||||
|
assert(!re.test("\u{10300}"), "Supplementary plane matched by a single .");
|
||||||
|
assert(!re.test("\n"));
|
||||||
|
assert(!re.test("\r"));
|
||||||
|
assert(!re.test("\u2028"));
|
||||||
|
assert(!re.test("\u2029"));
|
||||||
|
assert(re.test("\uD800"));
|
||||||
|
assert(re.test("\uDFFF"));
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
info: >
|
||||||
|
RegExpInitialize ( obj, pattern, flags )
|
||||||
|
5. If F contains any code unit other than "g", "i", "m", "s", "u", or "y" or if it contains the same code unit more than once, throw a SyntaxError exception.
|
||||||
|
esid: sec-regexpinitialize
|
||||||
|
description: Check that duplicate RegExp flags are disallowed
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, () => new RegExp("", "migg"), "duplicate g");
|
||||||
|
assert.throws(SyntaxError, () => new RegExp("", "ii"), "duplicate i");
|
||||||
|
assert.throws(SyntaxError, () => new RegExp("", "mm"), "duplicate m");
|
||||||
|
assert.throws(SyntaxError, () => new RegExp("", "ss"), "duplicate s");
|
||||||
|
assert.throws(SyntaxError, () => new RegExp("", "uu"), "duplicate u");
|
||||||
|
assert.throws(SyntaxError, () => new RegExp("", "yy"), "duplicate y");
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: >
|
||||||
|
get RegExp.prototype.dotAll.length is 0.
|
||||||
|
info: >
|
||||||
|
get RegExp.prototype.dotAll
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, has a length
|
||||||
|
property whose value is an integer. Unless otherwise specified, this
|
||||||
|
value is equal to the largest number of named arguments shown in the
|
||||||
|
subclause headings for the function description, including optional
|
||||||
|
parameters. However, rest parameters shown using the form “...name”
|
||||||
|
are not included in the default argument count.
|
||||||
|
|
||||||
|
Unless otherwise specified, the length property of a built-in Function
|
||||||
|
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||||
|
[[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll");
|
||||||
|
|
||||||
|
assert.sameValue(desc.get.length, 0);
|
||||||
|
|
||||||
|
verifyNotEnumerable(desc.get, "length");
|
||||||
|
verifyNotWritable(desc.get, "length");
|
||||||
|
verifyConfigurable(desc.get, "length");
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: >
|
||||||
|
RegExp.prototype.dotAll name
|
||||||
|
info: >
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
Functions that are specified as get or set accessor functions of built-in
|
||||||
|
properties have "get " or "set " prepended to the property name string.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll');
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
descriptor.get.name,
|
||||||
|
'get dotAll'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(descriptor.get, 'name');
|
||||||
|
verifyNotWritable(descriptor.get, 'name');
|
||||||
|
verifyConfigurable(descriptor.get, 'name');
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: >
|
||||||
|
`pending` property descriptor
|
||||||
|
info: >
|
||||||
|
RegExp.prototype.dotAll is an accessor property whose set accessor
|
||||||
|
function is undefined.
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll');
|
||||||
|
|
||||||
|
assert.sameValue(desc.set, undefined);
|
||||||
|
assert.sameValue(typeof desc.get, 'function');
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Invoked on an object without an [[OriginalFlags]] internal slot
|
||||||
|
esid: pending
|
||||||
|
info: >
|
||||||
|
get RegExp.prototype.dotAll
|
||||||
|
|
||||||
|
1. Let R be the this value.
|
||||||
|
2. If Type(R) is not Object, throw a TypeError exception.
|
||||||
|
3. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var dotAll = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll').get;
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call({});
|
||||||
|
}, 'ordinary object');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call([]);
|
||||||
|
}, 'array exotic object');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call(arguments);
|
||||||
|
}, 'arguments object');
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
`dotAll` accessor invoked on a non-object value
|
||||||
|
esid: pending
|
||||||
|
info: >
|
||||||
|
get RegExp.prototype.dotAll
|
||||||
|
|
||||||
|
1. Let R be the this value.
|
||||||
|
2. If Type(R) is not Object, throw a TypeError exception.
|
||||||
|
features: [Symbol, regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var dotAll = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll').get;
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call(Symbol('s'));
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
dotAll.call(4);
|
||||||
|
});
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: >
|
||||||
|
Return value of `undefined` when the "this" value is the RegExp prototype
|
||||||
|
object
|
||||||
|
info: |
|
||||||
|
1. Let R be the this value.
|
||||||
|
2. If Type(R) is not Object, throw a TypeError exception.
|
||||||
|
3. If R does not have an [[OriginalFlags]] internal slot, then
|
||||||
|
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll').get;
|
||||||
|
|
||||||
|
assert.sameValue(get.call(RegExp.prototype), undefined);
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
`dotAll` accessor function invoked on a RegExp instance
|
||||||
|
esid: pending
|
||||||
|
info: >
|
||||||
|
21.2.5.12 get RegExp.prototype.dotAll
|
||||||
|
|
||||||
|
4. Let flags be the value of R’s [[OriginalFlags]] internal slot.
|
||||||
|
5. If flags contains the code unit "s", return true.
|
||||||
|
6. Return false.
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(/./.dotAll, false);
|
||||||
|
assert.sameValue(/./i.dotAll, false);
|
||||||
|
assert.sameValue(/./g.dotAll, false);
|
||||||
|
assert.sameValue(/./y.dotAll, false);
|
||||||
|
assert.sameValue(/./m.dotAll, false);
|
||||||
|
|
||||||
|
assert.sameValue(/./s.dotAll, true);
|
||||||
|
assert.sameValue(/./is.dotAll, true);
|
||||||
|
assert.sameValue(/./sg.dotAll, true);
|
||||||
|
assert.sameValue(/./is.dotAll, true);
|
||||||
|
assert.sameValue(/./ms.dotAll, true);
|
||||||
|
|
||||||
|
assert.sameValue(new RegExp(".", "").dotAll, false);
|
||||||
|
assert.sameValue(new RegExp(".", "i").dotAll, false);
|
||||||
|
assert.sameValue(new RegExp(".", "g").dotAll, false);
|
||||||
|
assert.sameValue(new RegExp(".", "y").dotAll, false);
|
||||||
|
assert.sameValue(new RegExp(".", "m").dotAll, false);
|
||||||
|
|
||||||
|
assert.sameValue(new RegExp(".", "s").dotAll, true);
|
||||||
|
assert.sameValue(new RegExp(".", "is").dotAll, true);
|
||||||
|
assert.sameValue(new RegExp(".", "sg").dotAll, true);
|
||||||
|
assert.sameValue(new RegExp(".", "is").dotAll, true);
|
||||||
|
assert.sameValue(new RegExp(".", "ms").dotAll, true);
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (C) 2017 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.flags
|
||||||
|
description: >
|
||||||
|
RegExp.prototype.flags come in a single order, independent of source order
|
||||||
|
info: >
|
||||||
|
4. Let global be ToBoolean(? Get(R, "global")).
|
||||||
|
5. If global is true, append "g" as the last code unit of result.
|
||||||
|
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
|
||||||
|
7. If ignoreCase is true, append "i" as the last code unit of result.
|
||||||
|
8. Let multiline be ToBoolean(? Get(R, "multiline")).
|
||||||
|
9. If multiline is true, append "m" as the last code unit of result.
|
||||||
|
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
|
||||||
|
11. If dotAll is true, append "s" as the last code unit of result.
|
||||||
|
12. Let unicode be ToBoolean(? Get(R, "unicode")).
|
||||||
|
13. If unicode is true, append "u" as the last code unit of result.
|
||||||
|
14. Let sticky be ToBoolean(? Get(R, "sticky")).
|
||||||
|
15. If sticky is true, append "y" as the last code unit of result.
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue("gimsuy", new RegExp("", "gimsuy").flags);
|
||||||
|
assert.sameValue("gimsuy", new RegExp("", "yusmig").flags);
|
||||||
|
|
||||||
|
let re = /(?:)/;
|
||||||
|
re.compile("(?:)", "imsuyg");
|
||||||
|
assert.sameValue("gimsuy", re.flags);
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
's' entry's presence is determined by `s` flag
|
||||||
|
esid: sec-get-regexp.prototype.flags
|
||||||
|
info: >
|
||||||
|
21.2.5.3 get RegExp.prototype.flags
|
||||||
|
|
||||||
|
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
|
||||||
|
11. If dotAll is true, append "s" as the last code unit of result.
|
||||||
|
features: [regexp-dotall]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var flags;
|
||||||
|
|
||||||
|
flags = /./s.flags;
|
||||||
|
assert.sameValue(flags, 's');
|
||||||
|
|
||||||
|
let re = /./;
|
||||||
|
Object.defineProperty(re, 'dotAll', {value: true});
|
||||||
|
assert.sameValue(re.flags, 's');
|
Loading…
Reference in New Issue