aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test/test/luxc/generator/primitive.lux
blob: 84f47f146a95321c10aa84d16c79a270379fba53 (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
(;module:
  lux
  (lux [io]
       (control [monad #+ do]
                pipe)
       (data text/format
             ["e" error]
             [bool "B/" Eq<Bool>]
             [text "T/" Eq<Text>])
       ["r" math/random]
       [meta]
       (meta [code])
       test)
  (luxc [";L" host]
        (lang ["ls" synthesis])
        [analyser]
        [synthesizer]
        (generator [";G" expression]
                   ["@;" runtime]
                   ["@;" eval]
                   ["@;" common]))
  (test/luxc common))

(context: "Primitives."
  (<| (times +100)
      (do @
        [%bool% r;bool
         %nat% r;nat
         %int% r;int
         %deg% r;deg
         %frac% r;frac
         %text% (r;text +5)]
        (with-expansions
          [<tests> (do-template [<desc> <type> <synthesis> <sample> <test>]
                     [(test (format "Can generate " <desc> ".")
                            (|> (do meta;Monad<Meta>
                                  [sampleI (expressionG;generate (<synthesis> <sample>))]
                                  (@eval;eval sampleI))
                                (meta;run (init-compiler []))
                                (case> (#e;Success valueG)
                                       (<test> <sample> (:! <type> valueG))

                                       _
                                       false)))]

                     ["bool" Bool code;bool %bool% B/=]
                     ["nat"  Nat  code;nat  %nat%  n.=]
                     ["int"  Int  code;int  %int%  i.=]
                     ["deg"  Deg  code;deg  %deg%  d.=]
                     ["frac" Frac code;frac %frac% f.=]
                     ["text" Text code;text %text% T/=])]
          ($_ seq
              (test "Can generate unit."
                    (|> (do meta;Monad<Meta>
                          [sampleI (expressionG;generate (' []))]
                          (@eval;eval sampleI))
                        (meta;run (init-compiler []))
                        (case> (#e;Success valueG)
                               (is hostL;unit (:! Text valueG))

                               _
                               false)))
              <tests>
              )))))