Skip to content

Commit

Permalink
definition.wlk var
Browse files Browse the repository at this point in the history
  • Loading branch information
ivojawer committed Dec 30, 2024
1 parent 25b68dd commit 2697b7b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
18 changes: 9 additions & 9 deletions test/dynamicDiagram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BOOLEAN_MODULE, buildEnvironment, CLOSURE_MODULE, DATE_MODULE, DICTIONA
import { DynamicDiagramElement, DynamicDiagramNode, DynamicDiagramReference } from '../src/interpreter/dynamicDiagram'
import { interprete, Interpreter } from '../src/interpreter/interpreter'
import linker from '../src/linker'
import { environmentWithREPLInitializedFile, INIT_FILE, WREEnvironment } from './utils'
import { environmentWithREPLInitializedFile, INIT_PACKAGE_NAME, WREEnvironment } from './utils'

describe('Dynamic diagram', () => {

Expand Down Expand Up @@ -263,23 +263,23 @@ describe('Dynamic diagram', () => {
referenceLabel: 'pepona',
targetLabel: 'Ave',
targetType: 'object',
targetModule: INIT_FILE + '.Ave',
targetModule: INIT_PACKAGE_NAME + '.Ave',
})
checkConnection(elements, {
sourceLabel: 'Ave',
referenceLabel: 'amigue',
targetLabel: 'pepita',
targetType: 'object',
sourceModule: INIT_FILE + '.Ave',
targetModule: INIT_FILE + '.pepita',
sourceModule: INIT_PACKAGE_NAME + '.Ave',
targetModule: INIT_PACKAGE_NAME + '.pepita',
})
checkConnection(elements, {
sourceLabel: 'pepita',
referenceLabel: 'amigue',
targetLabel: 'Ave',
targetType: 'object',
sourceModule: INIT_FILE + '.pepita',
targetModule: INIT_FILE + '.Ave',
sourceModule: INIT_PACKAGE_NAME + '.pepita',
targetModule: INIT_PACKAGE_NAME + '.Ave',
})
checkNoConnectionToREPL(elements, 'pepita')
})
Expand All @@ -299,15 +299,15 @@ describe('Dynamic diagram', () => {
referenceLabel: 'pepita',
targetLabel: 'Ave',
targetType: 'object',
targetModule: INIT_FILE + '.Ave',
targetModule: INIT_PACKAGE_NAME + '.Ave',
})
checkConnection(elements, {
sourceLabel: 'Ave',
referenceLabel: 'amigue',
targetLabel: 'Ave',
targetType: 'object',
sourceModule: INIT_FILE + '.Ave',
targetModule: INIT_FILE + '.Ave',
sourceModule: INIT_PACKAGE_NAME + '.Ave',
targetModule: INIT_PACKAGE_NAME + '.Ave',
})

})
Expand Down
26 changes: 13 additions & 13 deletions test/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { buildEnvironment, Evaluation, EXCEPTION_MODULE, REPL, WRENatives } from
import { DirectedInterpreter, getStackTraceSanitized, interprete, Interpreter } from '../src/interpreter/interpreter'
import link from '../src/linker'
import { Body, Class, Field, Literal, Method, Package, ParameterizedType, Reference, Return, Send, Singleton, SourceIndex, SourceMap } from '../src/model'
import { environmentWithREPLInitializedFile, WREEnvironment } from './utils'
import { environmentWithREPLInitializedFile, INIT_FILE, INIT_PACKAGE_NAME, WREEnvironment } from './utils'

use(sinonChai)
should()
Expand Down Expand Up @@ -312,15 +312,15 @@ describe('Wollok Interpreter', () => {
}
`,
}, {
name: 'definitions.wlk', content: `
name: INIT_FILE, content: `
import medico.*
object testit {
method test() = new Medico(dosis = 200).saludar()
}
`,
}])
replEnvironment.scope.register([REPL, replEnvironment.getNodeByFQN('definitions')!])
replEnvironment.scope.register([REPL, replEnvironment.getNodeByFQN(INIT_PACKAGE_NAME)!])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error, result } = interprete(interpreter, 'testit.test()')
expect(error).to.be.undefined
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('Wollok Interpreter', () => {
}
`,
}, {
name: 'definitions.wlk', content: `
name: INIT_PACKAGE_NAME, content: `
import pediatra.*
object testit {
Expand All @@ -391,7 +391,7 @@ describe('Wollok Interpreter', () => {
`,
}])

replEnvironment.scope.register([REPL, replEnvironment.getNodeByFQN('definitions')!])
replEnvironment.scope.register([REPL, replEnvironment.getNodeByFQN(INIT_PACKAGE_NAME)!])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error, result } = interprete(interpreter, 'testit.test()')
expect(error).to.be.undefined
Expand Down Expand Up @@ -505,7 +505,7 @@ describe('Wollok Interpreter', () => {
expect(getStackTraceSanitized(error)).to.deep.equal(
[
'wollok.lang.EvaluationError: RangeError: super call for message fly/1: parameter #1 produces no value, cannot use it',
' at definitions.MockingBird.fly(minutes) [definitions.wlk:11]',
` at ${INIT_PACKAGE_NAME}.MockingBird.fly(minutes) [${INIT_PACKAGE_NAME}.wlk:11]`,
]
)
})
Expand All @@ -527,7 +527,7 @@ describe('Wollok Interpreter', () => {
expect(getStackTraceSanitized(error)).to.deep.equal(
[
'wollok.lang.EvaluationError: RangeError: Message fly - if condition produces no value, cannot use it',
' at definitions.Bird.fly(minutes) [definitions.wlk:5]',
` at ${INIT_PACKAGE_NAME}.Bird.fly(minutes) [${INIT_PACKAGE_NAME}.wlk:5]`,
]
)
})
Expand Down Expand Up @@ -643,8 +643,8 @@ describe('Wollok Interpreter', () => {
}
`)
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
expectError('new Bird(energy = void)', 'wollok.lang.EvaluationError: RangeError: new definitions.Bird: value of parameter \'energy\' produces no value, cannot use it')
expectError('new Bird(energy = 150, name = [1].add(2))', 'wollok.lang.EvaluationError: RangeError: new definitions.Bird: value of parameter \'name\' produces no value, cannot use it')
expectError('new Bird(energy = void)', `wollok.lang.EvaluationError: RangeError: new ${INIT_PACKAGE_NAME}.Bird: value of parameter 'energy' produces no value, cannot use it`)
expectError('new Bird(energy = 150, name = [1].add(2))', `wollok.lang.EvaluationError: RangeError: new ${INIT_PACKAGE_NAME}.Bird: value of parameter 'name' produces no value, cannot use it`)
})

it('should show Wollok stack', () => {
Expand Down Expand Up @@ -672,9 +672,9 @@ describe('Wollok Interpreter', () => {
assertBasicError(error)
expect(getStackTraceSanitized(error)).to.deep.equal([
'wollok.lang.EvaluationError: TypeError: Message plusDays: parameter "wollok.lang.Date" should be a number',
' at definitions.comun.despegar() [definitions.wlk:8]',
' at definitions.comun.volar() [definitions.wlk:4]',
' at definitions.Ave.volar() [definitions.wlk:17]',
` at ${INIT_PACKAGE_NAME}.comun.despegar() [${INIT_PACKAGE_NAME}.wlk:8]`,
` at ${INIT_PACKAGE_NAME}.comun.volar() [${INIT_PACKAGE_NAME}.wlk:4]`,
` at ${INIT_PACKAGE_NAME}.Ave.volar() [${INIT_PACKAGE_NAME}.wlk:17]`,
])
})

Expand All @@ -691,7 +691,7 @@ describe('Wollok Interpreter', () => {
assertBasicError(error)
expect(getStackTraceSanitized(error)).to.deep.equal([
'wollok.lang.EvaluationError: RangeError: Cannot send message +, receiver is an expression that produces no value.',
' at definitions.pepita.unMetodo() [definitions.wlk:4]',
` at ${INIT_PACKAGE_NAME}.pepita.unMetodo() [${INIT_PACKAGE_NAME}.wlk:4]`,
])
})

Expand Down
5 changes: 3 additions & 2 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Annotation, buildEnvironment, Class, Environment, FileContent, fromJSON
import { divideOn, List, notEmpty } from '../src/extensions'
import wre from '../src/wre/wre.json'

export const INIT_FILE = 'definitions'
export const INIT_PACKAGE_NAME = 'definitions'
export const INIT_FILE = INIT_PACKAGE_NAME + '.wlk'

export function buildEnvironmentForEachFile(folderPath: string, iterator: (filePackage: Package, fileContent: FileContent) => void): void {
const files = globby.sync(`**/*.@(${WOLLOK_FILE_EXTENSION}|${TEST_FILE_EXTENSION}|${PROGRAM_FILE_EXTENSION})`, { cwd: folderPath }).map(name => ({
Expand Down Expand Up @@ -85,7 +86,7 @@ export const validateExpectationProblem = (expectedProblem: Annotation, nodeProb
return effectiveProblem
}

export const environmentWithREPLInitializedFile = (content: string, name = INIT_FILE): Environment => {
export const environmentWithREPLInitializedFile = (content: string, name = INIT_PACKAGE_NAME): Environment => {
const environment = buildEnvironment([{ name: name + '.wlk', content }])
const initPackage = environment.getNodeByFQN<Package>(name)
environment.scope.register([REPL, initPackage])
Expand Down

0 comments on commit 2697b7b

Please sign in to comment.