Skip to content

Commit

Permalink
Merge pull request #9 from QSPFoundation/tests/ExtraTestsToCheckParam…
Browse files Browse the repository at this point in the history
…eterConversion

Add extra tests to check type conversion
  • Loading branch information
srg-kostyrko authored Nov 27, 2024
2 parents bb18bf2 + 82f26fb commit f455184
Show file tree
Hide file tree
Showing 7 changed files with 2,772 additions and 4,258 deletions.
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();
});
});

0 comments on commit f455184

Please sign in to comment.