diff options
author | daurnimator <quae@daurnimator.com> | 2017-11-12 14:29:42 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-11-12 14:29:50 +1100 |
commit | ed7815d9a5da88e7c83a0596fb75249c3ce165ab (patch) | |
tree | b787a8ec918d7f27e9b70a641f39b3d76d5e3efa /tests/defs.js | |
parent | 3033341b741cfb256baf91acf1f257a7f1ed6f7b (diff) | |
download | fengari-ed7815d9a5da88e7c83a0596fb75249c3ce165ab.tar.gz fengari-ed7815d9a5da88e7c83a0596fb75249c3ce165ab.tar.bz2 fengari-ed7815d9a5da88e7c83a0596fb75249c3ce165ab.zip |
src/defs.js: Fix conversion of non-BMP unicode codepoints
Adds tests for to_luastring
Diffstat (limited to 'tests/defs.js')
-rw-r--r-- | tests/defs.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/defs.js b/tests/defs.js new file mode 100644 index 0000000..8c86588 --- /dev/null +++ b/tests/defs.js @@ -0,0 +1,50 @@ +const test = require('tape'); + +global.WEB = false; +const defs = require('../src/defs.js'); + +test('to_luastring', function (t) { + t.deepEqual( + defs.to_luastring("foo"), + ["f".charCodeAt(0), "o".charCodeAt(0), "o".charCodeAt(0)], + "Convert normal ascii string" + ); + + t.deepEqual( + defs.to_luastring("fo\0o"), + ["f".charCodeAt(0), "o".charCodeAt(0), 0, "o".charCodeAt(0)], + "Convert ascii string containing null byte" + ); + + t.deepEqual( + defs.to_luastring("Café"), + [67, 97, 102, 195, 169], + "Convert string with BMP unicode chars" + ); + + t.deepEqual( + defs.to_luastring(""), + [239, 163, 191], + "Convert string with codepoint in PUA (U+E000 to U+F8FF)" + ); + + t.deepEqual( + defs.to_luastring("❤️🍾"), + [226, 157, 164, 239, 184, 143, 240, 159, 141, 190], + "Convert string with surrogate pair" + ); + + t.deepEqual( + defs.to_luastring("\uD800a"), + [237, 160, 128, 97], + "Convert string with broken surrogate pair" + ); + + t.deepEqual( + defs.to_luastring("\uD823"), + [237, 160, 163], + "Convert string with broken surrogate pair at end of string" + ); + + t.end(); +}); |