-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remaining tests; 100% coverage again
- Loading branch information
1 parent
e30036d
commit 964e170
Showing
9 changed files
with
407 additions
and
20 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
compiler/src/js2eel/generatorNodes/callExpression/js2EelLib/onBlock.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { expect } from 'chai'; | ||
import { Js2EelCompiler } from '../../../compiler/Js2EelCompiler.js'; | ||
|
||
describe('onBlock()', () => { | ||
it('Error if called elsewhere than root scope', () => { | ||
const compiler = new Js2EelCompiler(); | ||
|
||
const result = | ||
compiler.compile(`config({ description: 'onBlock', inChannels: 2, outChannels: 2 }); | ||
onSample(function callback() { | ||
onBlock(() => {}); | ||
}); | ||
`); | ||
expect(result.success).to.equal(false); | ||
expect(result.errors.length).to.equal(1); | ||
expect(result.errors[0].type).to.equal('ScopeError'); | ||
}); | ||
|
||
it('can only be called once', () => { | ||
const compiler = new Js2EelCompiler(); | ||
|
||
const result = | ||
compiler.compile(`config({ description: 'onBlock', inChannels: 2, outChannels: 2 }); | ||
onBlock(() => {}); | ||
onBlock(() => {}); | ||
`); | ||
expect(result.success).to.equal(false); | ||
expect(result.errors.length).to.equal(1); | ||
expect(result.errors[0].type).to.equal('StageError'); | ||
}); | ||
|
||
it('Error if no callback given', () => { | ||
const compiler = new Js2EelCompiler(); | ||
|
||
const result = | ||
compiler.compile(`config({ description: 'onBlock', inChannels: 2, outChannels: 2 }); | ||
onBlock(); | ||
`); | ||
expect(result.success).to.equal(false); | ||
expect(result.errors.length).to.equal(2); | ||
expect(result.errors[0].type).to.equal('ArgumentError'); | ||
expect(result.errors[1].type).to.equal('ArgumentError'); | ||
}); | ||
|
||
it('Error if callback has args', () => { | ||
const compiler = new Js2EelCompiler(); | ||
|
||
const result = | ||
compiler.compile(`config({ description: 'onBlock', inChannels: 2, outChannels: 2 }); | ||
onBlock((sample) => {}); | ||
`); | ||
expect(result.success).to.equal(false); | ||
expect(result.errors.length).to.equal(1); | ||
expect(result.errors[0].type).to.equal('ParameterError'); | ||
}); | ||
|
||
it('Error if callback body is not a block statement', () => { | ||
const compiler = new Js2EelCompiler(); | ||
|
||
const result = | ||
compiler.compile(`config({ description: 'onBlock', inChannels: 2, outChannels: 2 }); | ||
onBlock(() => "nope"); | ||
`); | ||
expect(result.success).to.equal(false); | ||
expect(result.errors.length).to.equal(1); | ||
expect(result.errors[0].type).to.equal('TypeError'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
compiler/src/js2eel/generatorNodes/updateExpression/updateExpression.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { expect } from 'chai'; | ||
import { Js2EelCompiler } from '../../compiler/Js2EelCompiler.js'; | ||
import { testEelSrc } from '../../test/helpers.js'; | ||
|
||
describe('updateExpression()', () => { | ||
it('decrements', () => { | ||
const compiler = new Js2EelCompiler(); | ||
const result = | ||
compiler.compile(`config({ description: 'update expression', inChannels: 2, outChannels: 2 }); | ||
let number = 1; | ||
onBlock(() => { | ||
number--; | ||
}); | ||
`); | ||
|
||
expect(result.success).to.equal(true); | ||
expect(result.errors.length).to.equal(0); | ||
expect(testEelSrc(result.src)).to.equal( | ||
testEelSrc(`/* Compiled with JS2EEL vTO_BE_REPLACED_COMPILER_VERSION */ | ||
desc:update expression | ||
in_pin:In 0 | ||
in_pin:In 1 | ||
out_pin:Out 0 | ||
out_pin:Out 1 | ||
@init | ||
number = 1; | ||
@block | ||
number -= 1; | ||
`) | ||
); | ||
}); | ||
|
||
it('does not work with wrong type', () => { | ||
const compiler = new Js2EelCompiler(); | ||
const result = | ||
compiler.compile(`config({ description: 'update expression', inChannels: 2, outChannels: 2 }); | ||
onBlock(() => { | ||
console.log++; | ||
}); | ||
`); | ||
|
||
expect(result.success).to.equal(false); | ||
expect(result.errors.length).to.equal(1); | ||
expect(result.errors[0].type).to.equal('TypeError'); | ||
expect(testEelSrc(result.src)).to.equal( | ||
testEelSrc(`/* Compiled with JS2EEL vTO_BE_REPLACED_COMPILER_VERSION */ | ||
desc:update expression | ||
in_pin:In 0 | ||
in_pin:In 1 | ||
out_pin:Out 0 | ||
out_pin:Out 1 | ||
@block | ||
?ä__DENY_COMPILATION; | ||
`) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.