aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/version.lux
blob: 4a8ccc1beb7f5d019d7a8bbfb14830cfd9dfad9d (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
(.module:
  [library
   [lux #*
    ["_" test (#+ Test)]
    [abstract
     [monad (#+ do)]]
    [control
     ["." try]
     ["." exception (#+ exception:)]
     [concurrency
      ["." promise (#+ Promise)]]]
    [data
     ["." maybe]
     ["." text ("#\." equivalence)
      ["%" format (#+ format)]]]
    [math
     ["." random]]
    [tool
     [compiler
      ["." version]
      ["." language #_
       ["#/." lux #_
        ["#" version]]]]]
    [world
     ["." console (#+ Console Mock)]]]]
  [///
   ["@." profile]]
  [\\program
   ["." /]])

(exception: #export console_is_closed!)

(implementation: mock
  (Mock [Bit Text])

  (def: (on_read [open? state])
    (if open?
      (try.from_maybe
       (do maybe.monad
         [head (text.nth 0 state)
          [_ tail] (text.split 1 state)]
         (wrap [[open? tail] head])))
      (exception.throw ..console_is_closed! [])))
  (def: (on_read_line [open? state])
    (if open?
      (try.from_maybe
       (do maybe.monad
         [[output state] (text.split_with text.new_line state)]
         (wrap [[open? state] output])))
      (exception.throw ..console_is_closed! [])))
  (def: (on_write input [open? state])
    (if open?
      (#try.Success [open? (format state input)])
      (exception.throw ..console_is_closed! [])))
  (def: (on_close [open? buffer])
    (if open?
      (#try.Success [false buffer])
      (exception.throw ..console_is_closed! []))))

(def: #export echo
  (-> Text (Console Promise))
  (|>> [true]
       (console.mock ..mock)
       console.async))

(def: #export test
  Test
  (<| (_.covering /._)
      (do random.monad
        [profile @profile.random]
        (wrap (do promise.monad
                [#let [console (..echo "")]
                 verdict (do (try.with promise.monad)
                           [_ (/.do! console profile)
                            logging (\ console read_line [])]
                           (wrap (text\= (version.format language/lux.version)
                                         logging)))]
                (_.cover' [/.do!]
                          (try.default false verdict)))))))