diff options
| author | Priyansh <[email protected]> | 2020-12-22 17:49:59 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2020-12-22 17:49:59 +0530 |
| commit | e93da8b04da86773247aadb1cbb1912e4f4526b2 (patch) | |
| tree | eb4ef3203a92ed3dbd2252ddb1ea23bd2d670c98 /node_modules/utf8-byte-length/test.js | |
| parent | a5743c293dcb435e4b159a4df791f8955a4110ec (diff) | |
| download | styx-e93da8b04da86773247aadb1cbb1912e4f4526b2.tar.xz styx-e93da8b04da86773247aadb1cbb1912e4f4526b2.zip | |
Rewriting Project
Diffstat (limited to 'node_modules/utf8-byte-length/test.js')
| -rw-r--r-- | node_modules/utf8-byte-length/test.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/node_modules/utf8-byte-length/test.js b/node_modules/utf8-byte-length/test.js new file mode 100644 index 0000000..4f3cdbc --- /dev/null +++ b/node_modules/utf8-byte-length/test.js @@ -0,0 +1,67 @@ +"use strict"; + +var test = require("tape"); +var getLength = require("./index"); +var browserGetLength = require("./browser"); + +function repeat(string, times) { + return new Array(times + 1).join(string); +} + +// 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); +} + + +// 8-byte, 4-character string +var THUMB = "👍🏽"; + +// Tests run against both implementations +[getLength, browserGetLength].forEach(function(getLength) { + // Strings with known lengths + [ + ["", 0], + ["a", 1], + ["☃", 3], + ["a☃", 4], + [repeat("a", 250) + '\uD800\uDC00', 254], + [repeat("a", 251) + '\uD800\uDC00', 255], + [repeat("a", 252) + '\uD800\uDC00', 256], + [THUMB, 8], + [THUMB[0], 3], + [THUMB[1], 3], + [THUMB[2], 3], + [THUMB[3], 3], + [THUMB.slice(0, 2), 4], + [THUMB.slice(2, 4), 4], + [THUMB.slice(1, 3), 6], + ].forEach(function(desc) { + var string = desc[0]; + var length = desc[1]; + test(JSON.stringify(string) + "=" + length, function(t) { + t.equal(getLength(string), length); + t.end(); + }); + }); + + // Make sure result matches Buffer.byteLength for various strings + blns.forEach(function(str) { + test(JSON.stringify(str), function(t) { + t.equal(getLength(str), Buffer.byteLength(str)); + t.end(); + }); + }); +}); + |
