summary refs log tree commit diff stats
path: root/tests/c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/c')
-rw-r--r--tests/c/tcompile.c3
-rw-r--r--tests/c/tcompile.nim10
-rw-r--r--tests/c/temit.nim16
-rw-r--r--tests/c/treservedcidentsasfields.nim39
4 files changed, 68 insertions, 0 deletions
diff --git a/tests/c/tcompile.c b/tests/c/tcompile.c
new file mode 100644
index 000000000..fc0482e40
--- /dev/null
+++ b/tests/c/tcompile.c
@@ -0,0 +1,3 @@
+int foo(int a, int b) {
+  return a+b;
+}
diff --git a/tests/c/tcompile.nim b/tests/c/tcompile.nim
new file mode 100644
index 000000000..cf99fd7ed
--- /dev/null
+++ b/tests/c/tcompile.nim
@@ -0,0 +1,10 @@
+discard """
+  output: '''44'''
+  joinable: "false"
+"""
+
+{.compile: "tcompile.c".}
+
+proc foo(a, b: cint): cint {.importc: "foo", cdecl.}
+
+echo foo(40, 4)
diff --git a/tests/c/temit.nim b/tests/c/temit.nim
new file mode 100644
index 000000000..1943c94ea
--- /dev/null
+++ b/tests/c/temit.nim
@@ -0,0 +1,16 @@
+discard """
+  output: "509"
+"""
+# Test the new ``emit`` pragma:
+
+{.emit: """
+#include <stdio.h>
+static int cvariable = 420;
+
+""".}
+
+proc embedsC() =
+  var nimVar = 89
+  {.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".}
+
+embedsC()
diff --git a/tests/c/treservedcidentsasfields.nim b/tests/c/treservedcidentsasfields.nim
new file mode 100644
index 000000000..6cdf9e855
--- /dev/null
+++ b/tests/c/treservedcidentsasfields.nim
@@ -0,0 +1,39 @@
+discard """
+  targets: "c cpp"
+"""
+
+import macros
+
+macro make_test_type(idents: varargs[untyped]): untyped =
+  result = nnkStmtList.newTree()
+
+  var ident_defs: seq[NimNode] = @[]
+  for i in idents:
+    ident_defs.add newIdentDefs(i, ident("int"))
+
+  result.add newTree(nnkTypeSection,
+    newTree(nnkTypeDef,
+      ident("TestType"),
+      newEmptyNode(),
+      newTree(nnkObjectTy,
+        newEmptyNode(),
+        newEmptyNode(),
+        newTree(nnkRecList,
+          ident_defs
+        )
+      )
+    )
+  )
+
+make_test_type(
+  auto, bool, catch, char, class, compl, const_cast, default, delete, double,
+  dynamic_cast, explicit, extern, false, float, friend, goto, int, long,
+  mutable, namespace, new, operator, private, protected, public, register,
+  reinterpret_cast, restrict, short, signed, sizeof, static_cast, struct, switch,
+  this, throw, true, typedef, typeid, typeof, typename, union, packed, unsigned,
+  virtual, void, volatile, wchar_t, alignas, alignof, constexpr, decltype, nullptr,
+  noexcept, thread_local, static_assert, char16_t, char32_t
+)
+
+# Make sure the type makes it to codegen.
+var test_instance: TestType