aboutsummaryrefslogtreecommitdiff
path: root/examples/test-runner.ts
blob: fecd3e44689175f89524a35d943b25f7b65db8a7 (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
42
43
44
45
import { Do, Effect } from '../stdlib/effect'
import { PutStringLn } from '../stdlib/stdio'
import { DefineEffect } from '../stdlib/sys'

type Test<m extends string, effs extends Effect[]> = [
  PutStringLn<`* ${m}`>,
  ...effs,
]

type Equals<Left, Right> =
  [Left] extends [Right] ? ([Right] extends [Left] ? true : false) : false

type Not<B extends boolean> = B extends true ? false : true

interface TestConfig {
  CompileTestFailures: false
}

type Assertion = TestConfig['CompileTestFailures'] extends true ? true : boolean
interface Assert<_B extends Assertion> extends Effect { }

export type main = [
  DefineEffect<'Assert', `([b], ctx) => {
    if (!ctx.getTypeValue(b)) {
      throw new Error('AAAAAAA')
    }
  }`>,

  PutStringLn<"Running tests...">,

  Do<[
    ...Test<"should do some stuff", [
      Assert<Equals<1, 1>>,
      Assert<Not<Equals<2, 1>>>,
    ]>,

    ...Test<"hello world", [
      Assert<Equals<1, 1>>,
    ]>,

    ...Test<"should do some other stuff", [
      Assert<Equals<1, 1>>,
    ]>,
  ]>,
]