aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/meta/import.lux
blob: a60d920a8d083633dbd069720d39948e79ccf24a (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
... 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]" maybe (.use "[1]#[0]" functor)]
    ["[0]" try (.use "[1]#[0]" functor)]
    ["[0]" exception]
    [concurrency
     ["[0]" async]]]
   [data
    ["[0]" product]
    ["[0]" bit (.use "[1]#[0]" equivalence)]
    ["[0]" binary (.only Binary) (.use "[1]#[0]" equivalence)
     ["[0]" \\format]
     ["<[1]>" \\parser]]
    ["[0]" format
     ["[0]" tar (.only Tar)]]
    ["[0]" text (.use "[1]#[0]" equivalence)
     ["%" \\format (.only format)]
     [encoding
      ["[0]" utf8]]]
    [collection
     ["[0]" sequence]
     ["[0]" dictionary]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]
   [world
    ["[0]" file]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   [//
    ["[0]" export]
    ["[0]" io
     ["[1]" context]]]]])

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Import])
      (do [! random.monad]
        [library/0 (random.lower_cased 1)
         library/1 (random.lower_cased 2)
         
         .let [/ .module_separator
               random_file (is (Random file.Path)
                               (of ! each (text.suffix io.lux_extension) (random.lower_cased 3)))]
         file/0 random_file
         
         dir/0 (random.lower_cased 4)
         file/1 (of ! each (|>> (format dir/0 /)) random_file)
         
         .let [random_content (is (Random Binary)
                                  (of ! each (|>> %.nat (of utf8.codec encoded)) random.nat))]
         now random.instant
         content/0 random_content
         content/1 random_content
         .let [library_content (|> (do try.monad
                                     [file/0 (tar.path file/0)
                                      file/1 (tar.path file/1)
                                      content/0 (tar.content content/0)
                                      content/1 (tar.content content/1)]
                                     (in (|> (sequence.sequence {tar.#Normal [file/0 now export.mode export.ownership content/0]}
                                                                {tar.#Normal [file/1 now export.mode export.ownership content/1]})
                                             (\\format.result tar.format))))
                                   (try.else (binary.empty 0)))
               library_content/0 (|> (do try.monad
                                       [file/0 (tar.path file/0)
                                        content/0 (tar.content content/0)]
                                       (in (|> (sequence.sequence {tar.#Normal [file/0 now export.mode export.ownership content/0]})
                                               (\\format.result tar.format))))
                                     (try.else (binary.empty 0)))
               library_content/1 (|> (do try.monad
                                       [file/1 (tar.path file/1)
                                        content/1 (tar.content content/1)]
                                       (in (|> (sequence.sequence {tar.#Normal [file/1 now export.mode export.ownership content/1]})
                                               (\\format.result tar.format))))
                                     (try.else (binary.empty 0)))
               library_content/-0 (|> (do try.monad
                                        [file/0 (tar.path file/0)
                                         content/0 (tar.content content/0)]
                                        (in (|> (sequence.sequence {tar.#Contiguous [file/0 now export.mode export.ownership content/0]})
                                                (\\format.result tar.format))))
                                      (try.else (binary.empty 0)))
               library_content/-1 (|> (do try.monad
                                        [file/0 (tar.path file/0)]
                                        (in (|> (sequence.sequence {tar.#Symbolic_Link file/0})
                                                (\\format.result tar.format))))
                                      (try.else (binary.empty 0)))
               library_content/-2 (|> (do try.monad
                                        [file/0 (tar.path file/0)]
                                        (in (|> (sequence.sequence {tar.#Directory file/0})
                                                (\\format.result tar.format))))
                                      (try.else (binary.empty 0)))
               imported? (is (-> /.Import Bit)
                             (function (_ it)
                               (and (n.= 2 (dictionary.size it))
                                    (|> it
                                        (dictionary.value file/0)
                                        (maybe#each (binary#= content/0))
                                        (maybe.else false))
                                    (|> it
                                        (dictionary.value file/1)
                                        (maybe#each (binary#= content/1))
                                        (maybe.else false)))))]]
        (all _.and
             (in (do [! async.monad]
                   [it/0 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (of fs write library/0 library_content)]
                           (/.import fs (list library/0)))
                    it/1 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (of fs write library/0 library_content/0)
                            _ (of fs write library/1 library_content/1)]
                           (/.import fs (list library/0 library/1)))]
                   (unit.coverage [/.import]
                     (and (|> it/0
                              (try#each imported?)
                              (try.else false))
                          (|> it/1
                              (try#each imported?)
                              (try.else false))))))
             (in (do [! async.monad]
                   [it (do (try.with !)
                         [.let [fs (file.mock /)]
                          _ (of fs write library/0 library_content)
                          _ (/.import fs (list library/0 library/0))]
                         (in false))]
                   (unit.coverage [/.duplicate]
                     (exception.otherwise (exception.match? /.duplicate) it))))
             (in (do [! async.monad]
                   [it/0 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (of fs write library/0 library_content/-0)
                            _ (/.import fs (list library/0))]
                           (in false))
                    it/1 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (of fs write library/0 library_content/-1)
                            _ (/.import fs (list library/0))]
                           (in false))
                    it/2 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (of fs write library/0 library_content/-2)
                            _ (/.import fs (list library/0))]
                           (in false))]
                   (unit.coverage [/.useless_tar_entry]
                     (and (exception.otherwise (exception.match? /.useless_tar_entry) it/0)
                          (exception.otherwise (exception.match? /.useless_tar_entry) it/1)
                          (exception.otherwise (exception.match? /.useless_tar_entry) it/2)))))
             ))))