aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/version.lux
blob: b8792434a4fed98f14b2efe7706591ffa984e1c0 (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
(.using
 [library
  [lux "*"
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" maybe]
    ["[0]" try]
    ["[0]" exception (.only exception:)]
    [concurrency
     ["[0]" async (.only Async)]]]
   [data
    ["[0]" text ("[1]#[0]" equivalence)
     ["%" format (.only format)]]]
   [math
    ["[0]" random]]
   [meta
    ["lux_[0]" version]]
   [tool
    [compiler
     ["[0]" version]]]
   [world
    ["[0]" console (.only Console Mock)]]]]
 [///
  ["@[0]" profile]]
 [\\program
  ["[0]" /]])

(exception: .public console_is_closed!)

(implementation: mock
  (Mock [Bit Text])

  (def: (on_read [open? state])
    (if open?
      (try.of_maybe
       (do maybe.monad
         [head (text.char 0 state)
          [_ tail] (text.split_at 1 state)]
         (in [[open? tail] head])))
      (exception.except ..console_is_closed! [])))
  (def: (on_read_line [open? state])
    (if open?
      (try.of_maybe
       (do maybe.monad
         [[output state] (text.split_by text.new_line state)]
         (in [[open? state] output])))
      (exception.except ..console_is_closed! [])))
  (def: (on_write input [open? state])
    (if open?
      {try.#Success [open? (format state input)]}
      (exception.except ..console_is_closed! [])))
  (def: (on_close [open? buffer])
    (if open?
      {try.#Success [false buffer]}
      (exception.except ..console_is_closed! []))))

(def: .public echo
  (-> Text (Console Async))
  (|>> [true]
       (console.mock ..mock)
       console.async))

(def: .public test
  Test
  (<| (_.covering /._)
      (do random.monad
        [profile @profile.random]
        (in (do async.monad
              [.let [console (..echo "")]
               verdict (do (try.with async.monad)
                         [_ (/.do! console profile)
                          logging (# console read_line [])]
                         (in (text#= (version.format lux_version.latest)
                                     logging)))]
              (_.coverage' [/.do!]
                (try.else false verdict)))))))