Skip to content

Commit

Permalink
Test global var if calls GOTO
Browse files Browse the repository at this point in the history
  • Loading branch information
Varg committed Sep 28, 2024
1 parent 2b93122 commit b5a589f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Binary file modified src/qsplib/public/qsp-engine-debug.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion src/qsplib/public/qsp-engine-debug.wasm.map

Large diffs are not rendered by default.

Binary file modified src/qsplib/public/qsp-engine.wasm
Binary file not shown.
38 changes: 38 additions & 0 deletions tests/variables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,44 @@ $glob_test = $test
expect(api.readVariable('$glob_test')).toBe("value");
});

test('global variables get restored if $ONGSAVE calls goto', () => {
const onSaveGame = vi.fn((_, callback) => { api.saveGame(); callback(); });
api.on('save_game', onSaveGame);

runTestFile(api,
`
$ongsave = 'other'
$test='value'
local $test='value 1'
if 1:
local $test='value 2'
$last_loc_test1 = $test
savegame 'test.sav'
$last_loc_test2 = $test
end
---
# other
$glob_test1 = $test
gt 'new'
---
# new
$glob_test2 = $test
act 'test value':
$glob_test3 = $test
end
`);

api.selectAction(0);
api.execSelectedAction();

expect(api.readVariable('$last_loc_test1')).toBe("value 2");
expect(onSaveGame).toHaveBeenCalledWith('test.sav', expect.any(Function));
expect(api.readVariable('$last_loc_test2')).toBe("");
expect(api.readVariable('$glob_test1')).toBe("value");
expect(api.readVariable('$glob_test2')).toBe("value");
expect(api.readVariable('$glob_test3')).toBe("value");
});

test('local variables in nested calls are preserved (shadowing global)', () => {
runTestFile(
api,
Expand Down

0 comments on commit b5a589f

Please sign in to comment.