aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test/test/luxc/lang/synthesis/case/special.lux
blob: 585c7d3494ab6d5c5e43d3c2a34eecea9a713e51 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(;module:
  lux
  (lux [io]
       (control [monad #+ do]
                pipe)
       (meta [code])
       ["r" math/random "r/" Monad<Random>]
       test)
  (luxc (lang ["la" analysis]
              ["ls" synthesis]
              (synthesis [";S" expression])
              [";L" variable #+ Variable]))
  (../.. common))

(context: "Dummy variables."
  (<| (times +100)
      (do @
        [maskedA gen-primitive
         temp (|> r;nat (:: @ map (n.% +100)))
         #let [maskA (` ("lux case" (~ maskedA)
                         {("lux case bind" (~ (code;nat temp)))
                          (~ (la;var (variableL;local temp)))}))]]
        (test "Dummy variables created to mask expressions get eliminated during synthesis."
              (|> (expressionS;synthesize maskA)
                  (corresponds? maskedA))))))

(context: "Let expressions."
  (<| (times +100)
      (do @
        [registerA r;nat
         inputA gen-primitive
         outputA gen-primitive
         #let [letA (` ("lux case" (~ inputA)
                        {("lux case bind" (~ (code;nat registerA)))
                         (~ outputA)}))]]
        (test "Can detect and reify simple 'let' expressions."
              (|> (expressionS;synthesize letA)
                  (case> (^ [_ (#;Form (list [_ (#;Text "lux let")] [_ (#;Nat registerS)] inputS outputS))])
                         (and (n.= registerA registerS)
                              (corresponds? inputA inputS)
                              (corresponds? outputA outputS))

                         _
                         false))))))

(context: "If expressions."
  (<| (times +100)
      (do @
        [then|else r;bool
         inputA gen-primitive
         thenA gen-primitive
         elseA gen-primitive
         #let [ifA (if then|else
                     (` ("lux case" (~ inputA)
                         {true (~ thenA)
                          false (~ elseA)}))
                     (` ("lux case" (~ inputA)
                         {false (~ elseA)
                          true (~ thenA)})))]]
        (test "Can detect and reify simple 'if' expressions."
              (|> (expressionS;synthesize ifA)
                  (case> (^ [_ (#;Form (list [_ (#;Text "lux if")] inputS thenS elseS))])
                         (and (corresponds? inputA inputS)
                              (corresponds? thenA thenS)
                              (corresponds? elseA elseS))

                         _
                         false))))))