diff options
Diffstat (limited to 'tests/cpp')
-rw-r--r-- | tests/cpp/tcppraise.nim | 17 | ||||
-rw-r--r-- | tests/cpp/tget_subsystem.nim | 23 | ||||
-rw-r--r-- | tests/cpp/tnativesockets.nim (renamed from tests/cpp/trawsockets.nim) | 2 | ||||
-rw-r--r-- | tests/cpp/tthread_createthread.nim | 2 | ||||
-rw-r--r-- | tests/cpp/ttypeinfo2.nim | 6 | ||||
-rw-r--r-- | tests/cpp/tvector_iterator.nim | 19 | ||||
-rw-r--r-- | tests/cpp/tvectorseq.nim | 38 |
7 files changed, 105 insertions, 2 deletions
diff --git a/tests/cpp/tcppraise.nim b/tests/cpp/tcppraise.nim new file mode 100644 index 000000000..a9ea8e6ce --- /dev/null +++ b/tests/cpp/tcppraise.nim @@ -0,0 +1,17 @@ +discard """ + cmd: "nim cpp $file" + output: '''foo +bar +Need odd and >= 3 digits## +baz''' +""" + +# bug #1888 +echo "foo" +try: + echo "bar" + raise newException(ValueError, "Need odd and >= 3 digits") +# echo "baz" +except ValueError: + echo getCurrentExceptionMsg(), "##" +echo "baz" diff --git a/tests/cpp/tget_subsystem.nim b/tests/cpp/tget_subsystem.nim new file mode 100644 index 000000000..461914739 --- /dev/null +++ b/tests/cpp/tget_subsystem.nim @@ -0,0 +1,23 @@ +discard """ + cmd: "nim cpp $file" +""" + +{.emit: """ + +namespace System { + struct Input {}; +} + +struct SystemManager { + template <class T> + static T* getSubsystem() { return new T; } +}; + +""".} + +type Input {.importcpp: "System::Input".} = object +proc getSubsystem*[T](): ptr T {. + importcpp: "SystemManager::getSubsystem<'*0>()", nodecl.} + +let input: ptr Input = getSubsystem[Input]() + diff --git a/tests/cpp/trawsockets.nim b/tests/cpp/tnativesockets.nim index bc129de57..6108380a8 100644 --- a/tests/cpp/trawsockets.nim +++ b/tests/cpp/tnativesockets.nim @@ -2,4 +2,4 @@ discard """ cmd: "nim cpp $file" """ -import rawsockets +import nativesockets diff --git a/tests/cpp/tthread_createthread.nim b/tests/cpp/tthread_createthread.nim index 0dc081268..2c239005f 100644 --- a/tests/cpp/tthread_createthread.nim +++ b/tests/cpp/tthread_createthread.nim @@ -11,4 +11,4 @@ proc main() = thread.createThread(threadMain, 0) thread.joinThreads() -main() \ No newline at end of file +main() diff --git a/tests/cpp/ttypeinfo2.nim b/tests/cpp/ttypeinfo2.nim new file mode 100644 index 000000000..64bd43e96 --- /dev/null +++ b/tests/cpp/ttypeinfo2.nim @@ -0,0 +1,6 @@ +discard """ + cmd: "nim cpp $file" +""" +# bug #2841 +import typeinfo +var tt: Any diff --git a/tests/cpp/tvector_iterator.nim b/tests/cpp/tvector_iterator.nim new file mode 100644 index 000000000..cb5ab33af --- /dev/null +++ b/tests/cpp/tvector_iterator.nim @@ -0,0 +1,19 @@ +discard """ + cmd: "nim cpp $file" +""" + +{.emit: """ + +template <class T> +struct Vector { + struct Iterator {}; +}; + +""".} + +type + Vector {.importcpp: "Vector".} [T] = object + VectorIterator {.importcpp: "Vector<'0>::Iterator".} [T] = object + +var x: VectorIterator[void] + diff --git a/tests/cpp/tvectorseq.nim b/tests/cpp/tvectorseq.nim new file mode 100644 index 000000000..6eb5dc9e4 --- /dev/null +++ b/tests/cpp/tvectorseq.nim @@ -0,0 +1,38 @@ +discard """ + output: '''(x: 1.0) +(x: 0.0)''' + cmd: "nim cpp $file" + disabled: "true" +""" + +# This cannot work yet because we omit type information for importcpp'ed types. +# Fixing this is not hard, but also requires fixing Urhonimo. + +# bug #2536 + +{.emit: """/*TYPESECTION*/ +struct Vector3 { +public: + Vector3(): x(5) {} + Vector3(float x_): x(x_) {} + float x; +}; +""".} + +type Vector3 {.importcpp: "Vector3", nodecl} = object + x: cfloat + +proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl} + +# hack around another codegen issue: Generics are attached to where they came +# from: +proc `$!`(v: seq[Vector3]): string = "(x: " & $v[0].x & ")" + +proc vec3List*(): seq[Vector3] = + let s = @[constructVector3(cfloat(1))] + echo($!s) + result = s + echo($!result) + +let f = vec3List() +#echo($!f) |