aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/format/json.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-10-24 16:58:07 -0400
committerEduardo Julian2022-10-24 16:58:07 -0400
commit45c599e49ae2659331d13222948f7e755967fdf9 (patch)
tree1f1b0be2423b69562d7479fd8db9abb509aaaf7f /stdlib/source/test/lux/data/format/json.lux
parent99d196a528804b3b136ac6c45cb872a5e7c70cde (diff)
New module just for the Char type + fixes to JSON parsing.
Diffstat (limited to 'stdlib/source/test/lux/data/format/json.lux')
-rw-r--r--stdlib/source/test/lux/data/format/json.lux54
1 files changed, 51 insertions, 3 deletions
diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux
index e04705902..ad9427770 100644
--- a/stdlib/source/test/lux/data/format/json.lux
+++ b/stdlib/source/test/lux/data/format/json.lux
@@ -26,9 +26,10 @@
["[0]" set]
["[0]" list (.use "[1]#[0]" functor)]]]
[math
- ["[0]" random (.only Random)]
- [number
+ ["[0]" random (.only Random) (.use "[1]#[0]" monad)]
+ [number (.only hex)
["n" nat]
+ ["[0]" i64]
["[0]" frac]]]
["[0]" meta (.only)
["@" target]
@@ -297,6 +298,42 @@
[value (macro.symbol "string")]
(in (list (code.text (%.code value)))))))
+(def (digits/4 it)
+ (-> Nat Text)
+ (<| (if (n.< (hex "10") it)
+ (format "000" (%.nat_16 it)))
+ (if (n.< (hex "100") it)
+ (format "00" (%.nat_16 it)))
+ (if (n.< (hex "1000") it)
+ (format "0" (%.nat_16 it)))
+ (%.nat_16 it)))
+
+(def escaped_string
+ (Random [Text Text])
+ (all random.either
+ (random#in [text.tab "\t"])
+ (random#in [text.back_space "\b"])
+ (random#in [text.new_line "\n"])
+ (random#in [text.carriage_return "\r"])
+ (random#in [text.form_feed "\f"])
+ (random#in [text.double_quote (format "\" text.double_quote)])
+ (random#in ["\" "\\"])
+ (do [! random.monad]
+ [char (at ! each (i64.and (hex "FF"))
+ random.nat)]
+ (in [(text.of_char char)
+ (format "\u" (digits/4 char))]))
+ ))
+
+(def any_string
+ (Random [Text Text])
+ (all random.either
+ escaped_string
+ (do random.monad
+ [it (random.alphabetic 1)]
+ (in [it it]))
+ ))
+
(def .public test
Test
(<| (_.covering /._)
@@ -305,7 +342,18 @@
(_.for [/.equivalence]
($equivalence.spec /.equivalence ..random))
(_.for [/.codec]
- ($codec.spec /.equivalence /.codec ..random))
+ (all _.and
+ ($codec.spec /.equivalence /.codec ..random)
+ (do random.monad
+ [key (random.alphabetic 1)
+ [expected escaped] any_string]
+ (_.coverage [/.#String]
+ (|> {/.#String escaped}
+ (at /.codec encoded)
+ (at /.codec decoded)
+ (try#each (at /.equivalence = {/.#String expected}))
+ (try.else false))))
+ ))
(do random.monad
[sample ..random]