mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Additional tests for escape and unescape methods (#2695)
Co-authored-by: Leo Balter <leonardo.balter@gmail.com>
This commit is contained in:
parent
91a9abff4e
commit
19653bdfc8
16
test/annexB/built-ins/escape/argument_bigint.js
Normal file
16
test/annexB/built-ins/escape/argument_bigint.js
Normal file
@ -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');
|
@ -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');
|
||||
|
22
test/annexB/built-ins/escape/to-primitive-err.js
Normal file
22
test/annexB/built-ins/escape/to-primitive-err.js
Normal file
@ -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);
|
||||
});
|
20
test/annexB/built-ins/escape/to-primitive-observe.js
Normal file
20
test/annexB/built-ins/escape/to-primitive-observe.js
Normal file
@ -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');
|
16
test/annexB/built-ins/unescape/argument_bigint.js
Normal file
16
test/annexB/built-ins/unescape/argument_bigint.js
Normal file
@ -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');
|
33
test/annexB/built-ins/unescape/argument_types.js
Normal file
33
test/annexB/built-ins/unescape/argument_types.js
Normal file
@ -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');
|
22
test/annexB/built-ins/unescape/to-primitive-err.js
Normal file
22
test/annexB/built-ins/unescape/to-primitive-err.js
Normal file
@ -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);
|
||||
});
|
20
test/annexB/built-ins/unescape/to-primitive-observe.js
Normal file
20
test/annexB/built-ins/unescape/to-primitive-observe.js
Normal file
@ -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');
|
Loading…
x
Reference in New Issue
Block a user