aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/program.lux
blob: 4d0f13aa9570bc2f71843702ad903b88857456aa (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
(.using
 [library
  [lux "*"
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" io]
    ["[0]" try]
    ["<>" parser
     ["<[0]>" code]
     ["<[0]>" cli]]]
   [data
    ["[0]" text]
    [collection
     ["[0]" list]]]
   [macro
    [syntax (.only syntax:)]]
   [math
    ["[0]" random]]]]
 [\\library
  ["[0]" /]])

(syntax: (actual_program [actual_program (<| <code>.form
                                             (<>.after (<code>.this_text "lux def program"))
                                             <code>.any)])
  (in (list actual_program)))

(def: .public test
  Test
  (<| (_.covering /._)
      (do random.monad
        [inputs (random.list 5 (random.upper_case 5))]
        (_.coverage [/.program:]
          (let [(open "list#[0]") (list.equivalence text.equivalence)]
            (and (with_expansions [<program> (/.program: all_arguments
                                               (io.io all_arguments))]
                   (let [outcome ((is (-> (List Text) (io.IO Any))
                                      (..actual_program <program>))
                                  inputs)]
                     (same? (is Any inputs)
                            (io.run! outcome))))
                 (with_expansions [<program> (/.program: [arg/0 <cli>.any
                                                          arg/1 <cli>.any
                                                          arg/2 <cli>.any
                                                          arg/3 <cli>.any
                                                          arg/4 <cli>.any]
                                               (io.io (list arg/4 arg/3 arg/2 arg/1 arg/0)))]
                   (let [outcome ((is (-> (List Text) (io.IO Any))
                                      (..actual_program <program>))
                                  inputs)]
                     (list#= (list.reversed inputs)
                             (as (List Text) (io.run! outcome)))))
                 (with_expansions [<program> (/.program: [all_arguments (<>.many <cli>.any)]
                                               (io.io all_arguments))]
                   (let [outcome ((is (-> (List Text) (io.IO Any))
                                      (..actual_program <program>))
                                  inputs)]
                     (list#= inputs
                             (as (List Text) (io.run! outcome)))))
                 (with_expansions [<program> (/.program: [arg/0 <cli>.any
                                                          arg/1 <cli>.any
                                                          arg/2 <cli>.any
                                                          arg/3 <cli>.any]
                                               (io.io []))]
                   (case (try ((is (-> (List Text) (io.IO Any))
                                   (..actual_program <program>))
                               inputs))
                     {try.#Success _}
                     false
                     
                     {try.#Failure _}
                     true))))))))