summary refs log tree commit diff stats
path: root/tests/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cpp')
-rw-r--r--tests/cpp/mexportc.nim9
-rw-r--r--tests/cpp/tempty_generic_obj.nim11
-rw-r--r--tests/cpp/texportc.nim22
3 files changed, 40 insertions, 2 deletions
diff --git a/tests/cpp/mexportc.nim b/tests/cpp/mexportc.nim
new file mode 100644
index 000000000..dee51f157
--- /dev/null
+++ b/tests/cpp/mexportc.nim
@@ -0,0 +1,9 @@
+{.used.} # ideally, would not be needed
+
+var fun0 {.exportc.} = 10
+proc fun1() {.exportc.} = discard
+proc fun2() {.exportc: "$1".} = discard
+proc fun3() {.exportc: "fun3Bis".} = discard
+
+when defined cpp:
+  proc funx1() {.exportcpp.} = discard
diff --git a/tests/cpp/tempty_generic_obj.nim b/tests/cpp/tempty_generic_obj.nim
index b61c699f6..d05a82f9a 100644
--- a/tests/cpp/tempty_generic_obj.nim
+++ b/tests/cpp/tempty_generic_obj.nim
@@ -8,7 +8,7 @@ import typetraits
 
 # bug #4625
 type
-  Vector {.importcpp: "std::vector<'0 >", header: "vector".} [T] = object
+  Vector[T] {.importcpp: "std::vector<'0 >", header: "vector".} = object
 
 proc initVector[T](): Vector[T] {.importcpp: "'0(@)", header: "vector", constructor.}
 
@@ -24,7 +24,7 @@ vf.doSomething() # Nim uses doSomething[int] here in C++
 # Alternative definition:
 # https://github.com/nim-lang/Nim/issues/7653
 
-type VectorAlt* {.importcpp: "std::vector", header: "<vector>", nodecl.} [T] = object
+type VectorAlt*[T] {.importcpp: "std::vector", header: "<vector>", nodecl.} = object
 proc mkVector*[T]: VectorAlt[T] {.importcpp: "std::vector<'*0>()", header: "<vector>", constructor, nodecl.}
 
 proc foo(): VectorAlt[cint] =
@@ -36,3 +36,10 @@ proc bar(): VectorAlt[cstring] =
 var x = foo()
 var y = bar()
 
+proc init[T; Self: Vector[T]](_: typedesc[Self], n: csize): Vector[T]
+  {.importcpp: "std::vector<'*0>(@)", header: "<vector>", constructor, nodecl.}
+proc size[T](x: Vector[T]): csize
+  {.importcpp: "#.size()", header: "<vector>", nodecl.}
+
+var z = Vector[int16].init(32)
+assert z.size == 32
diff --git a/tests/cpp/texportc.nim b/tests/cpp/texportc.nim
new file mode 100644
index 000000000..3a2fa8748
--- /dev/null
+++ b/tests/cpp/texportc.nim
@@ -0,0 +1,22 @@
+discard """
+  targets: "c cpp"
+"""
+
+var fun0 {.importc.}: int
+proc fun1() {.importc.}
+proc fun2() {.importc: "$1".}
+proc fun3() {.importc: "fun3Bis".}
+
+when defined cpp:
+  # proc funx1() {.importcpp.} # this does not work yet
+  proc funx1() {.importc: "_Z5funx1v".}
+
+doAssert fun0 == 10
+fun1()
+fun2()
+fun3()
+
+when defined cpp:
+  funx1()
+
+import ./mexportc