aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test/test/luxc/analyser/common.lux
blob: 9a17fbb45851536cb4363e67394a73b4afc45ff7 (plain)
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
46
47
48
49
50
51
52
(;module:
  lux
  (lux (control pipe)
       ["r" math/random "r/" Monad<Random>]
       (data ["R" result])
       [macro]
       (macro [code]))
  (luxc ["&" base]
        [analyser])
  (test/luxc common))

(def: gen-unit
  (r;Random Code)
  (r/wrap (' [])))

(def: #export gen-primitive
  (r;Random [Type Code])
  (with-expansions
    [<generators> (do-template [<type> <code-wrapper> <value-gen>]
                    [(r;seq (r/wrap <type>) (r/map <code-wrapper> <value-gen>))]

                    [Unit code;tuple (r;list +0 gen-unit)]
                    [Bool code;bool  r;bool]
                    [Nat  code;nat   r;nat]
                    [Int  code;int   r;int]
                    [Deg  code;deg   r;deg]
                    [Real code;real  r;real]
                    [Char code;char  r;char]
                    [Text code;text  (r;text +5)]
                    )]
    ($_ r;either
        <generators>
        )))

(def: #export analyse
  &;Analyser
  (analyser;analyser (:!! [])))

(do-template [<name> <on-success> <on-failure>]
  [(def: #export (<name> analysis)
     (All [a] (-> (Lux a) Bool))
     (|> analysis
         (macro;run (init-compiler []))
         (case> (#R;Success _)
                <on-success>

                (#R;Error error)
                <on-failure>)))]

  [check-success true false]
  [check-failure false true]
  )