From 2f5d7ae64580c016f66a4c442b3bafb6e31a926d Mon Sep 17 00:00:00 2001 From: Robert Nix Date: Fri, 12 Feb 2016 12:12:54 -0600 Subject: [PATCH] Fix javascript unicode test The generated buffer should be tested for semantic equivalence to the correct buffer, instead of being tested for bytewise equality. --- tests/JavaScriptTest.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/JavaScriptTest.js b/tests/JavaScriptTest.js index 8eb50f3c5..0f4f23351 100644 --- a/tests/JavaScriptTest.js +++ b/tests/JavaScriptTest.js @@ -122,21 +122,23 @@ function testUnicode() { var json = JSON.parse(fs.readFileSync('unicode_test.json', 'utf8')); // Test reading - var bb = new flatbuffers.ByteBuffer(new Uint8Array(correct)); - var monster = MyGame.Example.Monster.getRootAsMonster(bb); - assert.strictEqual(monster.name(), json.name); - assert.deepEqual(new Buffer(monster.name(flatbuffers.Encoding.UTF8_BYTES)), new Buffer(json.name)); - assert.strictEqual(monster.testarrayoftablesLength(), json.testarrayoftables.length); - json.testarrayoftables.forEach(function(table, i) { - var value = monster.testarrayoftables(i); - assert.strictEqual(value.name(), table.name); - assert.deepEqual(new Buffer(value.name(flatbuffers.Encoding.UTF8_BYTES)), new Buffer(table.name)); - }); - assert.strictEqual(monster.testarrayofstringLength(), json.testarrayofstring.length); - json.testarrayofstring.forEach(function(string, i) { - assert.strictEqual(monster.testarrayofstring(i), string); - assert.deepEqual(new Buffer(monster.testarrayofstring(i, flatbuffers.Encoding.UTF8_BYTES)), new Buffer(string)); - }); + function testReadingUnicode(bb) { + var monster = MyGame.Example.Monster.getRootAsMonster(bb); + assert.strictEqual(monster.name(), json.name); + assert.deepEqual(new Buffer(monster.name(flatbuffers.Encoding.UTF8_BYTES)), new Buffer(json.name)); + assert.strictEqual(monster.testarrayoftablesLength(), json.testarrayoftables.length); + json.testarrayoftables.forEach(function(table, i) { + var value = monster.testarrayoftables(i); + assert.strictEqual(value.name(), table.name); + assert.deepEqual(new Buffer(value.name(flatbuffers.Encoding.UTF8_BYTES)), new Buffer(table.name)); + }); + assert.strictEqual(monster.testarrayofstringLength(), json.testarrayofstring.length); + json.testarrayofstring.forEach(function(string, i) { + assert.strictEqual(monster.testarrayofstring(i), string); + assert.deepEqual(new Buffer(monster.testarrayofstring(i, flatbuffers.Encoding.UTF8_BYTES)), new Buffer(string)); + }); + } + testReadingUnicode(new flatbuffers.ByteBuffer(new Uint8Array(correct))); // Test writing var fbb = new flatbuffers.Builder(); @@ -156,7 +158,7 @@ function testUnicode() { MyGame.Example.Monster.addTestarrayoftables(fbb, testarrayoftablesOffset); MyGame.Example.Monster.addName(fbb, name); MyGame.Example.Monster.finishMonsterBuffer(fbb, MyGame.Example.Monster.endMonster(fbb)); - assert.deepEqual(new Buffer(fbb.asUint8Array()), correct); + testReadingUnicode(new flatbuffers.ByteBuffer(fbb.asUint8Array())); } var __imul = Math.imul ? Math.imul : function(a, b) {