aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/ffi.js.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/ffi.js.lux104
1 files changed, 74 insertions, 30 deletions
diff --git a/stdlib/source/test/lux/ffi.js.lux b/stdlib/source/test/lux/ffi.js.lux
index 57a8332e2..e2c699dbd 100644
--- a/stdlib/source/test/lux/ffi.js.lux
+++ b/stdlib/source/test/lux/ffi.js.lux
@@ -6,6 +6,7 @@
[control
["." try]]
[data
+ ["." bit ("#\." equivalence)]
["." text ("#\." equivalence)]]
[math
["." random (#+ Random)]
@@ -53,33 +54,76 @@
## I64s get compiled as JavaScript objects with a specific structure.
object random.nat]
(<| (_.covering /._)
- ($_ _.and
- (_.cover [/.on_browser? /.on_node_js? /.on_nashorn?]
- (or /.on_nashorn?
- /.on_node_js?
- /.on_browser?))
- (_.cover [/.type_of]
- (and (text\= "boolean" (/.type_of boolean))
- (text\= "number" (/.type_of number))
- (text\= "string" (/.type_of string))
- (text\= "function" (/.type_of function))
- (text\= "object" (/.type_of object))))
- (_.cover [/.import:]
- (let [encoding "utf8"]
- (text\= string
- (cond /.on_nashorn?
- (let [binary (java/lang/String::getBytes [encoding] (:as java/lang/String string))]
- (|> (java/lang/String::new [binary encoding])
- (:as Text)))
-
- /.on_node_js?
- (|> (Buffer::from [string encoding])
- (Buffer::toString [encoding]))
-
- ## On the browser
- (let [binary (|> (TextEncoder::new [encoding])
- (TextEncoder::encode [string]))]
- (|> (TextDecoder::new [encoding])
- (TextDecoder::decode [binary])))
- ))))
- ))))
+ (`` ($_ _.and
+ (~~ (template [<type> <value>]
+ [(_.cover [<type>]
+ (exec
+ (: <type> <value>)
+ true))]
+
+ [/.Boolean boolean]
+ [/.Number number]
+ [/.String string]
+ ))
+ (_.for [/.Object]
+ ($_ _.and
+ (~~ (template [<type>]
+ [(_.cover [<type>]
+ (exec
+ (: (Ex [a] (/.Object a))
+ (: <type>
+ (:assume [])))
+ true))]
+
+ [/.Function]
+ [/.Symbol]
+ [/.Null]
+ [/.Undefined]
+ ))
+ ))
+ (_.cover [/.constant]
+ (|> (/.constant /.Function [parseFloat])
+ "js object null?"
+ not))
+ (_.cover [/.closure]
+ (|> (/.closure [input/0] input/0)
+ "js object null?"
+ not))
+ (_.cover [/.on_browser? /.on_node_js? /.on_nashorn?]
+ (and (or /.on_nashorn?
+ /.on_node_js?
+ /.on_browser?)
+ (bit\= /.on_nashorn?
+ (not (or /.on_node_js?
+ /.on_browser?)))
+ (bit\= /.on_node_js?
+ (not (or /.on_nashorn?
+ /.on_browser?)))
+ (bit\= /.on_browser?
+ (not (or /.on_nashorn?
+ /.on_node_js?)))))
+ (_.cover [/.type_of]
+ (and (text\= "boolean" (/.type_of boolean))
+ (text\= "number" (/.type_of number))
+ (text\= "string" (/.type_of string))
+ (text\= "function" (/.type_of function))
+ (text\= "object" (/.type_of object))))
+ (_.cover [/.import:]
+ (let [encoding "utf8"]
+ (text\= string
+ (cond /.on_nashorn?
+ (let [binary (java/lang/String::getBytes [encoding] (:as java/lang/String string))]
+ (|> (java/lang/String::new [binary encoding])
+ (:as Text)))
+
+ /.on_node_js?
+ (|> (Buffer::from [string encoding])
+ (Buffer::toString [encoding]))
+
+ ## On the browser
+ (let [binary (|> (TextEncoder::new [encoding])
+ (TextEncoder::encode [string]))]
+ (|> (TextDecoder::new [encoding])
+ (TextDecoder::decode [binary])))
+ ))))
+ )))))