diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/aedifex/command/auto.lux | 13 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/profile.lux | 6 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/runtime.lux | 51 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/text/format.lux | 14 | ||||
-rw-r--r-- | stdlib/source/test/lux/ffi.jvm.lux | 258 | ||||
-rw-r--r-- | stdlib/source/test/lux/time/date.lux | 7 |
6 files changed, 262 insertions, 87 deletions
diff --git a/stdlib/source/test/aedifex/command/auto.lux b/stdlib/source/test/aedifex/command/auto.lux index dfb4dc672..193a5b8d8 100644 --- a/stdlib/source/test/aedifex/command/auto.lux +++ b/stdlib/source/test/aedifex/command/auto.lux @@ -27,7 +27,7 @@ ["." instant]] [world [console (#+ Console)] - ["." shell (#+ Shell)] + ["." shell (#+ Exit Shell)] ["." program (#+ Program)] ["." file ["." watch]]]] @@ -46,7 +46,7 @@ (def: (command expected_runs end_signal fs dummy_file) (-> Nat Text (file.System Promise) file.Path [(Atom Nat) - (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any))]) + (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit Any]))]) (let [@runs (: (Atom Nat) (atom.atom 0))] [@runs @@ -56,10 +56,11 @@ (if (n.= expected_runs actual_runs) (wrap (#try.Failure end_signal)) (do (try.with !) - [_ (\ fs write (\ utf8.codec encode (%.nat actual_runs)) dummy_file)] - (\ fs modify - (|> actual_runs .int instant.from_millis) - dummy_file)))))])) + [_ (\ fs write (\ utf8.codec encode (%.nat actual_runs)) dummy_file) + _ (\ fs modify + (|> actual_runs .int instant.from_millis) + dummy_file)] + (wrap [shell.normal []])))))])) (def: #export test Test diff --git a/stdlib/source/test/aedifex/profile.lux b/stdlib/source/test/aedifex/profile.lux index d4cbb958a..e7e3f50ac 100644 --- a/stdlib/source/test/aedifex/profile.lux +++ b/stdlib/source/test/aedifex/profile.lux @@ -27,6 +27,7 @@ [\\program ["." / ["/#" // #_ + ["#." runtime] ["#." dependency (#+ Dependency)] ["#." format] [repository @@ -129,6 +130,11 @@ (random.maybe (random.ascii/alpha 1)) (random.maybe (random.ascii/alpha 1)) (..dictionary_of text.hash (random.ascii/alpha 1) ..repository) + (random\wrap //runtime.default_java) + (random\wrap //runtime.default_js) + (random\wrap //runtime.default_python) + (random\wrap //runtime.default_lua) + (random\wrap //runtime.default_ruby) )) (def: #export test diff --git a/stdlib/source/test/aedifex/runtime.lux b/stdlib/source/test/aedifex/runtime.lux index 968e753f8..e75a9297e 100644 --- a/stdlib/source/test/aedifex/runtime.lux +++ b/stdlib/source/test/aedifex/runtime.lux @@ -4,26 +4,57 @@ [abstract [monad (#+ do)]] [data - ["." text]] + ["." maybe ("#\." functor)] + ["." text ("#\." equivalence)] + [collection + ["." list ("#\." functor)] + ["." set]]] [math - ["." random]]] + ["." random (#+ Random) ("#\." monad)] + [number + ["n" nat]]]] [\\program ["." /]]) +(def: #export random + (Random /.Runtime) + ($_ random.either + (random\wrap /.default_java) + (random\wrap /.default_js) + (random\wrap /.default_python) + (random\wrap /.default_lua) + (random\wrap /.default_ruby) + )) + (def: #export test Test (<| (_.covering /._) + (_.for [/.Runtime]) (do random.monad - [path (random.ascii/alpha 5)] + [path (random.ascii/alpha 5) + runtime ..random] (`` ($_ _.and (~~ (template [<command>] - [(_.cover [<command>] - (let [command (text.join_with " " (#.Cons (<command> path))) - pure_command (text.join_with " " (#.Cons (<command> "")))] - (and (text.starts_with? pure_command command) - (text.ends_with? path command))))] + [(_.cover [/.default_java /.default_js /.default_python /.default_lua /.default_ruby] + (let [listing (|> (list /.default_java /.default_js /.default_python /.default_lua /.default_ruby) + (list\map (get@ #/.program))) + unique (set.from_list text.hash listing)] + (n.= (list.size listing) + (set.size unique))))] - [/.java] - [/.node] + [/.default_java] + [/.default_js] + [/.default_python] + [/.default_lua] + [/.default_ruby] )) + (_.cover [/.for] + (let [runtime' (/.for runtime path)] + (and (text\= (get@ #/.program runtime) + (get@ #/.program runtime')) + (|> runtime' + (get@ #/.parameters) + list.last + (maybe\map (text\= path)) + (maybe.default false))))) ))))) diff --git a/stdlib/source/test/lux/data/text/format.lux b/stdlib/source/test/lux/data/text/format.lux index db1615631..54176cda3 100644 --- a/stdlib/source/test/lux/data/text/format.lux +++ b/stdlib/source/test/lux/data/text/format.lux @@ -19,6 +19,8 @@ [collection ["." list ("#\." functor)]]] ["." time + ["." day] + ["." month] ["." instant] ["." duration] ["." date]] @@ -102,6 +104,8 @@ [/.name name.codec ($///name.random 5 5)] [/.xml xml.codec $///xml.random] [/.json json.codec $///json.random] + [/.day day.codec random.day] + [/.month month.codec random.month] [/.instant instant.codec random.instant] [/.duration duration.codec random.duration] [/.date date.codec random.date] @@ -152,6 +156,16 @@ (text.join_with " ") list (/.list (|>>)))))) + (do random.monad + [sample (random.maybe random.nat)] + (_.cover [/.maybe] + (case sample + #.None + true + + (#.Some value) + (text.contains? (/.nat value) + (/.maybe /.nat sample))))) (do {! random.monad} [modulus (random.one (|>> modulus.modulus try.to_maybe) diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux index 86e43a9f3..7baa32fa2 100644 --- a/stdlib/source/test/lux/ffi.jvm.lux +++ b/stdlib/source/test/lux/ffi.jvm.lux @@ -1,16 +1,28 @@ (.module: [lux #* - [abstract/monad (#+ Monad do)] + ["_" test (#+ Test)] + ["." type ("#\." equivalence)] + ["." meta] + [abstract + [monad (#+ do)]] [control - pipe] + [pipe (#+ case>)] + ["." try] + ["." exception]] [data - ["." text ("#\." equivalence)]] + ["." bit ("#\." equivalence)] + ["." text ("#\." equivalence)] + [collection + ["." array (#+ Array)]]] + ["." macro + [syntax (#+ syntax:)] + ["." code]] [math - ["r" random] + ["." random] [number ["n" nat] - ["i" int]]] - ["_" test (#+ Test)]] + ["i" int ("#\." equivalence)] + ["f" frac ("#\." equivalence)]]]] [\\ ["." /]]) @@ -74,78 +86,184 @@ ## (/.interface: TestInterface ## ([] foo [boolean java/lang/String] void #throws [java/lang/Exception])) +(template [<name> <type> <conversion> <lux> <=>] + [(def: (<name> left right) + (-> <type> <type> Bit) + (<=> (:as <lux> (<conversion> left)) + (:as <lux> (<conversion> right))))] + + [boolean\= /.Boolean <| Bit bit\=] + [byte\= /.Byte /.byte_to_long Int i\=] + [short\= /.Short /.short_to_long Int i\=] + [integer\= /.Integer /.int_to_long Int i\=] + [long\= /.Long <| Int i\=] + [float\= /.Float /.float_to_double Frac f\=] + [double\= /.Double <| Frac f\=] + [character\= /.Character /.char_to_long Int i\=] + ) + +(syntax: (macro_error expression) + (function (_ lux) + (|> (macro.expand_once expression) + (meta.run lux) + (case> (#try.Success expansion) + (#try.Failure "OOPS!") + + (#try.Failure error) + (#try.Success [lux (list (code.text error))]))))) + (def: conversions Test - (do r.monad - [sample r.int] + (do {! random.monad} + [long (\ ! map (|>> (:as /.Long)) random.int) + integer (\ ! map (|>> (:as /.Long) /.long_to_int) random.int) + byte (\ ! map (|>> (:as /.Long) /.long_to_byte) random.int) + short (\ ! map (|>> (:as /.Long) /.long_to_short) random.int) + float (\ ! map (|>> (:as /.Double) /.double_to_float) random.frac)] (`` ($_ _.and - (~~ (template [<to> <from> <message>] - [(_.test <message> - (or (|> sample (:as java/lang/Long) <to> <from> (:as Int) (i.= sample)) - (let [capped_sample (|> sample (:as java/lang/Long) <to> <from>)] - (|> capped_sample <to> <from> (:as Int) (i.= (:as Int capped_sample))))))] - - [/.long_to_byte /.byte_to_long "Can succesfully convert to/from byte."] - [/.long_to_short /.short_to_long "Can succesfully convert to/from short."] - [/.long_to_int /.int_to_long "Can succesfully convert to/from int."] - [/.long_to_float /.float_to_long "Can succesfully convert to/from float."] - [/.long_to_double /.double_to_long "Can succesfully convert to/from double."] - [(<| /.int_to_char /.long_to_int) (<| /.int_to_long /.char_to_int) "Can succesfully convert to/from char."] - )) - )))) + (~~ (template [<sample> <=> <to> <from>] + [(_.cover [<to> <from>] + (or (|> <sample> <to> <from> (<=> <sample>)) + (let [capped (|> <sample> <to> <from>)] + (|> capped <to> <from> (<=> capped)))))] -(def: miscellaneous - Test - (do {! r.monad} - [sample (\ ! map (|>> (:as java/lang/Object)) - (r.ascii 1))] - ($_ _.and - (_.test "Can check if an object is of a certain class." - (and (case (/.check java/lang/String sample) (#.Some _) true #.None false) - (case (/.check java/lang/Long sample) (#.Some _) false #.None true) - (case (/.check java/lang/Object sample) (#.Some _) true #.None false) - (case (/.check java/lang/Object (/.null)) (#.Some _) false #.None true))) - - (_.test "Can run code in a 'synchronized' block." - (/.synchronized sample #1)) - - (_.test "Can access Class instances." - (text\= "java.lang.Class" (java/lang/Class::getName (/.class_for java/lang/Class)))) - - (_.test "Can check if a value is null." - (and (/.null? (/.null)) - (not (/.null? sample)))) - - (_.test "Can safely convert nullable references into Maybe values." - (and (|> (: (Maybe java/lang/Object) (/.??? (/.null))) - (case> #.None #1 - _ #0)) - (|> (: (Maybe java/lang/Object) (/.??? sample)) - (case> (#.Some _) #1 - _ #0)))) - ))) + [long long\= /.long_to_byte /.byte_to_long] + [long long\= /.long_to_short /.short_to_long] + [long long\= /.long_to_int /.int_to_long] + [long long\= /.long_to_float /.float_to_long] + [long long\= /.long_to_double /.double_to_long] + [long long\= /.long_to_char /.char_to_long] + + [integer integer\= /.int_to_double /.double_to_int] + [integer integer\= /.int_to_float /.float_to_int] + [integer integer\= /.int_to_char /.char_to_int] + + [byte byte\= /.byte_to_int /.int_to_byte] + [short short\= /.short_to_int /.int_to_short] + [byte byte\= /.byte_to_char /.char_to_byte] + [short short\= /.short_to_char /.char_to_short] + [float float\= /.float_to_double /.double_to_float] + )))))) (def: arrays Test - (do {! r.monad} - [size (|> r.nat (\ ! map (|>> (n.% 100) (n.max 1)))) - idx (|> r.nat (\ ! map (n.% size))) - value (\ ! map (|>> (:as java/lang/Long)) r.int)] + (do {! random.monad} + [size (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1)))) + idx (|> random.nat (\ ! map (n.% size))) + value (\ ! map (|>> (:as java/lang/Long)) random.int)] ($_ _.and - (_.test "Can create arrays of some length." - (n.= size (/.array_length (/.array java/lang/Long size)))) + (_.cover [/.array /.array_length] + (|> size + (/.array java/lang/Long) + /.array_length + (n.= size))) + (_.cover [/.array_write /.array_read] + (|> (/.array java/lang/Long size) + (/.array_write idx value) + (/.array_read idx) + (:as Int) + (i.= (:as Int value)))) + (_.cover [/.cannot_convert_to_jvm_type] + (let [array (:as (Array Nothing) + (array.new 1))] + (|> array + /.array_length + ..macro_error + (text.contains? (get@ #exception.label /.cannot_convert_to_jvm_type)))))))) - (_.test "Can set and get array values." - (let [arr (/.array java/lang/Long size)] - (exec (/.array_write idx value arr) - (i.= (:as Int value) - (:as Int (/.array_read idx arr))))))))) +(def: miscellaneous + Test + (`` (do {! random.monad} + [sample (\ ! map (|>> (:as java/lang/Object)) + (random.ascii 1)) + boolean (\ ! map (|>> (:as /.Boolean)) random.bit) + byte (\ ! map (|>> (:as /.Long) /.long_to_byte) random.int) + short (\ ! map (|>> (:as /.Long) /.long_to_short) random.int) + integer (\ ! map (|>> (:as /.Long) /.long_to_int) random.int) + long (\ ! map (|>> (:as /.Long)) random.int) + float (\ ! map (|>> (:as /.Double) /.double_to_float) random.frac) + double (\ ! map (|>> (:as /.Double)) random.frac) + character (\ ! map (|>> (:as /.Long) /.long_to_int /.int_to_char) random.int) + string (\ ! map (|>> (:as java/lang/String)) + (random.ascii 1))] + ($_ _.and + (_.cover [/.check] + (and (case (/.check java/lang/String sample) (#.Some _) true #.None false) + (case (/.check java/lang/Long sample) (#.Some _) false #.None true) + (case (/.check java/lang/Object sample) (#.Some _) true #.None false) + (case (/.check java/lang/Object (/.null)) (#.Some _) false #.None true))) + (_.cover [/.synchronized] + (/.synchronized sample #1)) + (_.cover [/.class_for] + (text\= "java.lang.Class" (java/lang/Class::getName (/.class_for java/lang/Class)))) + (_.cover [/.null /.null?] + (and (/.null? (/.null)) + (not (/.null? sample)))) + (_.cover [/.???] + (and (|> (/.??? (/.null)) + (: (Maybe java/lang/Object)) + (case> #.None #1 + (#.Some _) #0)) + (|> (/.??? sample) + (: (Maybe java/lang/Object)) + (case> (#.Some _) #1 + #.None #0)))) + (_.cover [/.!!!] + (and (|> (/.??? (/.null)) + /.!!! + /.null?) + (|> (/.??? sample) + /.!!! + /.null? + not))) + (~~ (template [<object> <primitive> <value> <=>] + [(|> <value> + (: <object>) + "jvm object cast" + (: <primitive>) + "jvm object cast" + (: <object>) + (<=> <value>) + (_.cover [<object> <primitive>]))] + + [/.Boolean /.boolean boolean boolean\=] + [/.Byte /.byte byte byte\=] + [/.Short /.short short short\=] + [/.Integer /.int integer integer\=] + [/.Long /.long long long\=] + [/.Float /.float float float\=] + [/.Double /.double double double\=] + [/.Character /.char character character\=] + )) + (_.cover [/.cannot_cast_to_non_object] + (text.contains? (get@ #exception.label /.cannot_cast_to_non_object) + (macro_error (/.:cast boolean (: /.Boolean boolean))))) + (_.cover [/.:cast] + (|> string + (/.:cast java/lang/Object) + (is? (:as java/lang/Object string)))) + (_.cover [/.type] + (and (and (type\= /.Boolean (/.type java/lang/Boolean)) + (type\= /.Boolean (/.type boolean))) + (and (type\= /.Byte (/.type java/lang/Byte)) + (type\= /.Byte (/.type byte))) + (and (type\= /.Short (/.type java/lang/Short)) + (type\= /.Short (/.type short))) + (and (type\= /.Integer (/.type java/lang/Integer)) + (type\= /.Integer (/.type int))) + (and (type\= /.Long (/.type java/lang/Long)) + (type\= /.Long (/.type long))) + (and (type\= /.Float (/.type java/lang/Float)) + (type\= /.Float (/.type float))) + (and (type\= /.Double (/.type java/lang/Double)) + (type\= /.Double (/.type double))) + (and (type\= /.Character (/.type java/lang/Character)) + (type\= /.Character (/.type char))))) + )))) (def: #export test - ($_ _.and - (<| (_.context "Conversions.") - ..conversions) - (<| (_.context "Miscellaneous.") - ..miscellaneous) - (<| (_.context "Arrays.") - ..arrays))) + (<| (_.covering /._) + ($_ _.and + ..conversions + ..arrays + ..miscellaneous))) diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux index b8813ba77..fdf78d535 100644 --- a/stdlib/source/test/lux/time/date.lux +++ b/stdlib/source/test/lux/time/date.lux @@ -19,7 +19,8 @@ [math ["." random (#+ Random)] [number - ["n" nat]]]] + ["n" nat] + ["i" int]]]] [\\ ["." /]]) @@ -63,6 +64,10 @@ /.to_days /.from_days (\ /.equivalence = expected)))) + (_.cover [/.epoch] + (|> /.epoch + /.to_days + (i.= +0))) (do random.monad [expected random.date] (_.cover [/.parser] |