aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux.lux80
-rw-r--r--stdlib/source/test/lux/ffi.jvm.lux239
2 files changed, 241 insertions, 78 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index cbc63d90d..20d21d74d 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -93,40 +93,6 @@
value)))))
))
-(template: (quadrance cat0 cat1)
- (n.+ (n.* cat0 cat0) (n.* cat1 cat1)))
-
-(def: templates
- Test
- (do random.monad
- [cat0 random.nat
- cat1 random.nat]
- (_.test "Template application is a stand-in for the templated code."
- (n.= (n.+ (n.* cat0 cat0) (n.* cat1 cat1))
- (quadrance cat0 cat1)))))
-
-(def: cross_platform_support
- Test
- (do random.monad
- [on_default random.nat
- on_fake_host random.nat
- on_valid_host random.nat]
- ($_ _.and
- (_.test "Can provide default in case there is no particular host/platform support."
- (n.= on_default
- (for {"" on_fake_host}
- on_default)))
- (_.test "Can pick code depending on the host/platform being targeted."
- (n.= on_valid_host
- (for {@.old on_valid_host
- @.jvm on_valid_host
- @.js on_valid_host
- @.python on_valid_host
- @.lua on_valid_host
- @.ruby on_valid_host
- @.php on_valid_host}
- on_default))))))
-
(def: sub_tests
Test
(with_expansions [## TODO: Update & expand tests for this
@@ -732,6 +698,47 @@
(not (code\= (' <left_association>)
(' <right_association>))))))))
+(def: for_expansion
+ Test
+ (do random.monad
+ [left random.nat
+ right random.nat
+ dummy random.nat
+ #let [expected (n.+ left right)]]
+ ($_ _.and
+ (_.cover [/.as_is]
+ (`` (and (~~ (as_is true
+ true
+ true)))))
+ (_.cover [/.with_expansions]
+ (/.with_expansions [<operands> (as_is left right)]
+ (n.= expected
+ (n.+ <operands>))))
+ (_.cover [/.comment]
+ (/.with_expansions [<dummy> (/.comment dummy)
+ <operands> (as_is left right)]
+ (n.= expected
+ ($_ n.+ <operands> <dummy>))))
+ (_.cover [/.``]
+ (n.= expected
+ (/.`` ($_ n.+
+ (~~ (as_is left right))
+ (~~ (/.comment dummy))))))
+ (_.cover [/.for]
+ (and (n.= expected
+ (/.for {"fake host" dummy}
+ expected))
+ (n.= expected
+ (/.for {@.old expected
+ @.jvm expected
+ @.js expected
+ @.python expected
+ @.lua expected
+ @.ruby expected
+ @.php expected}
+ dummy))))
+ )))
+
(def: test
Test
(<| (_.covering /._)
@@ -740,10 +747,6 @@
..identity)
(<| (_.context "Prelude macros.")
..prelude_macros)
- (<| (_.context "Templates.")
- ..templates)
- (<| (_.context "Cross-platform support.")
- ..cross_platform_support)
..for_bit
..for_try
@@ -760,6 +763,7 @@
..for_static
..for_slot
..for_associative
+ ..for_expansion
..sub_tests
)))
diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux
index e8e07e7e1..b0ae4fc0f 100644
--- a/stdlib/source/test/lux/ffi.jvm.lux
+++ b/stdlib/source/test/lux/ffi.jvm.lux
@@ -38,25 +38,6 @@
["#::."
(getName [] java/lang/String)])
-## TODO: Handle "/.class:" ASAP.
-## (/.class: #final (TestClass A) [java/lang/Runnable]
-## ## Fields
-## (#private foo boolean)
-## (#private bar A)
-## (#private baz java/lang/Object)
-## ## Methods
-## (#public [] (new self {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
-## []))
-
(template [<name> <type> <conversion> <lux> <=>]
[(def: (<name> left right)
(-> <type> <type> Bit)
@@ -83,14 +64,16 @@
(#try.Failure error)
(#try.Success [lux (list (code.text error))])))))
-(def: conversions
+(def: for_conversions
Test
(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)]
+ float (|> random.frac
+ (random.filter (|>> f.not_a_number? not))
+ (\ ! map (|>> (:as /.Double) /.double_to_float)))]
(`` ($_ _.and
(~~ (template [<sample> <=> <to> <from>]
[(_.cover [<to> <from>]
@@ -116,7 +99,7 @@
[float float\= /.float_to_double /.double_to_float]
))))))
-(def: arrays
+(def: for_arrays
Test
(do {! random.monad}
[size (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1))))
@@ -142,7 +125,7 @@
..macro_error
(text.contains? (get@ #exception.label /.cannot_convert_to_jvm_type))))))))
-(def: miscellaneous
+(def: for_miscellaneous
Test
(`` (do {! random.monad}
[sample (\ ! map (|>> (:as java/lang/Object))
@@ -152,8 +135,12 @@
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)
+ float (|> random.frac
+ (random.filter (|>> f.not_a_number? not))
+ (\ ! map (|>> (:as /.Double) /.double_to_float)))
+ double (|> random.frac
+ (random.filter (|>> f.not_a_number? not))
+ (\ ! map (|>> (:as /.Double))))
character (\ ! map (|>> (:as /.Long) /.long_to_int /.int_to_char) random.int)
string (\ ! map (|>> (:as java/lang/String))
(random.ascii 1))]
@@ -260,7 +247,8 @@
["#::."
(actual3 [] a)])
-(def: interface
+(def: for_interface
+ Test
(do random.monad
[expected random.nat
#let [object/0 (/.object [] [test/TestInterface0]
@@ -270,6 +258,10 @@
java/lang/Long
(:as java/lang/Long
expected)))
+ example/0!
+ (is? (: Any expected)
+ (: Any (test/TestInterface0::actual0 object/0)))
+
object/1 (/.object [] [test/TestInterface1]
[]
(test/TestInterface1
@@ -280,12 +272,31 @@
(error! "YOLO")
(:as java/lang/Long
expected))))
+ example/1!
+ (and (case (test/TestInterface1::actual1 false object/1)
+ (#try.Success actual)
+ (is? (: Any expected)
+ (: Any actual))
+
+ (#try.Failure error)
+ false)
+ (case (test/TestInterface1::actual1 true object/1)
+ (#try.Success actual)
+ false
+
+ (#try.Failure error)
+ true))
+
object/2 (/.object [] [test/TestInterface2]
[]
(test/TestInterface2
[a] (actual2 self {input a})
a
input))
+ example/2!
+ (is? (: Any expected)
+ (: Any (test/TestInterface2::actual2 (:as java/lang/Long expected) object/2)))
+
object/3 (/.object [] [(test/TestInterface3 java/lang/Long)]
[]
((test/TestInterface3 a)
@@ -293,16 +304,143 @@
a
(:as java/lang/Long
expected)))
+ example/3!
+ (is? (: Any expected)
+ (: Any (test/TestInterface3::actual3 object/3)))]]
+ (_.cover [/.interface: /.object]
+ (and example/0!
+ example/1!
+ example/2!
+ example/3!))))
+
+(/.class: #final test/TestClass0 [test/TestInterface0]
+ ## Fields
+ (#private value java/lang/Long)
+ ## Constructors
+ (#public [] (new self {value java/lang/Long}) []
+ (:= ::value value))
+ ## Methods
+ (test/TestInterface0 [] (actual0 self) java/lang/Long
+ ::value))
+
+(/.import: test/TestClass0
+ ["#::."
+ (new [java/lang/Long])])
+
+(/.class: #final test/TestClass1 [test/TestInterface1]
+ ## Fields
+ (#private value java/lang/Long)
+ ## Constructors
+ (#public [] (new self {value java/lang/Long}) []
+ (:= ::value value))
+ ## Methods
+ (test/TestInterface1 [] (actual1 self {throw? java/lang/Boolean}) java/lang/Long #throws [java/lang/Throwable]
+ (if (:as Bit throw?)
+ (error! "YOLO")
+ ::value)))
+
+(/.import: test/TestClass1
+ ["#::."
+ (new [java/lang/Long])])
+
+(/.class: #final test/TestClass2 [test/TestInterface2]
+ ## Constructors
+ (#public [] (new self) []
+ [])
+ ## Methods
+ (test/TestInterface2
+ [a] (actual2 self {input a})
+ a
+ input))
+
+(/.import: test/TestClass2
+ ["#::."
+ (new [])])
+
+(/.class: #final (test/TestClass3 a) [(test/TestInterface3 a)]
+ ## Fields
+ (#private value a)
+ ## Constructors
+ (#public [] (new self {value a}) []
+ (:= ::value value))
+ ## Methods
+ ((test/TestInterface3 a)
+ [] (actual3 self)
+ a
+ ::value))
+
+(/.import: (test/TestClass3 a)
+ ["#::."
+ (new [a])])
+
+(/.class: #final test/TestClass4 []
+ ## Constructors
+ (#public [] (new self) []
+ [])
+ ## Methods
+ (#public (actual4 self {value java/lang/Long}) java/lang/Long
+ value))
+
+(/.import: test/TestClass4
+ ["#::."
+ (new [])
+ (actual4 [java/lang/Long] java/lang/Long)])
+
+(/.class: #final test/TestClass5 []
+ ## Constructors
+ (#public [] (new self) []
+ [])
+ ## Methods
+ (#public #static (actual5 {value java/lang/Long})
+ java/lang/Long
+ value))
+
+(/.import: test/TestClass5
+ ["#::."
+ (#static actual5 [java/lang/Long] java/lang/Long)])
+
+(/.class: #abstract test/TestClass6 []
+ ## Constructors
+ (#public [] (new self) []
+ [])
+ ## Methods
+ (#public #abstract (actual6 {value java/lang/Long})
+ java/lang/Long))
+
+(/.import: test/TestClass6
+ ["#::."
+ (actual6 [java/lang/Long] java/lang/Long)])
+(/.class: #final test/TestClass7 test/TestClass6 []
+ ## Constructors
+ (#public [] (new self) []
+ [])
+ ## Methods
+ (test/TestClass6
+ [] (actual6 self {input java/lang/Long})
+ java/lang/Long
+ input))
+
+(/.import: test/TestClass7
+ ["#::."
+ (new [])])
+
+(def: for_class
+ Test
+ (do random.monad
+ [expected random.nat
+
+ #let [object/0 (test/TestClass0::new (.int expected))
example/0!
- (is? (: Any expected)
- (: Any (test/TestInterface0::actual0 object/0)))
+ (n.= expected
+ (:as Nat (test/TestInterface0::actual0 object/0)))
+ object/1 (test/TestClass1::new (.int expected))
example/1!
(and (case (test/TestInterface1::actual1 false object/1)
(#try.Success actual)
- (is? (: Any expected)
- (: Any actual))
+ (n.= expected
+ (:as Nat actual))
(#try.Failure error)
false)
@@ -313,24 +451,45 @@
(#try.Failure error)
true))
+ object/2 (test/TestClass2::new)
example/2!
- (is? (: Any expected)
- (: Any (test/TestInterface2::actual2 (:as /.Long expected) object/2)))
+ (n.= expected
+ (: Nat (test/TestInterface2::actual2 (:as java/lang/Long expected) object/2)))
+ object/3 (: (test/TestClass3 java/lang/Long)
+ (test/TestClass3::new (:as java/lang/Long expected)))
example/3!
- (is? (: Any expected)
- (: Any (test/TestInterface3::actual3 object/3)))]]
- (_.cover [/.interface:]
+ (n.= expected
+ (: Nat (test/TestInterface3::actual3 object/3)))
+
+ object/4 (test/TestClass4::new)
+ example/4!
+ (n.= expected
+ (.nat (test/TestClass4::actual4 (.int expected) object/4)))
+
+ example/5!
+ (n.= expected
+ (.nat (test/TestClass5::actual5 (.int expected))))
+
+ object/7 (test/TestClass7::new)
+ example/7!
+ (n.= expected
+ (.nat (test/TestClass6::actual6 (.int expected) object/7)))]]
+ (_.cover [/.class: /.import:]
(and example/0!
example/1!
example/2!
- example/3!))))
+ example/3!
+ example/4!
+ example/5!
+ example/7!))))
(def: #export test
(<| (_.covering /._)
($_ _.and
- ..conversions
- ..arrays
- ..miscellaneous
- ..interface
+ ..for_conversions
+ ..for_arrays
+ ..for_miscellaneous
+ ..for_interface
+ ..for_class
)))