aboutsummaryrefslogtreecommitdiffstats
path: root/lib/monoucha0/test/basic.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-18 23:15:21 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-18 23:15:21 +0100
commit28fefabdeb685f4777ad2ad2ebf05e5e94e179d6 (patch)
tree56cd048df4a6987b4d9ef5924942119b3f2fd8aa /lib/monoucha0/test/basic.nim
parentb56abad0883c0b4179f9c329a7169bb544fac4a5 (diff)
parent33efaee783c2adb20df019a8bc924411c4a97e7f (diff)
downloadchawan-28fefabdeb685f4777ad2ad2ebf05e5e94e179d6.tar.gz
Add 'lib/monoucha0/' from commit '33efaee783c2adb20df019a8bc924411c4a97e7f'
git-subtree-dir: lib/monoucha0 git-subtree-mainline: b56abad0883c0b4179f9c329a7169bb544fac4a5 git-subtree-split: 33efaee783c2adb20df019a8bc924411c4a97e7f
Diffstat (limited to 'lib/monoucha0/test/basic.nim')
-rw-r--r--lib/monoucha0/test/basic.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/monoucha0/test/basic.nim b/lib/monoucha0/test/basic.nim
new file mode 100644
index 00000000..25161b1a
--- /dev/null
+++ b/lib/monoucha0/test/basic.nim
@@ -0,0 +1,26 @@
+import std/unittest
+
+import monoucha/fromjs
+import monoucha/javascript
+import monoucha/optshim
+
+type MyGlobal = ref object
+ s: string
+
+proc testFun(x: MyGlobal): string {.jsfunc.} =
+ return "Hello, " & x.s
+
+test "hello JS":
+ let rt = newJSRuntime()
+ let ctx = rt.newJSContext()
+ let global = MyGlobal(s: "world!")
+ ctx.registerType(MyGlobal, asglobal = true)
+ ctx.setGlobal(global)
+ const code = "testFun()"
+ let val = ctx.eval(code, "<test>", 0)
+ var res: string
+ check ctx.fromJS(val, res).isSome
+ check res == "Hello, world!"
+ JS_FreeValue(ctx, val)
+ ctx.free()
+ rt.free()