From bfc9020d51513c77fb2819002c9996d80bc25bcb Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg <microdan@gmail.com> Date: Fri, 28 Apr 2017 00:20:24 +0200 Subject: [PATCH] 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/ --- test/built-ins/RegExp/S15.10.4.1_A5_T2.js | 21 ---------- .../RegExp/dotall/with-dotall-unicode.js | 35 ++++++++++++++++ test/built-ins/RegExp/dotall/with-dotall.js | 35 ++++++++++++++++ .../RegExp/dotall/without-dotall-unicode.js | 34 ++++++++++++++++ .../built-ins/RegExp/dotall/without-dotall.js | 34 ++++++++++++++++ test/built-ins/RegExp/duplicate-flags.js | 18 +++++++++ .../RegExp/prototype/dotAll/length.js | 32 +++++++++++++++ .../built-ins/RegExp/prototype/dotAll/name.js | 25 ++++++++++++ .../RegExp/prototype/dotAll/prop-desc.js | 16 ++++++++ .../prototype/dotAll/this-val-invalid-obj.js | 29 ++++++++++++++ .../prototype/dotAll/this-val-non-obj.js | 40 +++++++++++++++++++ .../dotAll/this-val-regexp-prototype.js | 18 +++++++++ .../prototype/dotAll/this-val-regexp.js | 39 ++++++++++++++++++ .../built-ins/RegExp/prototype/flags/order.js | 28 +++++++++++++ test/built-ins/RegExp/prototype/flags/s.js | 23 +++++++++++ 15 files changed, 406 insertions(+), 21 deletions(-) delete mode 100644 test/built-ins/RegExp/S15.10.4.1_A5_T2.js create mode 100644 test/built-ins/RegExp/dotall/with-dotall-unicode.js create mode 100644 test/built-ins/RegExp/dotall/with-dotall.js create mode 100644 test/built-ins/RegExp/dotall/without-dotall-unicode.js create mode 100644 test/built-ins/RegExp/dotall/without-dotall.js create mode 100644 test/built-ins/RegExp/duplicate-flags.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/length.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/name.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/prop-desc.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js create mode 100644 test/built-ins/RegExp/prototype/dotAll/this-val-regexp.js create mode 100644 test/built-ins/RegExp/prototype/flags/order.js create mode 100644 test/built-ins/RegExp/prototype/flags/s.js diff --git a/test/built-ins/RegExp/S15.10.4.1_A5_T2.js b/test/built-ins/RegExp/S15.10.4.1_A5_T2.js deleted file mode 100644 index 6e0d79277b..0000000000 --- a/test/built-ins/RegExp/S15.10.4.1_A5_T2.js +++ /dev/null @@ -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)); - } -} diff --git a/test/built-ins/RegExp/dotall/with-dotall-unicode.js b/test/built-ins/RegExp/dotall/with-dotall-unicode.js new file mode 100644 index 0000000000..6625e2a577 --- /dev/null +++ b/test/built-ins/RegExp/dotall/with-dotall-unicode.js @@ -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")); +} diff --git a/test/built-ins/RegExp/dotall/with-dotall.js b/test/built-ins/RegExp/dotall/with-dotall.js new file mode 100644 index 0000000000..aef495dea5 --- /dev/null +++ b/test/built-ins/RegExp/dotall/with-dotall.js @@ -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")); +} diff --git a/test/built-ins/RegExp/dotall/without-dotall-unicode.js b/test/built-ins/RegExp/dotall/without-dotall-unicode.js new file mode 100644 index 0000000000..8de7369af9 --- /dev/null +++ b/test/built-ins/RegExp/dotall/without-dotall-unicode.js @@ -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")); +} diff --git a/test/built-ins/RegExp/dotall/without-dotall.js b/test/built-ins/RegExp/dotall/without-dotall.js new file mode 100644 index 0000000000..1a52d51e44 --- /dev/null +++ b/test/built-ins/RegExp/dotall/without-dotall.js @@ -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")); +} diff --git a/test/built-ins/RegExp/duplicate-flags.js b/test/built-ins/RegExp/duplicate-flags.js new file mode 100644 index 0000000000..5ba1204da7 --- /dev/null +++ b/test/built-ins/RegExp/duplicate-flags.js @@ -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"); diff --git a/test/built-ins/RegExp/prototype/dotAll/length.js b/test/built-ins/RegExp/prototype/dotAll/length.js new file mode 100644 index 0000000000..cc6fe55290 --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/length.js @@ -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"); diff --git a/test/built-ins/RegExp/prototype/dotAll/name.js b/test/built-ins/RegExp/prototype/dotAll/name.js new file mode 100644 index 0000000000..06d8f07a4e --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/name.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/dotAll/prop-desc.js b/test/built-ins/RegExp/prototype/dotAll/prop-desc.js new file mode 100644 index 0000000000..babf99e28f --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/prop-desc.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js b/test/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js new file mode 100644 index 0000000000..1557946b7f --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js b/test/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js new file mode 100644 index 0000000000..c9325a3cba --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js @@ -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); +}); diff --git a/test/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js b/test/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js new file mode 100644 index 0000000000..686bd0dfb7 --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js @@ -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); diff --git a/test/built-ins/RegExp/prototype/dotAll/this-val-regexp.js b/test/built-ins/RegExp/prototype/dotAll/this-val-regexp.js new file mode 100644 index 0000000000..4d45bb49af --- /dev/null +++ b/test/built-ins/RegExp/prototype/dotAll/this-val-regexp.js @@ -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); diff --git a/test/built-ins/RegExp/prototype/flags/order.js b/test/built-ins/RegExp/prototype/flags/order.js new file mode 100644 index 0000000000..141cf21342 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/order.js @@ -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); diff --git a/test/built-ins/RegExp/prototype/flags/s.js b/test/built-ins/RegExp/prototype/flags/s.js new file mode 100644 index 0000000000..f70aa3a4ac --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/s.js @@ -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'); -- GitLab