mirror of https://github.com/tc39/test262.git
String.prototype.codePointAt
This commit is contained in:
parent
0599e839a3
commit
c6c61bd50d
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Property type and descriptor.
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof String.prototype.codePointAt,
|
||||
'function',
|
||||
'`typeof String.prototype.codePointAt` is `function`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(String.prototype, 'codePointAt');
|
||||
verifyWritable(String.prototype, 'codePointAt');
|
||||
verifyConfigurable(String.prototype, 'codePointAt');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
String.prototype.codePointAt.length value and descriptor.
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
String.prototype.codePointAt.length, 1,
|
||||
'The value of `String.prototype.codePointAt.length` is `1`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(String.prototype.codePointAt, 'length');
|
||||
verifyNotWritable(String.prototype.codePointAt, 'length');
|
||||
verifyConfigurable(String.prototype.codePointAt, 'length');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
String.prototype.codePointAt.name value and descriptor.
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
String.prototype.codePointAt.name, 'codePointAt',
|
||||
'The value of `String.prototype.codePointAt.name` is `"codePointAt"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(String.prototype.codePointAt, 'name');
|
||||
verifyNotWritable(String.prototype.codePointAt, 'name');
|
||||
verifyConfigurable(String.prototype.codePointAt, 'name');
|
25
test/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js
vendored
Normal file
25
test/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Returns abrupt from ToInteger(pos)
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
4. Let position be ToInteger(pos).
|
||||
5. ReturnIfAbrupt(position).
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
'abc'.codePointAt(o);
|
||||
});
|
22
test/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js
vendored
Normal file
22
test/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Returns abrupt from ToInteger(pos)
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
4. Let position be ToInteger(pos).
|
||||
5. ReturnIfAbrupt(position).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
'abc'.codePointAt(s);
|
||||
});
|
20
test/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js
vendored
Normal file
20
test/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Returns abrupt from ToString(this) where this is a Symbol
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
String.prototype.codePointAt.call(s, 1);
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Returns abrupt from ToString(this)
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
String.prototype.codePointAt.call(o, 1);
|
||||
});
|
26
test/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js
vendored
Normal file
26
test/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Return value on coerced values on ToInteger(position).
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
...
|
||||
4. Let position be ToInteger(pos).
|
||||
...
|
||||
|
||||
---*/
|
||||
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(''), 65536);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt('0'), 65536);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(NaN), 65536);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(false), 65536);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(null), 65536);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(undefined), 65536);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt([]), 65536);
|
||||
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt('1'), 56320);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(true), 56320);
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt([1]), 56320);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Returns code point of LeadSurrogate if not followed by a valid TrailSurrogate.
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
...
|
||||
8. Let first be the code unit value of the element at index position in the
|
||||
String S.
|
||||
9. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first.
|
||||
10. Let second be the code unit value of the element at index position+1 in
|
||||
the String S.
|
||||
11. If second < 0xDC00 or second > 0xDFFF, return first.
|
||||
---*/
|
||||
|
||||
assert.sameValue('\uD800\uDBFF'.codePointAt(0), 0xD800);
|
||||
assert.sameValue('\uD800\uE000'.codePointAt(0), 0xD800);
|
||||
|
||||
assert.sameValue('\uDAAA\uDBFF'.codePointAt(0), 0xDAAA);
|
||||
assert.sameValue('\uDAAA\uE000'.codePointAt(0), 0xDAAA);
|
||||
|
||||
assert.sameValue('\uDBFF\uDBFF'.codePointAt(0), 0xDBFF);
|
||||
assert.sameValue('\uDBFF\uE000'.codePointAt(0), 0xDBFF);
|
||||
|
||||
assert.sameValue('\uD800\u0000'.codePointAt(0), 0xD800);
|
||||
assert.sameValue('\uD800\uFFFF'.codePointAt(0), 0xD800);
|
||||
|
||||
assert.sameValue('\uDAAA\u0000'.codePointAt(0), 0xDAAA);
|
||||
assert.sameValue('\uDAAA\uFFFF'.codePointAt(0), 0xDAAA);
|
||||
|
||||
assert.sameValue('\uDBFF\uDBFF'.codePointAt(0), 0xDBFF);
|
||||
assert.sameValue('\uDBFF\uFFFF'.codePointAt(0), 0xDBFF);
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Return single code unit value of the element at index position.
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
4. Let position be ToInteger(pos).
|
||||
5. ReturnIfAbrupt(position).
|
||||
6. Let size be the number of elements in S.
|
||||
7. If position < 0 or position ≥ size, return undefined.
|
||||
8. Let first be the code unit value of the element at index position in the
|
||||
String S.
|
||||
9. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first.
|
||||
---*/
|
||||
|
||||
assert.sameValue('abc'.codePointAt(0), 97);
|
||||
assert.sameValue('abc'.codePointAt(1), 98);
|
||||
assert.sameValue('abc'.codePointAt(2), 99);
|
||||
|
||||
assert.sameValue('\uAAAA\uBBBB'.codePointAt(0), 0xAAAA);
|
||||
assert.sameValue('\uD7FF\uAAAA'.codePointAt(0), 0xD7FF);
|
||||
assert.sameValue('\uDC00\uAAAA'.codePointAt(0), 0xDC00);
|
||||
assert.sameValue('\uAAAA\uBBBB'.codePointAt(0), 0xAAAA);
|
||||
|
||||
assert.sameValue('123\uD800'.codePointAt(3), 0xD800);
|
||||
assert.sameValue('123\uDAAA'.codePointAt(3), 0xDAAA);
|
||||
assert.sameValue('123\uDBFF'.codePointAt(3), 0xDBFF);
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Return UTF16 Decode value of the lead and trail elements at index position.
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
...
|
||||
8. Let first be the code unit value of the element at index position in the
|
||||
String S.
|
||||
9. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first.
|
||||
10. Let second be the code unit value of the element at index position+1 in
|
||||
the String S.
|
||||
11. If second < 0xDC00 or second > 0xDFFF, return first.
|
||||
12. Return UTF16Decode(first, second).
|
||||
|
||||
10.1.2 Static Semantics: UTF16Decode( lead, trail )
|
||||
|
||||
Two code units, lead and trail, that form a UTF-16 surrogate pair are
|
||||
converted to a code point by performing the following steps:
|
||||
|
||||
1. Assert: 0xD800 ≤ lead ≤ 0xDBFF and 0xDC00 ≤ trail ≤ 0xDFFF.
|
||||
2. Let cp be (lead – 0xD800) × 1024 + (trail – 0xDC00) + 0x10000.
|
||||
3. Return the code point cp.
|
||||
---*/
|
||||
|
||||
assert.sameValue('\uD800\uDC00'.codePointAt(0), 65536, 'U+10000');
|
||||
assert.sameValue('\uD800\uDDD0'.codePointAt(0), 66000, 'U+101D0');
|
||||
assert.sameValue('\uD800\uDFFF'.codePointAt(0), 66559, 'U+103FF');
|
||||
|
||||
assert.sameValue('\uDAAA\uDC00'.codePointAt(0), 763904, 'U+BA800');
|
||||
assert.sameValue('\uDAAA\uDDD0'.codePointAt(0), 764368, 'U+BA9D0');
|
||||
assert.sameValue('\uDAAA\uDFFF'.codePointAt(0), 764927, 'U+BABFF');
|
||||
|
||||
assert.sameValue('\uDBFF\uDC00'.codePointAt(0), 1113088, 'U+10FC00');
|
||||
assert.sameValue('\uDBFF\uDDD0'.codePointAt(0), 1113552, 'U+10FDD0');
|
||||
assert.sameValue('\uDBFF\uDFFF'.codePointAt(0), 1114111, 'U+10FFFF');
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
If pos >= size, return undefined
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
4. Let position be ToInteger(pos).
|
||||
5. ReturnIfAbrupt(position).
|
||||
6. Let size be the number of elements in S.
|
||||
7. If position < 0 or position ≥ size, return undefined.
|
||||
---*/
|
||||
|
||||
assert.sameValue('abc'.codePointAt(3), undefined);
|
||||
assert.sameValue('abc'.codePointAt(4), undefined);
|
||||
assert.sameValue('abc'.codePointAt(Infinity), undefined);
|
20
test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js
vendored
Normal file
20
test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
If pos < size, return undefined
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
3. ReturnIfAbrupt(S).
|
||||
4. Let position be ToInteger(pos).
|
||||
5. ReturnIfAbrupt(position).
|
||||
6. Let size be the number of elements in S.
|
||||
7. If position < 0 or position ≥ size, return undefined.
|
||||
---*/
|
||||
|
||||
assert.sameValue('abc'.codePointAt(-1), undefined);
|
||||
assert.sameValue('abc'.codePointAt(-Infinity), undefined);
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Throws TypeError when `this` is null
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
String.prototype.codePointAt.call(null, 1);
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.1.3.3
|
||||
description: >
|
||||
Throws TypeError when `this` is undefined
|
||||
info: >
|
||||
21.1.3.3 String.prototype.codePointAt ( pos )
|
||||
|
||||
1. Let O be RequireObjectCoercible(this value).
|
||||
2. Let S be ToString(O).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
String.prototype.codePointAt.call(undefined, 1);
|
||||
});
|
Loading…
Reference in New Issue