Skip to content

Commit d268d11

Browse files
committed
feat(test): Added mutation testing for scalar values.
This is a port of the tests found in test.cpp
1 parent a351124 commit d268d11

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/JavaScriptTest.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ function main() {
6464

6565
fs.writeFileSync('monsterdata_javascript_wire.mon', new Buffer(fbb.asUint8Array()));
6666

67-
// Test it:
67+
// Tests mutation first. This will verify that we did not trample any other
68+
// part of the byte buffer.
69+
testMutation(fbb.dataBuffer());
70+
6871
testBuffer(fbb.dataBuffer());
6972

7073
test64bit();
@@ -74,6 +77,21 @@ function main() {
7477
console.log('FlatBuffers test: completed successfully');
7578
}
7679

80+
function testMutation(bb) {
81+
var monster = MyGame.Example.Monster.getRootAsMonster(bb);
82+
83+
monster.mutate_hp(120);
84+
assert.strictEqual(monster.hp(), 120);
85+
86+
monster.mutate_hp(80);
87+
assert.strictEqual(monster.hp(), 80);
88+
89+
var manaRes = monster.mutate_mana(10);
90+
assert.strictEqual(manaRes, false); // Field was NOT present, because default value.
91+
92+
// TODO: There is not the availability to mutate structs or vectors.
93+
}
94+
7795
function testBuffer(bb) {
7896
assert.ok(MyGame.Example.Monster.bufferHasIdentifier(bb));
7997

0 commit comments

Comments
 (0)