diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2016-02-26 09:51:50 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2016-02-26 09:51:50 -0800 |
commit | 617fedf3491ca6029e4c5b7278869e92235b0af1 (patch) | |
tree | 0b84f7ec8b434cd4e2d4ad68e887b6b57f4a8229 /tests/JavaScriptTest.js | |
parent | 59caa536ede8490a1df00a867c4550b216278bd7 (diff) | |
parent | 9d92aeb182527989cd943fd1998d8669eea7d70d (diff) | |
download | flatbuffers-617fedf3491ca6029e4c5b7278869e92235b0af1.tar.gz flatbuffers-617fedf3491ca6029e4c5b7278869e92235b0af1.tar.bz2 flatbuffers-617fedf3491ca6029e4c5b7278869e92235b0af1.zip |
Merge pull request #3765 from Mischanix/js-typed-arrays
Javascript helper to get typed array views
Diffstat (limited to 'tests/JavaScriptTest.js')
-rw-r--r-- | tests/JavaScriptTest.js | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/tests/JavaScriptTest.js b/tests/JavaScriptTest.js index 3ed8b515..c89ae85d 100644 --- a/tests/JavaScriptTest.js +++ b/tests/JavaScriptTest.js @@ -106,6 +106,13 @@ function testBuffer(bb) { } assert.strictEqual(invsum, 10); + var invsum2 = 0; + var invArr = monster.inventoryArray(); + for (var i = 0; i < invArr.length; i++) { + invsum2 += invArr[i]; + } + assert.strictEqual(invsum2, 10); + var test_0 = monster.test4(0); var test_1 = monster.test4(1); assert.strictEqual(monster.test4Length(), 2); @@ -169,21 +176,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(); @@ -203,7 +212,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) { |