Commit d268d11c authored by Michael Paulson's avatar Michael Paulson

feat(test): Added mutation testing for scalar values.

This is a port of the tests found in test.cpp
parent a351124c
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment