|
1 | 1 | import { should } from 'chai'
|
2 | 2 | import { resolve } from 'path'
|
3 |
| -import { buildEnvironment } from './assertions' |
4 |
| -import natives from '../src/wre/wre.natives' |
5 |
| -import { Environment, GAME_MODULE, PROGRAM_FILE_EXTENSION } from '../src' |
| 3 | +import { Environment, Execution, get, Natives, PROGRAM_FILE_EXTENSION, RuntimeObject } from '../src' |
6 | 4 | import { interpret, Interpreter } from '../src/interpreter/interpreter'
|
| 5 | +import natives from '../src/wre/wre.natives' |
| 6 | +import { buildEnvironment } from './assertions' |
7 | 7 |
|
8 | 8 | should()
|
9 | 9 |
|
10 |
| -// TODO: Move the wollok code to language -> We need to run programs! |
11 |
| - |
12 | 10 | describe('Wollok Game', () => {
|
13 | 11 |
|
14 | 12 | describe('actions', () => {
|
15 | 13 |
|
16 | 14 | let environment: Environment
|
17 | 15 | let interpreter: Interpreter
|
| 16 | + const logs: string[] = [] |
18 | 17 |
|
| 18 | + const mockNativeFunction = function* (_self: RuntimeObject, obj: RuntimeObject): Execution<void> { |
| 19 | + logs.push(obj.innerString!) |
| 20 | + } |
19 | 21 |
|
20 | 22 | before(async () => {
|
21 | 23 | environment = await buildEnvironment(`**/*.${PROGRAM_FILE_EXTENSION}`, resolve('language', 'test', 'game'))
|
| 24 | + const wConsole = get<Natives>(natives, 'wollok.lib.console')! |
| 25 | + wConsole.println = mockNativeFunction |
22 | 26 | })
|
23 | 27 |
|
24 | 28 | beforeEach(() => {
|
25 | 29 | interpreter = interpret(environment, natives)
|
26 | 30 | })
|
27 | 31 |
|
28 |
| - it('addVisual', () => { |
29 |
| - interpreter.run('actions.addVisual') |
30 |
| - const visuals = interpreter.object(GAME_MODULE).get('visuals')!.innerValue! |
31 |
| - visuals.should.have.length(1) |
32 |
| - }) |
33 |
| - |
34 |
| - it('removeVisual', () => { |
35 |
| - interpreter.run('actions.removeVisual') |
36 |
| - const visuals = interpreter.object(GAME_MODULE).get('visuals')!.innerValue! |
37 |
| - visuals.should.have.length(0) |
38 |
| - }) |
39 |
| - |
40 |
| - it('say', () => { |
| 32 | + it('say set message and time to visual', () => { |
41 | 33 | interpreter.run('actions.say')
|
42 | 34 | interpreter.object('actions.visual').get('message')!.innerValue!.should.equal('Hi!')
|
43 | 35 | interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000)
|
44 | 36 | })
|
45 | 37 |
|
46 |
| - it('clear', () => { |
47 |
| - interpreter.run('actions.clear') |
48 |
| - const visuals = interpreter.object(GAME_MODULE)!.get('visuals')!.innerValue! |
49 |
| - visuals.should.have.length(0) |
| 38 | + it('on DomainError, visual source says the message', () => { |
| 39 | + interpreter.run('actions.domainError') |
| 40 | + interpreter.object('actions.visual').get('message')!.innerValue!.should.equal('DOMAIN_ERROR') |
| 41 | + interpreter.object('actions.visual').get('messageTime')!.innerValue!.should.equal(2000) |
| 42 | + }) |
50 | 43 |
|
| 44 | + it('on DomainError with error reporter, it says the message', () => { |
| 45 | + interpreter.run('actions.domainErrorWithReporter') |
| 46 | + interpreter.object('actions.reporter').get('message')!.innerValue!.should.equal('DOMAIN_ERROR') |
| 47 | + interpreter.object('actions.reporter').get('messageTime')!.innerValue!.should.equal(2000) |
51 | 48 | })
|
52 | 49 |
|
53 |
| - it('flush event', () => { |
54 |
| - const game = interpreter.object(GAME_MODULE)! |
55 |
| - const time = interpreter.reify(1) |
56 |
| - interpreter.send('flushEvents', game, time) |
| 50 | + it('on Error, console should print stack trace', () => { |
| 51 | + interpreter.run('actions.genericError') |
| 52 | + logs.should.be.deep.eq([ |
| 53 | + 'wollok.lang.Exception: ERROR', |
| 54 | + '\tat actions.genericError [actions.wpgm:33]']) |
57 | 55 | })
|
58 | 56 |
|
59 | 57 | it('with file name game (devil test)', () => {
|
|
0 commit comments