aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test/test/luxc/analyser/struct.lux
blob: 869b2b0d1d4e77fc85bf42b5a2987d3bf4f22e94 (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
(;module:
  lux
  (lux [io]
       (control monad
                pipe)
       (data ["R" result]
             [product]
             (coll [list "L/" Functor<List>]))
       ["r" math/random "R/" Monad<Random>]
       [type "Type/" Eq<Type>]
       [macro #+ Monad<Lux>]
       test)
  (luxc ["&" base]
        (lang ["~" analysis])
        [analyser]
        (analyser ["@" struct]
                  ["@;" common]))
  (.. common))

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

(test: "Tuples"
  [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2))))
   primitives (r;list size gen-simple-primitive)]
  ($_ seq
      (assert "Can analyse tuple."
              (|> (@common;with-unknown-type
                    (@;analyse-tuple analyse (L/map product;right primitives)))
                  (macro;run init-compiler)
                  (case> (#R;Success [_type (#~;Tuple elems)])
                         (and (Type/= (type;tuple (L/map product;left primitives))
                                      _type)
                              (n.= size (list;size elems)))

                         _
                         false))
              )))