aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/complex.lux
blob: bf08c727a3891f8ba74f3ed9c630b96253318037 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" io]
    ["[0]" try]]
   [data
    ["[0]" bit (.use "[1]#[0]" equivalence)]
    ["[0]" text (.use "[1]#[0]" equivalence)]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["[0]" i64 (.use "[1]#[0]" equivalence)]]]
   [meta
    ["[0]" location]
    [compiler
     [language
      [lux
       ["[0]" synthesis]]]
     [meta
      ["[0]" archive]]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   ["[0]" // (.only)
    ["[0]" host]
    ["[0]" runtime]
    [///
     ["[0]" extension]
     [//
      ["[0]" phase]
      ["[0]" translation]]]]]])

(type Variant/3
  (Or Bit (I64 Any) Text))

(type Tuple/3
  (And Bit (I64 Any) Text))

(def .public lux
  Lux
  [.#info            [.#target ""
                      .#version ""
                      .#mode {.#Build}
                      .#configuration (list)]
   .#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      []
   .#eval            (as (-> Type Code (Meta Any)) [])
   .#host            []])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [module (random.lower_cased 1)

         expected_bit random.bit
         expected_i64 random.i64
         expected_text (random.upper_cased 2)

         .let [extender (is extension.Extender
                            (function (_ _)
                              (undefined)))
               phase (//.translate extender ..lux)
               $unit [0 0]]])
      (all _.and
           (_.coverage [/.variant]
             (`` (and (,, (with_template [<lefts> <right?> <synthesis> <expected> <=>]
                            [(|> (do try.monad
                                   [.let [[_ host] (io.run! host.host)
                                          state (is runtime.State
                                                    (translation.state host module))]]
                                   (<| (phase.result state)
                                       (do phase.monad
                                         [_ (translation.set_buffer translation.empty_buffer)
                                          it (/.variant phase archive.empty
                                                        [<lefts> <right?> (<synthesis> location.dummy <expected>)])]
                                         (in (when (of host evaluate $unit [{.#None} it])
                                               {try.#Success actual}
                                               (when (as Variant/3 actual)
                                                 {<lefts> <right?> actual}
                                                 (<=> <expected> actual)

                                                 _
                                                 false)
                                               
                                               {try.#Failure error}
                                               false)))))
                                 (try.else false))]

                            [0 #0 synthesis.bit expected_bit bit#=]
                            [1 #0 synthesis.i64 expected_i64 i64#=]
                            [1 #1 synthesis.text expected_text text#=]
                            )))))
           (_.coverage [/.tuple]
             (|> (do try.monad
                   [.let [[_ host] (io.run! host.host)
                          state (is runtime.State
                                    (translation.state host module))]]
                   (<| (phase.result state)
                       (do phase.monad
                         [_ (translation.set_buffer translation.empty_buffer)
                          it (/.tuple phase archive.empty
                                      (list (synthesis.bit location.dummy expected_bit)
                                            (synthesis.i64 location.dummy expected_i64)
                                            (synthesis.text location.dummy expected_text)))]
                         (in (when (of host evaluate $unit [{.#None} it])
                               {try.#Success actual}
                               (let [[actual_bit actual_i64 actual_text] (as Tuple/3 actual)]
                                 (and (bit#= expected_bit actual_bit)
                                      (i64#= expected_i64 actual_i64)
                                      (text#= expected_text actual_text)))
                               
                               {try.#Failure error}
                               false)))))
                 (try.else false)))
           )))