diff options
| author | Timothee Cour <timothee.cour2@gmail.com> | 2018-11-27 18:06:17 -0500 |
|---|---|---|
| committer | Timothee Cour <timothee.cour2@gmail.com> | 2018-11-27 18:28:14 -0500 |
| commit | d00aeeafdd54134ff294dc4459a6b8cbaa560f8d (patch) | |
| tree | 5cdd3b1d174eab612618cafeff60486b704149cf /tests | |
| parent | fb053dd81eca9a45a813a7d7b0de868c28203976 (diff) | |
| download | nimterop-d00aeeafdd54134ff294dc4459a6b8cbaa560f8d.tar.gz nimterop-d00aeeafdd54134ff294dc4459a6b8cbaa560f8d.zip | |
add syntax cIncludeDir "$projpath/include"; do not use recursive search paths; add test tests/tnimterop_cpp.nim
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/include/test2.cpp | 8 | ||||
| -rw-r--r-- | tests/include/test2.hpp | 20 | ||||
| -rw-r--r-- | tests/tnimterop_c.nim (renamed from tests/tnimterop.nim) | 4 | ||||
| -rw-r--r-- | tests/tnimterop_cpp.nim | 49 |
4 files changed, 79 insertions, 2 deletions
diff --git a/tests/include/test2.cpp b/tests/include/test2.cpp new file mode 100644 index 0000000..4a40e90 --- /dev/null +++ b/tests/include/test2.cpp @@ -0,0 +1,8 @@ +#include "test2.hpp" + +// BUG: should complain +// # include test2.h + +int test_call_int() { + return 5; +} diff --git a/tests/include/test2.hpp b/tests/include/test2.hpp new file mode 100644 index 0000000..1ba9a8d --- /dev/null +++ b/tests/include/test2.hpp @@ -0,0 +1,20 @@ +#define TEST_INT 512 + +int test_call_int(); + +struct Foo{ + int bar; +}; + +class Foo1{ + int bar1; +}; + +template<typename T> +struct Foo2{ + int bar2; +}; + +typedef Foo2<int> Foo2_int; + + diff --git a/tests/tnimterop.nim b/tests/tnimterop_c.nim index dd822cb..1f2aaab 100644 --- a/tests/tnimterop.nim +++ b/tests/tnimterop_c.nim @@ -3,8 +3,8 @@ import nimterop/cimport cDebug() cDefine("FORCE") -cIncludeDir "include" -cAddSearchDir "include" +cIncludeDir "$projpath/include" +cAddSearchDir "$projpath/include" cCompile cSearchPath("test.c") cImport cSearchPath "test.h" diff --git a/tests/tnimterop_cpp.nim b/tests/tnimterop_cpp.nim new file mode 100644 index 0000000..b3d62f5 --- /dev/null +++ b/tests/tnimterop_cpp.nim @@ -0,0 +1,49 @@ +import nimterop/cimport +import unittest + +cDebug() + +cIncludeDir "$projpath/include" +cAddSearchDir "$projpath/include" +cCompile cSearchPath "test2.cpp" +# TODO: allow this to have correct language: cImport("test2.h") +cImport cSearchPath "test2.hpp" + +check TEST_INT == 512 +check test_call_int() == 5 + +var foo: Foo +check foo.bar == 2 + +# var foo2: Foo2[int] +# var foo2: Foo2Int + +when false: + doAssert TEST_FLOAT == 5.12 + doAssert TEST_HEX == 0x512 + + var + pt: PRIMTYPE + ct: CUSTTYPE + + s: STRUCT1 + s2: STRUCT2 + s3: STRUCT3 + + e: ENUM + e2: ENUM2 = enum5 + + pt = 3 + ct = 4 + + s.field1 = 5 + s2.field1 = 6 + s3.field1 = 7 + + e = enum1 + e2 = enum4 + + doAssert test_call_int_param(5).field1 == 5 + doAssert test_call_int_param2(5, s2).field1 == 11 + doAssert test_call_int_param3(5, s).field1 == 10 + doAssert test_call_int_param4(e) == e2 |
