diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2021-03-06 10:55:47 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2021-03-06 10:55:47 +0000 |
commit | 227614056be6b9d390b05a400dd5dcec85f82567 (patch) | |
tree | 5f9f4003f2f200369d82472155160eb5d1c1479c /Examples | |
parent | 22c8b33eddef1d6bafeeb75f31e94326c32be0ad (diff) | |
download | swig-227614056be6b9d390b05a400dd5dcec85f82567.tar.gz |
Convert javascript_arrays.i example into testcase
Diffstat (limited to 'Examples')
-rw-r--r-- | Examples/javascript/array/Makefile | 3 | ||||
-rw-r--r-- | Examples/javascript/array/binding.gyp.in | 9 | ||||
-rw-r--r-- | Examples/javascript/array/example.i | 31 | ||||
-rw-r--r-- | Examples/javascript/array/example.js | 1 | ||||
-rw-r--r-- | Examples/javascript/array/runme.js | 7 | ||||
-rw-r--r-- | Examples/javascript/check.list | 1 | ||||
-rw-r--r-- | Examples/test-suite/javascript/Makefile.in | 3 | ||||
-rw-r--r-- | Examples/test-suite/javascript/javascript_lib_arrays_runme.js | 20 | ||||
-rw-r--r-- | Examples/test-suite/javascript_lib_arrays.i | 30 |
9 files changed, 53 insertions, 52 deletions
diff --git a/Examples/javascript/array/Makefile b/Examples/javascript/array/Makefile deleted file mode 100644 index 0402f8d09..000000000 --- a/Examples/javascript/array/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -SRCS = - -include $(SRCDIR)../example.mk diff --git a/Examples/javascript/array/binding.gyp.in b/Examples/javascript/array/binding.gyp.in deleted file mode 100644 index 59779aef4..000000000 --- a/Examples/javascript/array/binding.gyp.in +++ /dev/null @@ -1,9 +0,0 @@ -{ - "targets": [ - { - "target_name": "example", - "sources": [ "example_wrap.cxx" ], - "include_dirs": ["$srcdir"] - } - ] -} diff --git a/Examples/javascript/array/example.i b/Examples/javascript/array/example.i deleted file mode 100644 index 3e77e2ac1..000000000 --- a/Examples/javascript/array/example.i +++ /dev/null @@ -1,31 +0,0 @@ -/* File : example.i */ -%module example - -%include <arrays_javascript.i> - -%apply int[] {int *data1} -%apply int[3] {int data2[3]} -%apply int[4] {int data3[4]} - -%inline %{ - -int sum1(int *data1, int size) { - int sum = 0; - for (int i = 0; i < size; i++) { - sum += data1[i]; - } - return sum; -} - -int sum2(int data2[3]) { - int sum = 0; - for (int i = 0; i < 3; i++) { - sum += data2[i]; - } - return sum; -} - -int data3[4] = {1, 2, 3, 4}; - -%} - diff --git a/Examples/javascript/array/example.js b/Examples/javascript/array/example.js deleted file mode 100644 index 2e7f83a06..000000000 --- a/Examples/javascript/array/example.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("build/Release/example"); diff --git a/Examples/javascript/array/runme.js b/Examples/javascript/array/runme.js deleted file mode 100644 index 816ac4af0..000000000 --- a/Examples/javascript/array/runme.js +++ /dev/null @@ -1,7 +0,0 @@ -var example = require("example"); - -var arr = [1, 2, 3, 4, 5]; - -console.log(example.sum1(arr, arr.length)); -console.log(example.sum2(arr)); -console.log(example.data3) diff --git a/Examples/javascript/check.list b/Examples/javascript/check.list index 7ae61277c..977835755 100644 --- a/Examples/javascript/check.list +++ b/Examples/javascript/check.list @@ -1,4 +1,3 @@ -array class constant enum diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index fed028388..93602a434 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -16,6 +16,9 @@ top_builddir = @top_builddir@ C_TEST_CASES += \ ccomplextest \ +CPP_TEST_CASES += \ + javascript_lib_arrays \ + SWIGEXE = $(top_builddir)/swig SWIG_LIB_DIR = $(top_srcdir)/Lib diff --git a/Examples/test-suite/javascript/javascript_lib_arrays_runme.js b/Examples/test-suite/javascript/javascript_lib_arrays_runme.js new file mode 100644 index 000000000..1eb586134 --- /dev/null +++ b/Examples/test-suite/javascript/javascript_lib_arrays_runme.js @@ -0,0 +1,20 @@ +var javascript_lib_arrays = require("javascript_lib_arrays"); + +var arr = [1, 2, 3, 4, 5]; + +function check(a, b) { + if (a !== b) { + throw new Error("Not equal: " + a + " " + b) + } +} + +function check_array(a, b) { + if (a.length != b.length) + throw new Error("Array length mismatch " + a.length + " " + b.length) + if (!a.every(function(element, index) { return element === b[index]; })) + throw new Error("Arrays don't match a:" + a + " b:" + b) +} + +check(15, javascript_lib_arrays.sum1(arr, arr.length)); +check(6, javascript_lib_arrays.sum2(arr)); +check_array([1, 2, 3, 4], javascript_lib_arrays.data3) diff --git a/Examples/test-suite/javascript_lib_arrays.i b/Examples/test-suite/javascript_lib_arrays.i new file mode 100644 index 000000000..512084ad5 --- /dev/null +++ b/Examples/test-suite/javascript_lib_arrays.i @@ -0,0 +1,30 @@ +%module javascript_lib_arrays + +%include <arrays_javascript.i> + +%apply int[] { int *data1 } +%apply int[3] { int data2[3] } +%apply int[4] { int data3[4] } + +%inline %{ + +int sum1(int *data1, int size) { + int sum = 0; + for (int i = 0; i < size; i++) { + sum += data1[i]; + } + return sum; +} + +int sum2(int data2[3]) { + int sum = 0; + for (int i = 0; i < 3; i++) { + sum += data2[i]; + } + return sum; +} + +int data3[4] = {1, 2, 3, 4}; + +%} + |