aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/format/json.lux
blob: f276c5180b45aac65cd792c5ab6d9d8541e6181c (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
(.module:
  [lux #*
   data/text/format
   ["_" test (#+ Test)]
   [control
    pipe
    codec
    [monad (#+ do Monad)]
    [equivalence (#+ Equivalence)]
    ["p" parser]
    {[0 #test]
     [/
      ["$." equivalence]
      ["$." codec]]}]
   [data
    ["." error]
    ["." bit]
    ["." maybe]
    ["." text]
    [number
     ["." frac]]
    [collection
     [row (#+ row)]
     ["d" dictionary]
     ["." list]]]
   [macro
    [poly (#+ derived:)]
    ["." poly/equivalence]
    ["." poly/json]]
   [type
    ["." unit]]
   [math
    ["r" random (#+ Random)]]
   [time
    ["ti" instant]
    ["tda" date]
    ## ["tdu" duration]
    ]]
  [test
   [lux
    [time
     ["_." instant]
     ## ["_." duration]
     ["_." date]]]]
  {1
   ["." / (#+ JSON)]}
  )

(def: #export json
  (Random JSON)
  (r.rec (function (_ recur)
           (do r.monad
             [size (:: @ map (n/% 2) r.nat)]
             ($_ r.or
                 (:: @ wrap [])
                 r.bit
                 r.safe-frac
                 (r.unicode size)
                 (r.row size recur)
                 (r.dictionary text.hash size (r.unicode size) recur)
                 )))))

(def: #export test
  Test
  (<| (_.context (%name (name-of /._)))
      ($_ _.and
          ($equivalence.spec /.equivalence ..json)
          ($codec.spec /.equivalence /.codec ..json)
          )))