summaryrefslogtreecommitdiff
path: root/Examples/test-suite/lua/li_constraints_runme.lua
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-05-12 16:18:46 +1200
committerOlly Betts <olly@survex.com>2023-05-12 16:18:46 +1200
commit5b709dd1632580e52fbbf1385c66abccbd16b728 (patch)
tree22dc87977ee955eb1d0c3851dba02a77624daf28 /Examples/test-suite/lua/li_constraints_runme.lua
parenta44a7de3481e5f59c08dd71ec89b30b7578a52b9 (diff)
parentb6eaee8d1219619113f715a7ee35644bfd557f34 (diff)
downloadswig-5b709dd1632580e52fbbf1385c66abccbd16b728.tar.gz
Merge branch 'JS-check-fix'
Diffstat (limited to 'Examples/test-suite/lua/li_constraints_runme.lua')
-rw-r--r--Examples/test-suite/lua/li_constraints_runme.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/Examples/test-suite/lua/li_constraints_runme.lua b/Examples/test-suite/lua/li_constraints_runme.lua
new file mode 100644
index 000000000..c7577c2ac
--- /dev/null
+++ b/Examples/test-suite/lua/li_constraints_runme.lua
@@ -0,0 +1,40 @@
+require('import') -- the import fn
+import('li_constraints') -- import lib into global
+cn=li_constraints --alias
+
+function check_func(except, f, val, name)
+ actual, err = pcall(f, val);
+ assert(actual == except, 'function perform exception wrongly');
+ if name == nil then
+ r = 'SWIG_ValueError:Received a NULL pointer.';
+ else
+ r = 'SWIG_ValueError:Expected a ' .. name .. ' value.';
+ end
+ if not actual then
+ assert(err == r, 'function perform the wrong exception');
+ end
+end
+
+check_func(true, cn.test_nonnegative, 10, 'non-negative');
+check_func(true, cn.test_nonnegative, 0, 'non-negative');
+check_func(false, cn.test_nonnegative, -10, 'non-negative');
+
+check_func(false, cn.test_nonpositive, 10, 'non-positive');
+check_func(true, cn.test_nonpositive, 0, 'non-positive');
+check_func(true, cn.test_nonpositive, -10, 'non-positive');
+
+check_func(true, cn.test_positive, 10, 'positive');
+check_func(false, cn.test_positive, 0, 'positive');
+check_func(false, cn.test_positive, -10, 'positive');
+
+check_func(false, cn.test_negative, 10, 'negative');
+check_func(false, cn.test_negative, 0, 'negative');
+check_func(true, cn.test_negative, -10, 'negative');
+
+check_func(true, cn.test_nonzero, 10, 'nonzero');
+check_func(false, cn.test_nonzero, 0, 'nonzero');
+check_func(true, cn.test_nonzero, -10, 'nonzero');
+
+check_func(false, cn.test_nonnull, nil);
+nonnull = cn.get_nonnull();
+check_func(true, cn.test_nonnull, nonnull);