diff --git a/test/built-ins/String/fromCodePoint/argument-is-Symbol.js b/test/built-ins/String/fromCodePoint/argument-is-Symbol.js new file mode 100644 index 0000000000..7295a6e484 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/argument-is-Symbol.js @@ -0,0 +1,27 @@ +// 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()); +}); diff --git a/test/built-ins/String/fromCodePoint/argument-is-not-integer.js b/test/built-ins/String/fromCodePoint/argument-is-not-integer.js new file mode 100644 index 0000000000..e188d9ea90 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/argument-is-not-integer.js @@ -0,0 +1,46 @@ +// 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'); +}); diff --git a/test/built-ins/String/fromCodePoint/argument-not-coercible.js b/test/built-ins/String/fromCodePoint/argument-not-coercible.js new file mode 100644 index 0000000000..6eb5781ca7 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/argument-not-coercible.js @@ -0,0 +1,41 @@ +// 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(); + } + }); +}); diff --git a/test/built-ins/String/fromCodePoint/arguments-is-empty.js b/test/built-ins/String/fromCodePoint/arguments-is-empty.js new file mode 100644 index 0000000000..fd71ed4900 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/arguments-is-empty.js @@ -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.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(), ''); diff --git a/test/built-ins/String/fromCodePoint/fromCodePoint.js b/test/built-ins/String/fromCodePoint/fromCodePoint.js new file mode 100644 index 0000000000..aed882564b --- /dev/null +++ b/test/built-ins/String/fromCodePoint/fromCodePoint.js @@ -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.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'); diff --git a/test/built-ins/String/fromCodePoint/length.js b/test/built-ins/String/fromCodePoint/length.js new file mode 100644 index 0000000000..c2f8cc15eb --- /dev/null +++ b/test/built-ins/String/fromCodePoint/length.js @@ -0,0 +1,17 @@ +// 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'); diff --git a/test/built-ins/String/fromCodePoint/name.js b/test/built-ins/String/fromCodePoint/name.js new file mode 100644 index 0000000000..5a657ab34b --- /dev/null +++ b/test/built-ins/String/fromCodePoint/name.js @@ -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.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'); diff --git a/test/built-ins/String/fromCodePoint/number-is-out-of-range.js b/test/built-ins/String/fromCodePoint/number-is-out-of-range.js new file mode 100644 index 0000000000..56b1801e75 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/number-is-out-of-range.js @@ -0,0 +1,38 @@ +// 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); +}); diff --git a/test/built-ins/String/fromCodePoint/return-string-value.js b/test/built-ins/String/fromCodePoint/return-string-value.js new file mode 100644 index 0000000000..6d9d5f1d40 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/return-string-value.js @@ -0,0 +1,32 @@ +// 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'); diff --git a/test/built-ins/String/fromCodePoint/to-number-conversions.js b/test/built-ins/String/fromCodePoint/to-number-conversions.js new file mode 100644 index 0000000000..c63ed3add7 --- /dev/null +++ b/test/built-ins/String/fromCodePoint/to-number-conversions.js @@ -0,0 +1,30 @@ +// 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' +);