-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest.js
More file actions
94 lines (81 loc) · 2.55 KB
/
test.js
File metadata and controls
94 lines (81 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
// Testing api calls for string
const test_string = loadAddon("test_string");
// The insufficient buffer test case allocates a buffer of size 4, including
// the null terminator.
const kInsufficientIdx = 3;
const asciiCases = [
"",
"hello world",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"?!@#$%^&*()_+-=[]{}/.,<>'\"\\",
];
const latin1Cases = [
{
str: "¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿",
utf8Length: 62,
utf8InsufficientIdx: 1,
},
{
str: "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ",
utf8Length: 126,
utf8InsufficientIdx: 1,
},
];
const unicodeCases = [
{
str: "\u{2003}\u{2101}\u{2001}\u{202}\u{2011}",
utf8Length: 14,
utf8InsufficientIdx: 1,
},
];
function testLatin1Cases(str) {
assert.strictEqual(test_string.TestLatin1(str), str);
assert.strictEqual(test_string.TestLatin1AutoLength(str), str);
assert.strictEqual(test_string.Latin1Length(str), str.length);
if (str !== "") {
assert.strictEqual(
test_string.TestLatin1Insufficient(str),
str.slice(0, kInsufficientIdx),
);
}
}
function testUnicodeCases(str, utf8Length, utf8InsufficientIdx) {
assert.strictEqual(test_string.TestUtf8(str), str);
assert.strictEqual(test_string.TestUtf16(str), str);
assert.strictEqual(test_string.TestUtf8AutoLength(str), str);
assert.strictEqual(test_string.TestUtf16AutoLength(str), str);
assert.strictEqual(test_string.Utf8Length(str), utf8Length);
assert.strictEqual(test_string.Utf16Length(str), str.length);
if (str !== "") {
assert.strictEqual(
test_string.TestUtf8Insufficient(str),
str.slice(0, utf8InsufficientIdx),
);
assert.strictEqual(
test_string.TestUtf16Insufficient(str),
str.slice(0, kInsufficientIdx),
);
}
}
asciiCases.forEach(testLatin1Cases);
asciiCases.forEach((str) =>
testUnicodeCases(str, str.length, kInsufficientIdx),
);
latin1Cases.forEach((it) => testLatin1Cases(it.str));
latin1Cases.forEach((it) =>
testUnicodeCases(it.str, it.utf8Length, it.utf8InsufficientIdx),
);
unicodeCases.forEach((it) =>
testUnicodeCases(it.str, it.utf8Length, it.utf8InsufficientIdx),
);
assert.throws(() => {
test_string.TestLargeUtf8();
}, /^Error: Invalid argument$/);
assert.throws(() => {
test_string.TestLargeLatin1();
}, /^Error: Invalid argument$/);
assert.throws(() => {
test_string.TestLargeUtf16();
}, /^Error: Invalid argument$/);
test_string.TestMemoryCorruption(" ".repeat(64 * 1024));