(.require [library [lux (.except) ["_" test (.only Test)] [abstract [monad (.only do)]] [control ["[0]" try]] [data ["[0]" bit (.use "[1]#[0]" equivalence)] ["[0]" text (.use "[1]#[0]" equivalence)]] [math ["[0]" random (.only Random)] [number ["[0]" nat] ["[0]" frac]]]]] [\\library ["[0]" /]] ["$[0]" / ["[1][0]" export]]) (/.import Uint8Array "[1]::[0]") ... On Nashorn (/.import java/lang/String "[1]::[0]" (new [Uint8Array /.String]) (getBytes [/.String] Uint8Array)) ... On Node (/.import Buffer "[1]::[0]" ("static" from [/.String /.String] Buffer) (toString [/.String] /.String)) ... On the browser (/.import TextEncoder "[1]::[0]" (new [/.String]) (encode [/.String] Uint8Array)) (/.import TextDecoder "[1]::[0]" (new [/.String]) (decode [Uint8Array] /.String)) (def .public test Test (do [! random.monad] [boolean random.bit number (at ! each (|>> (nat.% 100) nat.frac) random.nat) string (random.ascii 5) function (at ! each (function (_ shift) (is (-> Nat Nat) (nat.+ shift))) random.nat) ... I64s get compiled as JavaScript objects with a specific structure. object random.nat] (<| (_.covering /._) (`` (all _.and (,, (with_template [ ] [(_.coverage [] (exec (is ) true))] [/.Boolean boolean] [/.Number number] [/.String string] )) (_.for [/.Object] (all _.and (,, (with_template [] [(_.coverage [] (exec (is (Ex (_ a) (/.Object a)) (is (as_expected []))) true))] [/.Function] [/.Symbol] [/.Null] [/.Undefined] )) )) (_.coverage [/.null] (exec (is Nat (/.null [])) (is Text (/.null [])) (is (All (_ a) (-> a a)) (/.null [])) true)) (_.coverage [/.null?] (and (/.null? (/.null [])) (not (/.null? 0)) (not (/.null? "0")) (not (/.null? (|>>))))) (_.coverage [/.global] (|> (/.global /.Function [parseFloat]) "js object null?" not)) (_.coverage [/.function] (|> (/.function (_ [input/0 Nat]) Int (.int input/0)) "js object null?" not)) (_.coverage [/.on_browser? /.on_node_js? /.on_nashorn?] (and (or /.on_nashorn? /.on_node_js? /.on_browser?) (bit#= /.on_nashorn? (not (or /.on_node_js? /.on_browser?))) (bit#= /.on_node_js? (not (or /.on_nashorn? /.on_browser?))) (bit#= /.on_browser? (not (or /.on_nashorn? /.on_node_js?))))) (_.coverage [/.type_of] (and (text#= "boolean" (/.type_of boolean)) (text#= "number" (/.type_of number)) (text#= "string" (/.type_of string)) (text#= "function" (/.type_of function)) (text#= "object" (/.type_of object)))) (_.coverage [/.import] (let [encoding "utf8"] (text#= string (cond /.on_nashorn? (let [binary (java/lang/String::getBytes encoding (as java/lang/String string))] (|> (java/lang/String::new binary encoding) (as Text))) /.on_node_js? (|> (Buffer::from string encoding) (Buffer::toString encoding)) ... On the browser (let [binary (|> (TextEncoder::new encoding) (TextEncoder::encode string))] (|> (TextDecoder::new encoding) (TextDecoder::decode binary))) )))) (_.coverage [/.undefined /.undefined?] (and (not (/.undefined? number)) (/.undefined? (/.undefined)))) (_.coverage [/.object] (let [it (/.object "my_boolean" boolean "my_number" number "my_string" string "my_function" function "my_object" object "my_undefined" (/.undefined))] (and (same? boolean ("js object get" "my_boolean" it)) (same? number ("js object get" "my_number" it)) (same? string ("js object get" "my_string" it)) (same? function ("js object get" "my_function" it)) (same? object ("js object get" "my_object" it)) (same? (/.undefined) ("js object get" "my_undefined" it)) (/.undefined? ("js object get" "my_yolo" it))))) $/export.test )))))