]> Nishi Git Mirror - gwion.git/commitdiff
:white_check_mark: More tests
authorfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 11 Jul 2019 14:46:41 +0000 (16:46 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 11 Jul 2019 14:46:41 +0000 (16:46 +0200)
17 files changed:
tests/error/fork_value.gw [new file with mode: 0644]
tests/error/fptr_other_class.gw [new file with mode: 0644]
tests/error/non_public_typedef_global_scope.gw [new file with mode: 0644]
tests/error/non_static_from_member.gw [new file with mode: 0644]
tests/error/stack_overflow.gw [new file with mode: 0644]
tests/error/typedef_func_tmpl_types.gw [new file with mode: 0644]
tests/error/typedef_func_tmpl_types2.gw [new file with mode: 0644]
tests/import/fptr.c [new file with mode: 0644]
tests/import/fptr.gw [new file with mode: 0644]
tests/import/typedef.c
tests/import/typedef.gw
tests/sh/plugin.sh
tests/tree/typedef_func.gw [new file with mode: 0644]
tests/tree/typedef_func_class.gw [new file with mode: 0644]
tests/tree/typedef_func_tmpl.gw [new file with mode: 0644]
tests/tree/typedef_func_tmpl2.gw [new file with mode: 0644]
tests/tree/typedef_func_tmpl_class.gw [new file with mode: 0644]

diff --git a/tests/error/fork_value.gw b/tests/error/fork_value.gw
new file mode 100644 (file)
index 0000000..977f3e5
--- /dev/null
@@ -0,0 +1,2 @@
+#! [contains] forks must be stored in a value
+fork { <<< 1 >>>; };
diff --git a/tests/error/fptr_other_class.gw b/tests/error/fptr_other_class.gw
new file mode 100644 (file)
index 0000000..7a97e56
--- /dev/null
@@ -0,0 +1,8 @@
+#! [contains] can't use non global fptr of other class
+class C {
+  typedef void t_ptr() {}
+}
+class D {
+  typedef void t_ptr() {}
+  C->t_ptr ptr;
+}
diff --git a/tests/error/non_public_typedef_global_scope.gw b/tests/error/non_public_typedef_global_scope.gw
new file mode 100644 (file)
index 0000000..df46f92
--- /dev/null
@@ -0,0 +1,5 @@
+#! [contains] can't use non public typedef at global scope
+class C {
+  typedef void t_ptr();
+}
+C->t_ptr ptr;
diff --git a/tests/error/non_static_from_member.gw b/tests/error/non_static_from_member.gw
new file mode 100644 (file)
index 0000000..a08ab16
--- /dev/null
@@ -0,0 +1,5 @@
+#! [contains] non-static member 'i' used from static function
+class C {
+  int i;
+  fun static void test() { <<< i >>>; }
+}
diff --git a/tests/error/stack_overflow.gw b/tests/error/stack_overflow.gw
new file mode 100644 (file)
index 0000000..7152519
--- /dev/null
@@ -0,0 +1,3 @@
+#! [contains] StackOverflow
+fun void test() { test(); }
+test();
diff --git a/tests/error/typedef_func_tmpl_types.gw b/tests/error/typedef_func_tmpl_types.gw
new file mode 100644 (file)
index 0000000..71aa91d
--- /dev/null
@@ -0,0 +1,15 @@
+#! [contains] pre-defined types
+typedef void t_ptr<~A~>();
+
+<~int~>t_ptr iptr;
+
+fun void test<~A~>() {
+  <<< __func__ >>>;
+}
+
+test @=> iptr;
+#!<<< iptr<~int~>() >>>;
+<<< iptr() >>>;
+<<< iptr<~int~>() >>>;
+<<< iptr<~float~>() >>>;
+<<< iptr<~Object~>() >>>;
diff --git a/tests/error/typedef_func_tmpl_types2.gw b/tests/error/typedef_func_tmpl_types2.gw
new file mode 100644 (file)
index 0000000..5a8210a
--- /dev/null
@@ -0,0 +1,12 @@
+#! [contains] pre-defined types
+typedef void t_ptr<~A~>();
+typedef <~int~>t_ptr B;
+
+fun void test<~A~>() {
+  <<< __func__ >>>;
+}
+
+test @=> B b;
+#!<<< iptr<~int~>() >>>;
+<<< b() >>>;
+<<< b<~int~>() >>>;
diff --git a/tests/import/fptr.c b/tests/import/fptr.c
new file mode 100644 (file)
index 0000000..82b9f83
--- /dev/null
@@ -0,0 +1,29 @@
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "vm.h"
+#include "env.h"
+#include "type.h"
+#include "object.h"
+#include "instr.h"
+#include "gwion.h"
+#include "operator.h"
+#include "import.h"
+
+static MFUN(test_func) { puts("test"); }
+GWION_IMPORT(typedef_test) {
+  Type t_func_typedef;
+  CHECK_OB((t_func_typedef = gwi_mk_type(gwi, "FuncTypedef", SZ_INT , NULL)))
+  CHECK_BB(gwi_fptr_ini(gwi, "void", "PtrType"))
+  CHECK_OB(gwi_fptr_end(gwi, 0))
+  
+  CHECK_BB(gwi_class_ini(gwi, t_func_typedef, NULL, NULL))
+    CHECK_BB(gwi_fptr_ini(gwi, "void", "PtrType"))
+    CHECK_OB(gwi_fptr_end(gwi, ae_flag_static))
+    CHECK_BB(gwi_func_ini(gwi, "void", "test_func", test_func))
+    CHECK_BB(gwi_func_end(gwi, ae_flag_static))
+    CHECK_BB(gwi_item_ini(gwi, "PtrType", "ptr"))
+    CHECK_BB(gwi_item_end(gwi, ae_flag_static, NULL))
+  CHECK_BB(gwi_class_end(gwi))
+  return GW_OK;
+}
diff --git a/tests/import/fptr.gw b/tests/import/fptr.gw
new file mode 100644 (file)
index 0000000..2863933
--- /dev/null
@@ -0,0 +1,13 @@
+fun void test(){ <<< "test" >>>; }
+PtrType ptr;
+test();
+test @=> ptr;
+ptr();
+
+
+FuncTypedef.test_func();
+<<< FuncTypedef.test_func @=> FuncTypedef.ptr >>>;
+<FuncTypedef.PtrType> _ptr;
+<<< FuncTypedef.ptr >>>;
+FuncTypedef.ptr();
+
index 82b9f838d8fda723227a4602a3fe90e589b9def3..5e08baf19a912e65b98c8cb27b918f5338e43d94 100644 (file)
 #include "operator.h"
 #include "import.h"
 
-static MFUN(test_func) { puts("test"); }
 GWION_IMPORT(typedef_test) {
-  Type t_func_typedef;
-  CHECK_OB((t_func_typedef = gwi_mk_type(gwi, "FuncTypedef", SZ_INT , NULL)))
-  CHECK_BB(gwi_fptr_ini(gwi, "void", "PtrType"))
-  CHECK_OB(gwi_fptr_end(gwi, 0))
-  
-  CHECK_BB(gwi_class_ini(gwi, t_func_typedef, NULL, NULL))
-    CHECK_BB(gwi_fptr_ini(gwi, "void", "PtrType"))
-    CHECK_OB(gwi_fptr_end(gwi, ae_flag_static))
-    CHECK_BB(gwi_func_ini(gwi, "void", "test_func", test_func))
-    CHECK_BB(gwi_func_end(gwi, ae_flag_static))
-    CHECK_BB(gwi_item_ini(gwi, "PtrType", "ptr"))
-    CHECK_BB(gwi_item_end(gwi, ae_flag_static, NULL))
-  CHECK_BB(gwi_class_end(gwi))
+  GWI_OB(gwi_typedef_ini(gwi, "int", "Typedef"))
+  GWI_OB(gwi_typedef_end(gwi, ae_flag_none))
   return GW_OK;
 }
index 286393342a8a9fd0da60dcbb855582cde31bcff5..7cbe1087194fdb9bd144893d2b04bb232ef2a346 100644 (file)
@@ -1,13 +1,4 @@
-fun void test(){ <<< "test" >>>; }
-PtrType ptr;
-test();
-test @=> ptr;
-ptr();
-
-
-FuncTypedef.test_func();
-<<< FuncTypedef.test_func @=> FuncTypedef.ptr >>>;
-<FuncTypedef.PtrType> _ptr;
-<<< FuncTypedef.ptr >>>;
-FuncTypedef.ptr();
-
+Typedef t;
+#!fun int test(int i) { <<< i >>>; }
+#!test @=> t;
+<<< t >>>;
index b1cd9ac683e6152e50cbb7f795bd493d7efebaf5..1d873c2993371a6b3bcc3b9e0bc87e97b9ec9bb1 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# [test] #31
+# [test] #32
 
 n=0
 [ "$1" ] && n="$1"
diff --git a/tests/tree/typedef_func.gw b/tests/tree/typedef_func.gw
new file mode 100644 (file)
index 0000000..a521755
--- /dev/null
@@ -0,0 +1,8 @@
+typedef void t_ptr(int i);
+typedef t_ptr A;
+A a;
+<<<a>>>;
+
+fun void test(int i) { <<< __func__ , " ", i>>>; }
+test @=> a;
+a(1);
diff --git a/tests/tree/typedef_func_class.gw b/tests/tree/typedef_func_class.gw
new file mode 100644 (file)
index 0000000..f77ac2f
--- /dev/null
@@ -0,0 +1,14 @@
+class C {
+typedef void t_ptr();
+typedef t_ptr A;
+A a;
+<<<a>>>;
+
+fun void test() { <<< __func__ >>>; }
+test @=> a;
+a();
+a();
+a();
+}
+
+C c;
diff --git a/tests/tree/typedef_func_tmpl.gw b/tests/tree/typedef_func_tmpl.gw
new file mode 100644 (file)
index 0000000..cfa7ddf
--- /dev/null
@@ -0,0 +1,16 @@
+typedef void t_ptr<~A~>();
+
+<~int~>t_ptr iptr;
+<~float~>t_ptr fptr;
+
+fun void test<~A~>() {
+  <<< __func__ >>>;
+}
+
+test @=> iptr;
+test @=> fptr;
+
+<<< iptr() >>>;
+<<< iptr() >>>;
+<<< fptr() >>>;
+<<< fptr() >>>;
diff --git a/tests/tree/typedef_func_tmpl2.gw b/tests/tree/typedef_func_tmpl2.gw
new file mode 100644 (file)
index 0000000..98e11c3
--- /dev/null
@@ -0,0 +1,24 @@
+typedef void t_ptr<~A~>();
+fun void test<~A~>() {
+  <<< __func__ >>>;
+}
+
+typedef <~int~>t_ptr B;
+B b;
+<<< b >>>;
+test @=> b;
+<<< b >>>;
+<<< b() >>>;
+<<< b() >>>;
+
+
+typedef <~float~>t_ptr C;
+C c;
+<<< c >>>;
+test @=> c;
+<<< c >>>;
+<<< c() >>>;
+<<< c() >>>;
+
+<<< b() >>>;
+<<< c() >>>;
diff --git a/tests/tree/typedef_func_tmpl_class.gw b/tests/tree/typedef_func_tmpl_class.gw
new file mode 100644 (file)
index 0000000..3b91c5a
--- /dev/null
@@ -0,0 +1,16 @@
+class C {
+  typedef void t_ptr<~A~>();
+
+  <~int~>t_ptr iptr;
+
+  fun void test<~A~>() {
+    <<< this, " ", __func__ >>>;
+  }
+
+  test @=> iptr;
+  <<< iptr() >>>;
+#!  <<< iptr() >>>;
+}
+<<<C c>>>;
+  <<< c.iptr() >>>;
+#!  <<< c.iptr() >>>;