diff options
author | Erez Geva <ErezGeva2@gmail.com> | 2023-05-02 19:07:43 +0200 |
---|---|---|
committer | Erez Geva <ErezGeva2@gmail.com> | 2023-05-12 01:23:31 +0200 |
commit | b6eaee8d1219619113f715a7ee35644bfd557f34 (patch) | |
tree | be79612a387dbc5076fae9b53ea1f3c0b2385e7a /Examples/test-suite/lua/li_constraints_runme.lua | |
parent | 2dfa6d6b84eddd81f9c166a033a80b3224cf6127 (diff) | |
download | swig-b6eaee8d1219619113f715a7ee35644bfd557f34.tar.gz |
Add li_constraints test, testing 'constraints.i'.
For: JavaScript, C#, go, Java, Lua, Perl, PHP, python, Ruby, TCL and Octave.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
Diffstat (limited to 'Examples/test-suite/lua/li_constraints_runme.lua')
-rw-r--r-- | Examples/test-suite/lua/li_constraints_runme.lua | 40 |
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); |