File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff 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+
7795function testBuffer ( bb ) {
7896 assert . ok ( MyGame . Example . Monster . bufferHasIdentifier ( bb ) ) ;
7997
You can’t perform that action at this time.
0 commit comments