aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2021-07-23 01:05:41 -0400
committerEduardo Julian2021-07-23 01:05:41 -0400
commit4248cc22881a7eaa8f74bc426f2b0ba284b23153 (patch)
treeb6730483b658a185901c2a7c871632d85a434b23 /stdlib/source/test
parent51a5c28b0f9efd514e3fae7c2634fd5e9bd714e2 (diff)
Automatically handling input/output conversions for methods in new JVM compiler.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux.lux79
-rw-r--r--stdlib/source/test/lux/ffi.jvm.lux56
2 files changed, 113 insertions, 22 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index 20d21d74d..fcf33fa79 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -61,22 +61,6 @@
[_ (wrap [])]
body)))
-(def: identity
- Test
- (do {! random.monad}
- [value random.nat
- #let [object (: (Random (Atom Nat))
- (\ ! map atom.atom (wrap value)))]
- self object]
- ($_ _.and
- (_.test "Every value is identical to itself."
- (is? self self))
- (do !
- [other object]
- (_.test "Values created separately can't be identical."
- (not (is? self other))))
- )))
-
(def: prelude_macros
Test
($_ _.and
@@ -739,12 +723,70 @@
dummy))))
)))
+(def: for_value
+ Test
+ (do random.monad
+ [left random.nat
+ right (random.ascii/lower 1)]
+ ($_ _.and
+ (_.cover [/.Either]
+ (and (exec
+ (: (/.Either Nat Text)
+ (#.Left left))
+ true)
+ (exec
+ (: (/.Either Nat Text)
+ (#.Right right))
+ true)))
+ (_.cover [/.Any]
+ (and (exec
+ (: /.Any
+ left)
+ true)
+ (exec
+ (: /.Any
+ right)
+ true)))
+ (_.cover [/.Nothing]
+ (and (exec
+ (: (-> /.Any /.Nothing)
+ (function (_ _)
+ (undefined)))
+ true)
+ (exec
+ (: (-> /.Any /.Int)
+ (function (_ _)
+ (: /.Int (undefined))))
+ true)))
+ (_.cover [/.All]
+ (let [identity (: (/.All [a] (-> a a))
+ (|>>))]
+ (and (exec
+ (: Nat
+ (identity left))
+ true)
+ (exec
+ (: Text
+ (identity right))
+ true))))
+ (_.cover [/.Ex]
+ (let [hide (: (/.Ex [a] (-> Nat a))
+ (|>>))]
+ (exec
+ (: /.Any
+ (hide left))
+ true)))
+ (_.cover [/.is?]
+ (let [not_left (|> left inc dec)]
+ (and (/.is? left left)
+ (and (n.= not_left left)
+ (not (/.is? not_left left))))))
+ )))
+
(def: test
Test
(<| (_.covering /._)
($_ _.and
- (<| (_.context "Identity.")
- ..identity)
(<| (_.context "Prelude macros.")
..prelude_macros)
@@ -764,6 +806,7 @@
..for_slot
..for_associative
..for_expansion
+ ..for_value
..sub_tests
)))
diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux
index b0ae4fc0f..1396e1646 100644
--- a/stdlib/source/test/lux/ffi.jvm.lux
+++ b/stdlib/source/test/lux/ffi.jvm.lux
@@ -247,10 +247,19 @@
["#::."
(actual3 [] a)])
+(/.interface: test/TestInterface4
+ ([] actual4 [long long long] long))
+
+(/.import: test/TestInterface4
+ ["#::."
+ (actual4 [long long long] long)])
+
(def: for_interface
Test
(do random.monad
[expected random.nat
+ left random.int
+ right random.int
#let [object/0 (/.object [] [test/TestInterface0]
[]
(test/TestInterface0
@@ -306,12 +315,26 @@
expected)))
example/3!
(is? (: Any expected)
- (: Any (test/TestInterface3::actual3 object/3)))]]
+ (: Any (test/TestInterface3::actual3 object/3)))
+
+ example/4!
+ (let [expected (i.+ left right)
+ object/4 (/.object [] [test/TestInterface4]
+ []
+ (test/TestInterface4
+ [] (actual4 self {actual_left long} {actual_right long} {_ long})
+ long
+ (:as java/lang/Long
+ (i.+ (:as Int actual_left)
+ (:as Int actual_right)))))]
+ (i.= expected
+ (test/TestInterface4::actual4 left right right object/4)))]]
(_.cover [/.interface: /.object]
(and example/0!
example/1!
example/2!
- example/3!))))
+ example/3!
+ example/4!))))
(/.class: #final test/TestClass0 [test/TestInterface0]
## Fields
@@ -425,10 +448,28 @@
["#::."
(new [])])
+(/.class: #final test/TestClass8 [test/TestInterface4]
+ ## Constructors
+ (#public [] (new self) []
+ [])
+ ## Methods
+ (test/TestInterface4
+ [] (actual4 self {actual_left long} {actual_right long} {_ long})
+ long
+ (:as java/lang/Long
+ (i.+ (:as Int actual_left)
+ (:as Int actual_right)))))
+
+(/.import: test/TestClass8
+ ["#::."
+ (new [])])
+
(def: for_class
Test
(do random.monad
[expected random.nat
+ left random.int
+ right random.int
#let [object/0 (test/TestClass0::new (.int expected))
example/0!
@@ -474,7 +515,13 @@
object/7 (test/TestClass7::new)
example/7!
(n.= expected
- (.nat (test/TestClass6::actual6 (.int expected) object/7)))]]
+ (.nat (test/TestClass6::actual6 (.int expected) object/7)))
+
+ example/8!
+ (let [expected (i.+ left right)
+ object/8 (test/TestClass8::new)]
+ (i.= expected
+ (test/TestInterface4::actual4 left right right object/8)))]]
(_.cover [/.class: /.import:]
(and example/0!
example/1!
@@ -482,7 +529,8 @@
example/3!
example/4!
example/5!
- example/7!))))
+ example/7!
+ example/8!))))
(def: #export test
(<| (_.covering /._)