diff options
| author | Priyansh <[email protected]> | 2020-12-22 17:50:12 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2020-12-22 17:50:12 +0530 |
| commit | 22dc033f4938d6a19e086a1cbd36ec5cade5eaab (patch) | |
| tree | 9feb963ccd5c1581e676e41004801abc67db3357 /node_modules/truncate-utf8-bytes/test.js | |
| parent | e93da8b04da86773247aadb1cbb1912e4f4526b2 (diff) | |
| download | styx-22dc033f4938d6a19e086a1cbd36ec5cade5eaab.tar.xz styx-22dc033f4938d6a19e086a1cbd36ec5cade5eaab.zip | |
Remove node_modules
Diffstat (limited to 'node_modules/truncate-utf8-bytes/test.js')
| -rw-r--r-- | node_modules/truncate-utf8-bytes/test.js | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/node_modules/truncate-utf8-bytes/test.js b/node_modules/truncate-utf8-bytes/test.js deleted file mode 100644 index bde24f4..0000000 --- a/node_modules/truncate-utf8-bytes/test.js +++ /dev/null @@ -1,75 +0,0 @@ -"use strict"; - -var test = require("tape"); -var truncate = require("./"); -var browserTruncate = require("./browser"); - -function isHighSurrogate(codePoint) { - return codePoint >= 0xd800 && codePoint <= 0xdbff; -} - -function repeat(string, times) { - return new Array(times + 1).join(string); -} - -function assertLengths(t, string, charLength, byteLength) { - t.equal(string.length, charLength); - t.equal(Buffer.byteLength(string), byteLength); -} - -// Test writing files to the fs -// - -try { - var blns = require("./vendor/big-list-of-naughty-strings/blns.json"); -} -catch (err) { - console.error("Error: Cannot load file './vendor/big-list-of-naughty-strings/blns.json'"); - console.error(); - console.error("Make sure you've initialized git submodules by running"); - console.error(); - console.error(" git submodule update --init"); - console.error(); - process.exit(1); -} - -// Run tests against both implementations -[truncate, browserTruncate].forEach(function(truncate) { - test("strings", function(t) { - assertLengths(t, truncate("a☃", 2), 1, 1); - assertLengths(t, truncate(repeat("a", 250) + '\uD800\uDC00', 255), 252, 254); - assertLengths(t, truncate(repeat("a", 251) + '\uD800\uDC00', 255), 253, 255); - assertLengths(t, truncate(repeat("a", 252) + '\uD800\uDC00', 255), 252, 252); - assertLengths(t, truncate(repeat("a", 253) + '\uD800\uDC00', 255), 253, 253); - assertLengths(t, truncate(repeat("a", 254) + '\uD800\uDC00', 255), 254, 254); - assertLengths(t, truncate(repeat("a", 255) + '\uD800\uDC00', 255), 255, 255); - t.end(); - }); - - // Truncate various strings - [].concat( - [ - repeat("a", 300), - repeat("a", 252) + '\uD800\uDC00', - repeat("a", 251) + '\uD800\uDC00', - repeat("a", 253) + '\uD800\uDC00', - ], - blns - ).forEach(function(str) { - test(JSON.stringify(str), function(t) { - var i = 0; - t.equals(truncate(str, 0), ""); - // Truncate string one byte at a time - while (true) { - var truncated = truncate(str, i); - t.ok(Buffer.byteLength(truncated) <= i); - t.ok( ! isHighSurrogate(truncated[truncated.length - 1])); - if (truncated === str) { - break; - } - i += 1; - } - t.end(); - }); - }); -}); |
