aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/language/lux/translation.lux
blob: 3a29d167a65ff3f8a5dca0d9dbb8cfed55728542 (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
... 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]" try]]
   [data
    ["[0]" text (.use "[1]#[0]" equivalence)]
    [collection
     ["[0]" list]
     ["[0]" sequence]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   [//
    ["[0]" phase]
    [///
     [meta
      [archive
       ["[0]" registry]]]]]]])

(def dummy_host
  (/.Host Any Any)
  (implementation
   (def (evaluate _ _)
     {try.#Failure ""})
   (def (execute _)
     {try.#Failure ""})
   (def (define _ _ _)
     {try.#Failure ""})

   (def (ingest _ _)
     [])
   (def (re_learn _ _ _)
     {try.#Failure ""})
   (def (re_load _ _ _)
     {try.#Failure ""})))

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [expected_module (random.lower_cased 1)
         expected_prefix (random.lower_cased 2)])
      (all _.and
           (_.coverage [/.Host
                        /.evaluate /.execute /.define /.ingest /.re_learn /.re_load]
             true)
           (_.coverage [/.Operation /.Phase]
             true)
           (_.for [/.State
                   /.#anchor /.#host /.#buffer
                   /.#registry /.#registry_shift
                   /.#context /.#log /.#interim_artifacts]
                  (all _.and
                       (_.coverage [/.state]
                         (let [it (is (/.State Any Any Any)
                                      (/.state ..dummy_host expected_module))]
                           (and (same? expected_module (the /.#module it))
                                (when (the /.#anchor it) {.#None} true _ false)
                                (same? ..dummy_host (the /.#host it))
                                (when (the /.#buffer it) {.#None} true _ false)
                                (same? registry.empty (the /.#registry it))
                                (n.= 0 (the /.#registry_shift it))
                                (n.= 0 (the /.#counter it))
                                (when (the /.#context it) {.#None} true _ false)
                                (sequence.empty? (the /.#log it))
                                (list.empty? (the /.#interim_artifacts it)))))
                       (_.for [/.#module]
                              (all _.and
                                   (_.coverage [/.enter_module /.module]
                                     (|> (do phase.monad
                                           [expected (/.symbol expected_prefix)
                                            _ (/.enter_module expected)
                                            actual /.module]
                                           (in (same? expected actual)))
                                         (phase.result (/.state ..dummy_host expected_module))
                                         (try.else false)))
                                   ))
                       (_.for [/.#counter]
                              (all _.and
                                   (_.coverage [/.next]
                                     (|> (do phase.monad
                                           [before /.next
                                            after /.next]
                                           (in (n.= (++ before) after)))
                                         (phase.result (/.state ..dummy_host expected_module))
                                         (try.else false)))
                                   (_.coverage [/.symbol]
                                     (|> (do phase.monad
                                           [it (/.symbol expected_prefix)]
                                           (in (and (not (text#= expected_prefix it))
                                                    (text.starts_with? expected_prefix it))))
                                         (phase.result (/.state ..dummy_host expected_module))
                                         (try.else false)))
                                   ))
                       ))
           (_.for [/.Buffer]
                  (all _.and
                       (_.coverage [/.empty_buffer]
                         (sequence.empty? /.empty_buffer))
                       ))
           )))