aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/macro/syntax/definition.lux
blob: c98b1e853a7ef012dbc958f60f948569c1fb8491 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(.module:
  [library
   [lux #*
    ["_" test (#+ Test)]
    [abstract
     [monad (#+ do)]
     [\\spec
      ["$." equivalence]]]
    [control
     ["." try]
     ["." exception]
     ["<>" parser
      ["<.>" code]]]
    [math
     ["." random (#+ Random)]]
    [macro
     ["." code ("#\." equivalence)]]
    [meta
     ["." location]]]]
  [\\library
   ["." /]]
  ["$."// #_
   ["#." check]
   ["#." annotations]
   ["#/" // #_
    ["#." code]]])

(def: #export random
  (Random /.Definition)
  ($_ random.and
      (random.ascii/alpha 5)
      (random.or $//check.random
                 $///code.random)
      $//annotations.random
      random.bit
      ))

(def: compiler
  {#.info            {#.target  "FAKE"
                      #.version "0.0.0"
                      #.mode    #.Build}
   #.source          [location.dummy 0 ""]
   #.location        location.dummy
   #.current_module  #.None
   #.modules         (list)
   #.scopes          (list)
   #.type_context    {#.ex_counter 0
                      #.var_counter 0
                      #.var_bindings (list)}
   #.expected        #.None
   #.seed            0
   #.scope_type_vars (list)
   #.extensions      []
   #.host            []})

(def: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.Definition])
      ($_ _.and
          (_.for [/.equivalence]
                 ($equivalence.spec /.equivalence ..random))

          (do random.monad
            [expected ..random
             
             type $///code.random
             untyped_value $///code.random]
            ($_ _.and
                (_.cover [/.format /.parser]
                         (case (<code>.run (/.parser compiler)
                                           (list (/.format expected)))
                           (#try.Failure error)
                           false
                           
                           (#try.Success actual)
                           (\ /.equivalence = expected actual)))
                (_.cover [/.typed]
                         (let [expected (set@ #/.value (#.Left [type untyped_value]) expected)]
                           (case (<code>.run (/.typed compiler)
                                             (list (/.format expected)))
                             (#try.Failure error)
                             false
                             
                             (#try.Success actual)
                             (\ /.equivalence = expected actual))))
                (_.cover [/.lacks_type!]
                         (let [expected (set@ #/.value (#.Right untyped_value) expected)]
                           (case (<code>.run (/.typed compiler)
                                             (list (/.format expected)))
                             (#try.Failure error)
                             (exception.match? /.lacks_type! error)
                             
                             (#try.Success actual)
                             false)))
                )))
      ))