on master help sign in
Merge pull request #3859 from rbarreiro/test_for_issue_3192

added a test for javascript ffi with functions

commitedf03eebbc7010a1ce74127e79fd60737e327006 authorNiklas Larsson <metaniklas@gmail.com> dateTue 13 Jun 2017, 10:34 (9 years ago) parent1be086ffb55d38
5 files changed+52−1
test/README.md+1−1 test/TestData.hs+1 test/ffi010/expected+3 test/ffi010/ffi010.idr+43 test/ffi010/run+4
test/README.md+1−1
@@ -132,7 +132,7 @@ for the compatible backends are:
132132
133133- `ANY`: choose this if your test will work with any code generator
134134- `C_CG`: choose this to only test against the C code generator
135−- `JS_CG`: choose this to only test against the Node code generator
135+- `NODE_CG`: choose this to only test against the Node code generator
136136- `NONE`: choose this if you don't want your test to be run with multiple code
137137generators (mainly for tests that only perform type checking)
138138
test/TestData.hs+1
@@ -127,6 +127,7 @@ testFamiliesData = [
127127 , ( 7, C_CG )
128128 , ( 8, C_CG )
129129 , ( 9, C_CG )
130+ , ( 10, NODE_CG )
130131 ]),
131132 ("folding", "Folding",
132133 [ ( 1, ANY )]),
test/ffi010/expectednew file+3
@@ -0,0 +1,3 @@
1+start
2+olare
3+end
test/ffi010/ffi010.idrnew file+43
@@ -0,0 +1,43 @@
1+
2+%inline
3+public export
4+jscall : (fname : String) -> (ty : Type) ->
5+ {auto fty : FTy FFI_JS [] ty} -> ty
6+jscall fname ty = foreign FFI_JS fname ty
7+
8+export
9+data ServiceM : Type -> Type where
10+ PureServ : a -> ServiceM a
11+
12+
13+get_jsio : ServiceM a -> JS_IO (Either String a)
14+get_jsio (PureServ x) = do
15+ pure $ Right x
16+
17+export
18+mytst : String -> ServiceM String
19+mytst x = PureServ $ "end"
20+
21+call_fn : (String -> JS_IO String) -> String -> JS_IO String
22+call_fn f x = jscall
23+ "%0(%1)"
24+ ((JsFn (String -> JS_IO String)) -> String -> JS_IO String)
25+ (MkJsFn f)
26+ x
27+
28+mytstJs : String -> JS_IO String
29+mytstJs x = do
30+ r <- get_jsio $ mytst "arst"
31+ case r of
32+ Right k => pure k
33+
34+tst2 : JS_IO String
35+tst2 = call_fn mytstJs "inputmytst"
36+
37+export
38+main : JS_IO ()
39+main = do
40+ putStrLn' "start"
41+ r <- tst2
42+ putStrLn' "olare"
43+ putStrLn' r
test/ffi010/runnew file+4
@@ -0,0 +1,4 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} $@ ffi010.idr -o ffi010
3+./ffi010
4+rm -f ffi010 *.ibc