]> git.r.bdr.sh - rbdr/dotfiles/blob
88cda3d636471958a612d39541029fff303fd0b5
[rbdr/dotfiles] /
1 // Taken from: https://github.com/mathiasbynens/String.fromCodePoint/blob/master
2 // /tests/tests.js
3
4 'use strict';
5
6 var pow = Math.pow;
7
8 module.exports = function (t, a) {
9 var counter, result;
10
11 a(t.length, 1, "Length");
12 a(String.propertyIsEnumerable('fromCodePoint'), false, "Not enumerable");
13
14 a(t(''), '\0', "Empty string");
15 a(t(), '', "No arguments");
16 a(t(-0), '\0', "-0");
17 a(t(0), '\0', "0");
18 a(t(0x1D306), '\uD834\uDF06', "Unicode");
19 a(t(0x1D306, 0x61, 0x1D307), '\uD834\uDF06a\uD834\uDF07', "Complex unicode");
20 a(t(0x61, 0x62, 0x1D307), 'ab\uD834\uDF07', "Complex");
21 a(t(false), '\0', "false");
22 a(t(null), '\0', "null");
23
24 a.throws(function () { t('_'); }, RangeError, "_");
25 a.throws(function () { t(Infinity); }, RangeError, "Infinity");
26 a.throws(function () { t(-Infinity); }, RangeError, "-Infinity");
27 a.throws(function () { t(-1); }, RangeError, "-1");
28 a.throws(function () { t(0x10FFFF + 1); }, RangeError, "Range error #1");
29 a.throws(function () { t(3.14); }, RangeError, "Range error #2");
30 a.throws(function () { t(3e-2); }, RangeError, "Range error #3");
31 a.throws(function () { t(-Infinity); }, RangeError, "Range error #4");
32 a.throws(function () { t(+Infinity); }, RangeError, "Range error #5");
33 a.throws(function () { t(NaN); }, RangeError, "Range error #6");
34 a.throws(function () { t(undefined); }, RangeError, "Range error #7");
35 a.throws(function () { t({}); }, RangeError, "Range error #8");
36 a.throws(function () { t(/re/); }, RangeError, "Range error #9");
37
38 counter = pow(2, 15) * 3 / 2;
39 result = [];
40 while (--counter >= 0) result.push(0); // one code unit per symbol
41 t.apply(null, result); // must not throw
42
43 counter = pow(2, 15) * 3 / 2;
44 result = [];
45 while (--counter >= 0) result.push(0xFFFF + 1); // two code units per symbol
46 t.apply(null, result); // must not throw
47 };