Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra tests to check type conversion #9

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,038 changes: 2,703 additions & 3,335 deletions src/qsplib/public/qsp-engine-debug.js

Large diffs are not rendered by default.

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.

928 changes: 9 additions & 919 deletions src/qsplib/public/qsp-engine.js

Large diffs are not rendered by default.

Binary file modified src/qsplib/public/qsp-engine.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('api', () => {
expect(api.readVariableByKey('test', 'тест')).toBe(254);
});

it('should read numeric variable in cyrilic', async () => {
it('should read numeric variable in cyrillic', async () => {
runTestFile(api, `тест = 254`);

expect(api.readVariable('тест')).toBe(254);
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('api', () => {
expect(api.readVariableByKey('$test', 'тест')).toBe('252');
});

it('should read string variable in cyrilic', async () => {
it('should read string variable in cyrillic', async () => {
runTestFile(api, `$тест = '254'`);

expect(api.readVariable('$тест')).toBe('254');
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('api', () => {
});

it('should read version', () => {
expect(api.version()).toEqual('5.9.0');
expect(api.version()).toEqual('5.9.1');
});

it('should watch variable by index', async () => {
Expand Down
56 changes: 56 additions & 0 deletions tests/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,60 @@ end

expect(api.readVariable('$type')).toBe('new');
});

test('statement argument gets converted to string', () => {
const onMsg: Mock = vi.fn();
api.on('msg', onMsg);

runTestFile(api, ` msg 567 ` );
expect(onMsg).toHaveBeenCalledWith('567', expect.any(Function));
onMsg.mock.calls[0][1]();
});

test('statement argument gets converted to number', () => {
const onWait: Mock = vi.fn();
api.on('wait', onWait);

runTestFile(api, ` wait '567' `);
expect(onWait).toHaveBeenCalledWith(567, expect.any(Function));
onWait.mock.calls[0][1]();
});

test('statement argument cant be converted to number', () => {
runTestFile(api, ` wait 'sdsd' `);
expect(error).toHaveBeenCalledWith({
errorCode: 11,
description: 'Type mismatch!',
location: 'test',
actionIndex: -1,
line: 1,
localLine: 1,
lineSrc: "WAIT 'sdsd'"
});
error.mockReset();
});

test('function argument gets converted to string', () => {
runTestFile(api, ` $x = replace(123456, 456, 34) `);
expect(api.readVariable('$x')).toBe('12334');
});

test('function argument gets converted to number', () => {
runTestFile(api, ` x = rgb('12', '234', 32) `);
expect(api.readVariable('x')).toBe(-14620148);
});

test('function argument cant be converted to number', () => {
runTestFile(api, ` x = rgb('123', '65sd', 56) `);
expect(error).toHaveBeenCalledWith({
errorCode: 11,
description: 'Type mismatch!',
location: 'test',
actionIndex: -1,
line: 1,
localLine: 1,
lineSrc: "X = RGB('123', '65sd', 56)"
});
error.mockReset();
});
});