Skip to content

Commit

Permalink
Adding more tests and expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Dec 13, 2024
1 parent 7fa1dd6 commit bfb2b74
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions test/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ describe('Wollok Interpreter', () => {
)
})

it('Can\'t redefine a variable', () => {
it('Can\'t redefine a const with a var', () => {
const replEnvironment = buildEnvironment([{
name: REPL, content: `
const variableName = 1
Expand All @@ -521,23 +521,65 @@ describe('Wollok Interpreter', () => {

]
)
const { result } = interprete(interpreter, 'variableName')
expect(+result).to.equal(1)
})

it('Can\'t redefine a variable', () => {
it('Can\'t redefine a const with a const', () => {
const replEnvironment = buildEnvironment([{
name: REPL, content: `
var variableName = 2
const variableName = 1
`,
}])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error } = interprete(interpreter, 'const variableName = 2')
assertBasicError(error)
expect(getStackTraceSanitized(error)).to.deep.equal(
[
'wollok.lang.EvaluationError: Error: Can\'t redefine a variable',

]
)
const { result } = interprete(interpreter, 'variableName')
expect(+result).to.equal(1)
})

it('Can\'t redefine a var with a const', () => {
const replEnvironment = buildEnvironment([{
name: REPL, content: `
var variableName = 1
`,
}])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error } = interprete(interpreter, 'const variableName = 1')
const { error } = interprete(interpreter, 'const variableName = 2')
assertBasicError(error)
expect(getStackTraceSanitized(error)).to.deep.equal(
[
'wollok.lang.EvaluationError: Error: Can\'t redefine a variable',

]
)
const { result } = interprete(interpreter, 'variableName')
expect(+result).to.equal(1)
})

it('Can\'t redefine a var with a var', () => {
const replEnvironment = buildEnvironment([{
name: REPL, content: `
var variableName = 1
`,
}])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error } = interprete(interpreter, 'var variableName = 2')
assertBasicError(error)
expect(getStackTraceSanitized(error)).to.deep.equal(
[
'wollok.lang.EvaluationError: Error: Can\'t redefine a variable',

]
)
const { result } = interprete(interpreter, 'variableName')
expect(+result).to.equal(1)
})

it('should wrap void validation errors for assignment to void value', () => {
Expand Down

0 comments on commit bfb2b74

Please sign in to comment.