Skip to content
Snippets Groups Projects
Commit 0599e839 authored by Brian Terlson's avatar Brian Terlson
Browse files

Merge pull request #349 from bocoup/String.fromCodePoint

Add tests for String.fromCodePoint
parents 13ebbebf 57b7d137
No related branches found
No related tags found
No related merge requests found
Showing with 290 additions and 0 deletions
// 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.2.2
description: >
Return abrupt from ToNumber(next).
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
features: [Symbol]
---*/
assert.throws(TypeError, function() {
String.fromCodePoint(Symbol());
});
assert.throws(TypeError, function() {
String.fromCodePoint(42, Symbol());
});
// 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.2.2
description: >
Throw a RangeError if an argument is not equal to its Integer representation.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
d. If SameValue(nextCP, ToInteger(nextCP)) is false, throw a RangeError
exception.
...
---*/
assert.throws(RangeError, function() {
String.fromCodePoint(3.14);
});
assert.throws(RangeError, function() {
String.fromCodePoint(42, 3.14);
});
assert.throws(RangeError, function() {
String.fromCodePoint('3.14');
});
// ToNumber(undefined) returns NaN.
assert.throws(RangeError, function() {
String.fromCodePoint(undefined);
});
assert.throws(RangeError, function() {
String.fromCodePoint('_1');
});
assert.throws(RangeError, function() {
String.fromCodePoint('1a');
});
// 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.2.2
description: >
Return abrupt from ToNumber(next).
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
---*/
var obj = {};
Object.defineProperty(obj, 'item', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
String.fromCodePoint({
valueOf: function() {
throw new Test262Error();
}
});
});
assert.throws(Test262Error, function() {
String.fromCodePoint(42, {
valueOf: function() {
throw new Test262Error();
}
});
});
// 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.2.2
description: >
The the arguments list is empty, an empty string is returned.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
...
5. Repeat while nextIndex < length
...
f. Append the elements of the UTF16Encoding (10.1.1) of nextCP to the end of
elements.
g. Let nextIndex be nextIndex + 1.
6. Return the String value whose elements are, in order, the elements in the
List elements. If length is 0, the empty string is returned.
---*/
assert.sameValue(String.fromCodePoint(), '');
// 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.2.2
description: >
String.fromCodePoint property descriptor
info: >
String.fromCodePoint ( ...codePoints )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(String, 'fromCodePoint');
verifyWritable(String, 'fromCodePoint');
verifyConfigurable(String, 'fromCodePoint');
// 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.2.2
description: >
The length property of the String.fromCodePoint constructor is 1.
includes: [propertyHelper.js]
---*/
assert.sameValue(
String.fromCodePoint.length, 1,
'The value of `String.fromCodePoint.length` is `1`'
);
verifyNotEnumerable(String.fromCodePoint, 'length');
verifyNotWritable(String.fromCodePoint, 'length');
verifyConfigurable(String.fromCodePoint, 'length');
// 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.2.2
description: >
String.fromCodePoint.name
info: >
String.fromCodePoint ( ...codePoints )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
String.fromCodePoint.name, 'fromCodePoint',
'The value of `String.fromCodePoint.name` is "fromCodePoint"'
);
verifyNotEnumerable(String.fromCodePoint, 'name');
verifyNotWritable(String.fromCodePoint, 'name');
verifyConfigurable(String.fromCodePoint, 'name');
// 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.2.2
description: >
Throw a RangeError if an argument is < 0 or > 0x10FFFF.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
d. If SameValue(nextCP, ToInteger(nextCP)) is false, throw a RangeError
exception.
e. If nextCP < 0 or nextCP > 0x10FFFF, throw a RangeError exception.
...
---*/
assert.throws(RangeError, function() {
String.fromCodePoint(-1);
});
assert.throws(RangeError, function() {
String.fromCodePoint(1, -1);
});
assert.throws(RangeError, function() {
String.fromCodePoint(1114112);
});
assert.throws(RangeError, function() {
String.fromCodePoint(Infinity);
});
// 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.2.2
description: >
Returns the String value whose elements are, in order, the code unit for the
numbers in the arguments list.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
...
5. Repeat while nextIndex < length
...
f. Append the elements of the UTF16Encoding (10.1.1) of nextCP to the end of
elements.
g. Let nextIndex be nextIndex + 1.
6. Return the String value whose elements are, in order, the elements in the
List elements. If length is 0, the empty string is returned.
---*/
assert.sameValue(String.fromCodePoint(0), '\x00');
assert.sameValue(String.fromCodePoint(42), '*');
assert.sameValue(String.fromCodePoint(65, 90), 'AZ');
assert.sameValue(String.fromCodePoint(0x404), '\u0404');
assert.sameValue(String.fromCodePoint(0x2F804), '\uD87E\uDC04');
assert.sameValue(String.fromCodePoint(194564), '\uD87E\uDC04');
assert.sameValue(
String.fromCodePoint(0x1D306, 0x61, 0x1D307),
'\uD834\uDF06a\uD834\uDF07'
);
assert.sameValue(String.fromCodePoint(1114111), '\uDBFF\uDFFF');
// 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.2.2
description: >
Returns the String value with the code unit for the given coerced types.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
...
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
...
6. Return the String value whose elements are, in order, the elements in the
List elements. If length is 0, the empty string is returned.
Ref: 7.1.3 ToNumber ( argument )
---*/
assert.sameValue(String.fromCodePoint(null), '\x00');
assert.sameValue(String.fromCodePoint(false), '\x00');
assert.sameValue(String.fromCodePoint(true), '\x01');
assert.sameValue(String.fromCodePoint('42'), '\x2A');
assert.sameValue(String.fromCodePoint('042'), '\x2A');
assert.sameValue(
String.fromCodePoint({ valueOf: function() { return 31; } }),
'\x1F'
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment