From 19653bdfc846a660d01cd7d5089cf4b21fe89fe0 Mon Sep 17 00:00:00 2001 From: QuXing9 <40267809+QuXing9@users.noreply.github.com> Date: Fri, 10 Jul 2020 01:16:18 +0800 Subject: [PATCH] Additional tests for escape and unescape methods (#2695) Co-authored-by: Leo Balter --- .../built-ins/escape/argument_bigint.js | 16 +++++++++ .../annexB/built-ins/escape/argument_types.js | 16 ++++++++- .../built-ins/escape/to-primitive-err.js | 22 +++++++++++++ .../built-ins/escape/to-primitive-observe.js | 20 +++++++++++ .../built-ins/unescape/argument_bigint.js | 16 +++++++++ .../built-ins/unescape/argument_types.js | 33 +++++++++++++++++++ .../built-ins/unescape/to-primitive-err.js | 22 +++++++++++++ .../unescape/to-primitive-observe.js | 20 +++++++++++ 8 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 test/annexB/built-ins/escape/argument_bigint.js create mode 100644 test/annexB/built-ins/escape/to-primitive-err.js create mode 100644 test/annexB/built-ins/escape/to-primitive-observe.js create mode 100644 test/annexB/built-ins/unescape/argument_bigint.js create mode 100644 test/annexB/built-ins/unescape/argument_types.js create mode 100644 test/annexB/built-ins/unescape/to-primitive-err.js create mode 100644 test/annexB/built-ins/unescape/to-primitive-observe.js diff --git a/test/annexB/built-ins/escape/argument_bigint.js b/test/annexB/built-ins/escape/argument_bigint.js new file mode 100644 index 0000000000..5f186caa85 --- /dev/null +++ b/test/annexB/built-ins/escape/argument_bigint.js @@ -0,0 +1,16 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: Input is a BigInt +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +features: [BigInt] +---*/ + +assert.sameValue(escape(1n), '1'); + +assert.sameValue(escape(-1n), '-1'); diff --git a/test/annexB/built-ins/escape/argument_types.js b/test/annexB/built-ins/escape/argument_types.js index 5eb01d5997..b4ccb175da 100644 --- a/test/annexB/built-ins/escape/argument_types.js +++ b/test/annexB/built-ins/escape/argument_types.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-escape-string -description: Input is a null, undefined or boolean +description: Input is a null, undefined, boolean or Number info: | B.2.1.1 escape ( string ) @@ -14,6 +14,20 @@ assert.sameValue(escape(null), 'null'); assert.sameValue(escape(undefined), 'undefined'); +assert.sameValue(escape(), 'undefined'); + assert.sameValue(escape(true), 'true'); assert.sameValue(escape(false), 'false'); + +assert.sameValue(escape(-0), '0'); + +assert.sameValue(escape(0), '0'); + +assert.sameValue(escape(1), '1'); + +assert.sameValue(escape(NaN), 'NaN'); + +assert.sameValue(escape(Number.POSITIVE_INFINITY), 'Infinity'); + +assert.sameValue(escape(Number.NEGATIVE_INFINITY), '-Infinity'); diff --git a/test/annexB/built-ins/escape/to-primitive-err.js b/test/annexB/built-ins/escape/to-primitive-err.js new file mode 100644 index 0000000000..5046125485 --- /dev/null +++ b/test/annexB/built-ins/escape/to-primitive-err.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: If [Symbol.toPrimitive] method returned an object, it should throw a TypeError +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return function(){}; } +}; + +assert.throws(TypeError, function() { + escape(obj); +}); diff --git a/test/annexB/built-ins/escape/to-primitive-observe.js b/test/annexB/built-ins/escape/to-primitive-observe.js new file mode 100644 index 0000000000..d059db2ec6 --- /dev/null +++ b/test/annexB/built-ins/escape/to-primitive-observe.js @@ -0,0 +1,20 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: Observable operations from string coercion +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return 'success'; } +}; + +assert.sameValue(escape(obj), 'success'); diff --git a/test/annexB/built-ins/unescape/argument_bigint.js b/test/annexB/built-ins/unescape/argument_bigint.js new file mode 100644 index 0000000000..b5ed8a5461 --- /dev/null +++ b/test/annexB/built-ins/unescape/argument_bigint.js @@ -0,0 +1,16 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: Input is a BigInt +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + .... +features: [BigInt] +---*/ + +assert.sameValue(unescape(1n), '1'); + +assert.sameValue(unescape(-1n), '-1'); diff --git a/test/annexB/built-ins/unescape/argument_types.js b/test/annexB/built-ins/unescape/argument_types.js new file mode 100644 index 0000000000..d2e8ee6981 --- /dev/null +++ b/test/annexB/built-ins/unescape/argument_types.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: Input is a null, undefined, boolean or Number +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + ... +---*/ + +assert.sameValue(unescape(null), 'null'); + +assert.sameValue(unescape(undefined), 'undefined'); + +assert.sameValue(unescape(), 'undefined'); + +assert.sameValue(unescape(true), 'true'); + +assert.sameValue(unescape(false), 'false'); + +assert.sameValue(unescape(-0), '0'); + +assert.sameValue(unescape(0), '0'); + +assert.sameValue(unescape(1), '1'); + +assert.sameValue(unescape(NaN), 'NaN'); + +assert.sameValue(unescape(Number.POSITIVE_INFINITY), 'Infinity'); + +assert.sameValue(unescape(Number.NEGATIVE_INFINITY), '-Infinity'); diff --git a/test/annexB/built-ins/unescape/to-primitive-err.js b/test/annexB/built-ins/unescape/to-primitive-err.js new file mode 100644 index 0000000000..a29922ba30 --- /dev/null +++ b/test/annexB/built-ins/unescape/to-primitive-err.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: If [Symbol.toPrimitive] method returned an object, it should throw a TypeError +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + .... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return function(){}; } +}; + +assert.throws(TypeError, function() { + unescape(obj); +}); diff --git a/test/annexB/built-ins/unescape/to-primitive-observe.js b/test/annexB/built-ins/unescape/to-primitive-observe.js new file mode 100644 index 0000000000..12cef6c8e3 --- /dev/null +++ b/test/annexB/built-ins/unescape/to-primitive-observe.js @@ -0,0 +1,20 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: Observable operations from string coercion +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + .... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return 'success'; } +}; + +assert.sameValue(unescape(obj), 'success');