aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/tool/compiler/meta/import.lux
blob: 75bda2a9f64f4c847f7651aa8f7540dcda25c518 (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
(.using
 [library
  [lux "*"
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" maybe ("[1]#[0]" functor)]
    ["[0]" try ("[1]#[0]" functor)]
    ["[0]" exception]
    [concurrency
     ["[0]" async]]
    [parser
     ["<[0]>" binary]]]
   [data
    ["[0]" product]
    ["[0]" binary (.only Binary) ("[1]#[0]" equivalence)]
    ["[0]" bit ("[1]#[0]" equivalence)]
    ["[0]" format "_"
     ["[0]" tar (.only Tar)]
     ["[1]" binary]]
    ["[0]" text ("[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]]]]
 [\\library
  ["[0]" /
   [//
    ["[0]" export]
    ["[0]" io "_"
     ["[1]" context]]]]])

(def: .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Import])
      (do [! random.monad]
        [library/0 (random.lower_case 1)
         library/1 (random.lower_case 2)
         
         .let [/ .module_separator
               random_file (is (Random file.Path)
                               (# ! each (text.suffix io.lux_extension) (random.lower_case 3)))]
         file/0 random_file
         
         dir/0 (random.lower_case 4)
         file/1 (# ! each (|>> (format dir/0 /)) random_file)
         
         .let [random_content (is (Random Binary)
                                  (# ! each (|>> %.nat (# 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.writer))))
                                   (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.writer))))
                                     (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.writer))))
                                     (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.writer))))
                                      (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.writer))))
                                      (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.writer))))
                                      (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 /)]
                            _ (# fs write library/0 library_content)]
                           (/.import fs (list library/0)))
                    it/1 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (# fs write library/0 library_content/0)
                            _ (# fs write library/1 library_content/1)]
                           (/.import fs (list library/0 library/1)))]
                   (_.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 /)]
                          _ (# fs write library/0 library_content)
                          _ (/.import fs (list library/0 library/0))]
                         (in false))]
                   (_.coverage' [/.duplicate]
                     (exception.otherwise (exception.match? /.duplicate) it))))
             (in (do [! async.monad]
                   [it/0 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (# fs write library/0 library_content/-0)
                            _ (/.import fs (list library/0))]
                           (in false))
                    it/1 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (# fs write library/0 library_content/-1)
                            _ (/.import fs (list library/0))]
                           (in false))
                    it/2 (do (try.with !)
                           [.let [fs (file.mock /)]
                            _ (# fs write library/0 library_content/-2)
                            _ (/.import fs (list library/0))]
                           (in false))]
                   (_.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)))))
             ))))