summaryrefslogtreecommitdiff
path: root/tests/defs.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-11-12 14:41:25 +1100
committerdaurnimator <quae@daurnimator.com>2017-11-12 14:41:25 +1100
commitfd7bdaca33c7e62d76e8ef0dfe975e5ff20490cb (patch)
tree7d755b48bbed74d3ce8963ae30b470191b750808 /tests/defs.js
parent183bbe94cd55fec7c27431b7f4c1339a3186df3f (diff)
downloadfengari-fd7bdaca33c7e62d76e8ef0dfe975e5ff20490cb.tar.gz
fengari-fd7bdaca33c7e62d76e8ef0dfe975e5ff20490cb.tar.bz2
fengari-fd7bdaca33c7e62d76e8ef0dfe975e5ff20490cb.zip
tests/defs.js: Also test to_jsstring
Diffstat (limited to 'tests/defs.js')
-rw-r--r--tests/defs.js88
1 files changed, 48 insertions, 40 deletions
diff --git a/tests/defs.js b/tests/defs.js
index 8c86588..07e863b 100644
--- a/tests/defs.js
+++ b/tests/defs.js
@@ -3,48 +3,56 @@ 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"
- );
+const unicode_tests = [
+ {
+ description: "Convert normal ascii string",
+ literal: "foo",
+ byte_array: ["f".charCodeAt(0), "o".charCodeAt(0), "o".charCodeAt(0)]
+ },
+ {
+ description: "Convert ascii string containing null byte",
+ literal: "fo\0o",
+ byte_array: ["f".charCodeAt(0), "o".charCodeAt(0), 0, "o".charCodeAt(0)]
+ },
+ {
+ description: "Convert string with BMP unicode chars",
+ literal: "Café",
+ byte_array: [67, 97, 102, 195, 169]
+ },
+ {
+ description: "Convert string with codepoint in PUA (U+E000 to U+F8FF)",
+ literal: "",
+ byte_array: [239, 163, 191]
+ },
+ {
+ description: "Convert string with surrogate pair",
+ literal: "❤️🍾",
+ byte_array: [226, 157, 164, 239, 184, 143, 240, 159, 141, 190]
+ },
+ {
+ description: "Convert string with broken surrogate pair",
+ literal: "\uD800a",
+ byte_array: [237, 160, 128, 97]
+ },
+ {
+ description: "Convert string with broken surrogate pair at end of string",
+ literal: "\uD823",
+ byte_array: [237, 160, 163]
+ }
+];
- 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"
- );
+test('to_luastring', function (t) {
+ t.plan(unicode_tests.length);
- t.deepEqual(
- defs.to_luastring("\uD800a"),
- [237, 160, 128, 97],
- "Convert string with broken surrogate pair"
- );
+ unicode_tests.forEach(function(v) {
+ t.deepEqual(defs.to_luastring(v.literal), v.byte_array, v.description);
+ });
+});
- t.deepEqual(
- defs.to_luastring("\uD823"),
- [237, 160, 163],
- "Convert string with broken surrogate pair at end of string"
- );
+test('to_jsstring', function (t) {
+ t.plan(unicode_tests.length);
- t.end();
+ unicode_tests.forEach(function(v) {
+ t.deepEqual(defs.to_jsstring(v.byte_array), v.literal, v.description);
+ });
});