feat(test): Added mutation testing for scalar values.
This is a port of the tests found in test.cpp
This commit is contained in:
parent
a351124cfd
commit
d268d11ca2
|
@ -64,7 +64,10 @@ function main() {
|
||||||
|
|
||||||
fs.writeFileSync('monsterdata_javascript_wire.mon', new Buffer(fbb.asUint8Array()));
|
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());
|
testBuffer(fbb.dataBuffer());
|
||||||
|
|
||||||
test64bit();
|
test64bit();
|
||||||
|
@ -74,6 +77,21 @@ function main() {
|
||||||
console.log('FlatBuffers test: completed successfully');
|
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) {
|
function testBuffer(bb) {
|
||||||
assert.ok(MyGame.Example.Monster.bufferHasIdentifier(bb));
|
assert.ok(MyGame.Example.Monster.bufferHasIdentifier(bb));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue