Additional tests for escape and unescape methods (#2695)

Co-authored-by: Leo Balter <leonardo.balter@gmail.com>
This commit is contained in:
QuXing9 2020-07-10 01:16:18 +08:00 committed by GitHub
parent 91a9abff4e
commit 19653bdfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 164 additions and 1 deletions

View 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');

View File

@ -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');

View 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);
});

View 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');

View 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');

View 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');

View 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);
});

View 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');