diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test.lux (renamed from stdlib/test/tests.lux) | 2 | ||||
-rw-r--r-- | stdlib/test/test/lux/cli.lux | 5 | ||||
-rw-r--r-- | stdlib/test/test/lux/host.jvm.lux | 88 | ||||
-rw-r--r-- | stdlib/test/test/lux/host/jvm.jvm.lux | 55 |
4 files changed, 80 insertions, 70 deletions
diff --git a/stdlib/test/tests.lux b/stdlib/test/test.lux index 5c7838634..53efb1c05 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/test.lux @@ -81,7 +81,7 @@ ## ["._interpreter" type]] ] ## TODO: Must have 100% coverage on tests. - [test + [/ ["/." lux ## [io (#+)] ## [time diff --git a/stdlib/test/test/lux/cli.lux b/stdlib/test/test/lux/cli.lux index bf7bc72a7..7c50a679b 100644 --- a/stdlib/test/test/lux/cli.lux +++ b/stdlib/test/test/lux/cli.lux @@ -13,8 +13,9 @@ ["." list]]] [math ["r" random]] - ["/" cli] - ["_" test (#+ Test)]]) + ["_" test (#+ Test)]] + {[-1 ""] + ["." /]}) (def: #export test Test diff --git a/stdlib/test/test/lux/host.jvm.lux b/stdlib/test/test/lux/host.jvm.lux index c3dcf6791..f1151f010 100644 --- a/stdlib/test/test/lux/host.jvm.lux +++ b/stdlib/test/test/lux/host.jvm.lux @@ -5,10 +5,11 @@ pipe] [data [text ("text/." Equivalence<Text>)]] - ["&" host (#+ import: class: interface: object)] [math ["r" random]] - ["_" test (#+ Test)]]) + ["_" test (#+ Test)]] + {[-1 ""] + ["." / (#+ import: class: interface: object)]}) (import: (java/util/concurrent/Callable a)) @@ -58,7 +59,8 @@ (interface: TestInterface ([] foo [boolean String] void #throws [Exception])) -(def: conversions Test +(def: conversions + Test (do r.Monad<Random> [sample r.int] (`` ($_ _.and @@ -68,55 +70,59 @@ (let [capped-sample (|> sample <to> <from>)] (|> capped-sample <to> <from> (i/= 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."] + [/.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."] )) )))) -(def: miscellaneous Test - ($_ _.and - (_.test "Can check if an object is of a certain class." - (and (case (&.check String "") (#.Some _) true #.None false) - (case (&.check Long "") (#.Some _) false #.None true) - (case (&.check Object "") (#.Some _) true #.None false) - (case (&.check Object (&.null)) (#.Some _) false #.None true))) - - (_.test "Can run code in a 'synchronized' block." - (&.synchronized "" #1)) - - (_.test "Can access Class instances." - (text/= "java.lang.Class" (Class::getName (&.class-for java/lang/Class)))) - - (_.test "Can check if a value is null." - (and (&.null? (&.null)) - (not (&.null? "")))) - - (_.test "Can safely convert nullable references into Maybe values." - (and (|> (: (Maybe Object) (&.??? (&.null))) - (case> #.None #1 - _ #0)) - (|> (: (Maybe Object) (&.??? "")) - (case> (#.Some _) #1 - _ #0)))) - )) - -(def: arrays Test +(def: miscellaneous + Test + (do r.Monad<Random> + [sample (r.ascii 1)] + ($_ _.and + (_.test "Can check if an object is of a certain class." + (and (case (/.check String sample) (#.Some _) true #.None false) + (case (/.check Long sample) (#.Some _) false #.None true) + (case (/.check Object sample) (#.Some _) true #.None false) + (case (/.check 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" (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 Object) (/.??? (/.null))) + (case> #.None #1 + _ #0)) + (|> (: (Maybe Object) (/.??? sample)) + (case> (#.Some _) #1 + _ #0)))) + ))) + +(def: arrays + Test (do r.Monad<Random> [size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1)))) idx (|> r.nat (:: @ map (n/% size))) value r.int] ($_ _.and (_.test "Can create arrays of some length." - (n/= size (&.array-length (&.array Long size)))) + (n/= size (/.array-length (/.array Long size)))) (_.test "Can set and get array values." - (let [arr (&.array Long size)] - (exec (&.array-write idx value arr) - (i/= value (&.array-read idx arr)))))))) + (let [arr (/.array Long size)] + (exec (/.array-write idx value arr) + (i/= value (/.array-read idx arr)))))))) (def: #export test ($_ _.and diff --git a/stdlib/test/test/lux/host/jvm.jvm.lux b/stdlib/test/test/lux/host/jvm.jvm.lux index caa3efd1f..bacfd480b 100644 --- a/stdlib/test/test/lux/host/jvm.jvm.lux +++ b/stdlib/test/test/lux/host/jvm.jvm.lux @@ -17,19 +17,19 @@ [world ["." file (#+ File)] [binary (#+ Binary)]] - [host - [jvm - ["/." loader (#+ Library)] - ["/." version] - ["/." name] - ["/." descriptor] - ["/." field] - ["/." class] - [modifier - ["/.M" inner]]]] [math ["r" random]] - ["_" test (#+ Test)]]) + ["_" test (#+ Test)]] + {[-1 ""] + [/ + ["/." loader (#+ Library)] + ["/." version] + ["/." name] + ["/." descriptor] + ["/." field] + ["/." class] + [modifier + ["/.M" inner]]]}) (def: (write-class! name bytecode) (-> Text Binary (IO Text)) @@ -46,21 +46,24 @@ (#error.Failure error) error))))) -(def: class Test - (let [package "my.package" - name "MyClass" - full-name (format package "." name) - input (/class.class /version.v6_0 /class.public - (/name.internal "java.lang.Object") - (/name.internal full-name) - (list (/name.internal "java.io.Serializable") - (/name.internal "java.lang.Runnable")) - (list (/field.field /field.public "foo" /descriptor.long (row.row)) - (/field.field /field.public "bar" /descriptor.double (row.row))) - (row.row) - (row.row)) - bytecode (binary.write /class.format input) - loader (/loader.memory (/loader.new-library []))] +(def: class + Test + (do r.Monad<Random> + [_ (wrap []) + #let [package "my.package" + name "MyClass" + full-name (format package "." name) + input (/class.class /version.v6_0 /class.public + (/name.internal "java.lang.Object") + (/name.internal full-name) + (list (/name.internal "java.io.Serializable") + (/name.internal "java.lang.Runnable")) + (list (/field.field /field.public "foo" /descriptor.long (row.row)) + (/field.field /field.public "bar" /descriptor.double (row.row))) + (row.row) + (row.row)) + bytecode (binary.write /class.format input) + loader (/loader.memory (/loader.new-library []))]] ($_ _.and (_.test "Can read a generated class." (case (binary.read /class.format bytecode) |