Home | History | Annotate | Download | only in es6
      1 // Copyright 2014 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Tests taken from:
      6 // https://github.com/mathiasbynens/String.fromCodePoint
      7 
      8 assertEquals(String.fromCodePoint.length, 1);
      9 assertEquals(String.propertyIsEnumerable("fromCodePoint"), false);
     10 
     11 assertEquals(String.fromCodePoint(""), "\0");
     12 assertEquals(String.fromCodePoint(), "");
     13 assertEquals(String.fromCodePoint(-0), "\0");
     14 assertEquals(String.fromCodePoint(0), "\0");
     15 assertEquals(String.fromCodePoint(0x1D306), "\uD834\uDF06");
     16 assertEquals(
     17     String.fromCodePoint(0x1D306, 0x61, 0x1D307),
     18     "\uD834\uDF06a\uD834\uDF07");
     19 assertEquals(String.fromCodePoint(0x61, 0x62, 0x1D307), "ab\uD834\uDF07");
     20 assertEquals(String.fromCodePoint(false), "\0");
     21 assertEquals(String.fromCodePoint(null), "\0");
     22 
     23 assertThrows(function() { String.fromCodePoint("_"); }, RangeError);
     24 assertThrows(function() { String.fromCodePoint("+Infinity"); }, RangeError);
     25 assertThrows(function() { String.fromCodePoint("-Infinity"); }, RangeError);
     26 assertThrows(function() { String.fromCodePoint(-1); }, RangeError);
     27 assertThrows(function() { String.fromCodePoint(0x10FFFF + 1); }, RangeError);
     28 assertThrows(function() { String.fromCodePoint(3.14); }, RangeError);
     29 assertThrows(function() { String.fromCodePoint(3e-2); }, RangeError);
     30 assertThrows(function() { String.fromCodePoint(-Infinity); }, RangeError);
     31 assertThrows(function() { String.fromCodePoint(+Infinity); }, RangeError);
     32 assertThrows(function() { String.fromCodePoint(NaN); }, RangeError);
     33 assertThrows(function() { String.fromCodePoint(undefined); }, RangeError);
     34 assertThrows(function() { String.fromCodePoint({}); }, RangeError);
     35 assertThrows(function() { String.fromCodePoint(/./); }, RangeError);
     36 assertThrows(function() { String.fromCodePoint({
     37   valueOf: function() { throw Error(); } });
     38 }, Error);
     39 assertThrows(function() { String.fromCodePoint({
     40   valueOf: function() { throw Error(); } });
     41 }, Error);
     42 var tmp = 0x60;
     43 assertEquals(String.fromCodePoint({
     44   valueOf: function() { ++tmp; return tmp; }
     45 }), "a");
     46 assertEquals(tmp, 0x61);
     47 
     48 var counter = Math.pow(2, 15) * 3 / 2;
     49 var result = [];
     50 while (--counter >= 0) {
     51   result.push(0); // one code unit per symbol
     52 }
     53 String.fromCodePoint.apply(null, result); // must not throw
     54 
     55 var counter = Math.pow(2, 15) * 3 / 2;
     56 var result = [];
     57 while (--counter >= 0) {
     58   result.push(0xFFFF + 1); // two code units per symbol
     59 }
     60 String.fromCodePoint.apply(null, result); // must not throw
     61