diff options
author | Eduardo Julian | 2021-05-24 19:29:13 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-05-24 19:29:13 -0400 |
commit | da27db478b368724ee4659eb674dcdbeb2cd8747 (patch) | |
tree | c1c5ef50644fa78ea899ac8c0afa1e234cd03b26 /stdlib/source/test/lux/ffi.old.lux | |
parent | 1ffd2dd7e37d3be90522dfe768226334f60577f5 (diff) |
Re-named lux/host to lux/ffi.
Diffstat (limited to 'stdlib/source/test/lux/ffi.old.lux')
-rw-r--r-- | stdlib/source/test/lux/ffi.old.lux | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/ffi.old.lux b/stdlib/source/test/lux/ffi.old.lux new file mode 100644 index 000000000..b14dac30d --- /dev/null +++ b/stdlib/source/test/lux/ffi.old.lux @@ -0,0 +1,145 @@ +(.module: + [lux #* + [abstract/monad (#+ Monad do)] + [control + pipe] + [data + ["." text ("#\." equivalence)]] + [math + ["r" random] + [number + ["n" nat] + ["i" int]]] + ["_" test (#+ Test)]] + {1 + ["." / (#+ import: class: interface: object)]}) + +(import: (java/util/concurrent/Callable a)) + +(import: java/lang/Object) +(import: java/lang/String) + +(import: java/lang/Exception + ["#::." + (new [java/lang/String])]) + +(import: java/lang/Runnable) + +(import: (java/lang/Class a) + ["#::." + (getName [] java/lang/String)]) + +(import: java/lang/System + ["#::." + (#static out java/io/PrintStream) + (#static currentTimeMillis [] #io long) + (#static getenv [java/lang/String] #io #? java/lang/String)]) + +(class: #final (TestClass A) [java/lang/Runnable] + ## Fields + (#private foo boolean) + (#private bar A) + (#private baz java/lang/Object) + ## Methods + (#public [] (new {value A}) [] + (exec (:= ::foo #1) + (:= ::bar value) + (:= ::baz "") + [])) + (#public (virtual self) java/lang/Object + "") + (#public #static (static) java/lang/Object + "") + (java/lang/Runnable [] (run self) void + [])) + +(def: test_runnable + (object [] [java/lang/Runnable] + [] + (java/lang/Runnable [] (run self) void + []))) + +(def: test_callable + (object [a] [(java/util/concurrent/Callable a)] + [] + (java/util/concurrent/Callable [] (call self) a + (undefined)))) + +(interface: TestInterface + ([] foo [boolean java/lang/String] void #throws [java/lang/Exception])) + +(def: conversions + Test + (do r.monad + [sample r.int] + (`` ($_ _.and + (~~ (template [<to> <from> <message>] + [(_.test <message> + (or (|> sample <to> <from> (i.= sample)) + (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."] + )) + )))) + +(def: miscellaneous + Test + (do r.monad + [sample (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)))) + ))) + +(def: arrays + Test + (do {! r.monad} + [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 java/lang/Long size)))) + + (_.test "Can set and get array values." + (let [arr (/.array java/lang/Long size)] + (exec (/.array_write idx value arr) + (i.= value (/.array_read idx arr))))) + ))) + +(def: #export test + ($_ _.and + (<| (_.context "Conversions.") + ..conversions) + (<| (_.context "Miscellaneous.") + ..miscellaneous) + (<| (_.context "Arrays.") + ..arrays) + )) |