From d268d11ca29b95ce1b8186e6526b58b51f2c913a Mon Sep 17 00:00:00 2001 From: Michael Paulson Date: Wed, 27 Jul 2016 13:32:53 -0700 Subject: [PATCH] feat(test): Added mutation testing for scalar values. This is a port of the tests found in test.cpp --- tests/JavaScriptTest.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/JavaScriptTest.js b/tests/JavaScriptTest.js index c89ae85d7..c97ed2d08 100644 --- a/tests/JavaScriptTest.js +++ b/tests/JavaScriptTest.js @@ -64,7 +64,10 @@ function main() { fs.writeFileSync('monsterdata_javascript_wire.mon', new Buffer(fbb.asUint8Array())); - // Test it: + // Tests mutation first. This will verify that we did not trample any other + // part of the byte buffer. + testMutation(fbb.dataBuffer()); + testBuffer(fbb.dataBuffer()); test64bit(); @@ -74,6 +77,21 @@ function main() { console.log('FlatBuffers test: completed successfully'); } +function testMutation(bb) { + var monster = MyGame.Example.Monster.getRootAsMonster(bb); + + monster.mutate_hp(120); + assert.strictEqual(monster.hp(), 120); + + monster.mutate_hp(80); + assert.strictEqual(monster.hp(), 80); + + var manaRes = monster.mutate_mana(10); + assert.strictEqual(manaRes, false); // Field was NOT present, because default value. + + // TODO: There is not the availability to mutate structs or vectors. +} + function testBuffer(bb) { assert.ok(MyGame.Example.Monster.bufferHasIdentifier(bb));