aboutsummaryrefslogtreecommitdiff
path: root/src/eval-env/test.ts
blob: 4dd8c8da32355075358b3534992be86f9173c070 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Type } from 'ts-morph'
import { Ctx } from '../types'

export default (ctx: Ctx, args: Type[]) => ({
  Test: ctx.withScope(async () => {
    const [msg, effs] = args
    process.stdout.write(` - ${ctx.getTypeValue(msg)} `)

    try {
      for (const eff of effs?.getTupleElements() ?? []) {
        await ctx.evaluateType(ctx, eff)
      }

      console.log('[✓]')
    } catch (e) {
      // console.log('[TEST FAILED]')
      throw e
    }

    return []
  }),

  Assert: async () => {
    if (!ctx.getTypeValue(args[0])) {
      throw new Error('Assertion failed')
    }

    return []
  },

  ShowAssertionError: async () => {
    const [left, right] = args
    console.log()
    console.log(' | Assertion error:')
    console.log(' |   - Left: ', ctx.typeToString(left))
    console.log(' |   - Right:', ctx.typeToString(right))
    console.log()

    return []
  },
})