diff options
author | Alistair Delva <adelva@google.com> | 2024-04-10 14:15:29 -0700 |
---|---|---|
committer | Alistair Delva <adelva@google.com> | 2024-04-11 12:58:28 -0700 |
commit | d0f0f90be16c2ac553b5fa08512045273135147a (patch) | |
tree | 5d9ebb7a04807ea8a609ddd18b0162bc87530e4b /Examples/test-suite/lua/argcargvtest_runme.lua | |
parent | 6ffc1dbf29ba98c4d8aa71ebc9b484e973fe1030 (diff) | |
download | swig-master.tar.gz |
Update to v4.2.1HEADmastermainllvm-r522817
Change-Id: I47cef2be94299220d80265d949a95b58eee2c23b
Diffstat (limited to 'Examples/test-suite/lua/argcargvtest_runme.lua')
-rw-r--r-- | Examples/test-suite/lua/argcargvtest_runme.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Examples/test-suite/lua/argcargvtest_runme.lua b/Examples/test-suite/lua/argcargvtest_runme.lua new file mode 100644 index 000000000..eea522272 --- /dev/null +++ b/Examples/test-suite/lua/argcargvtest_runme.lua @@ -0,0 +1,38 @@ +require("import") -- the import fn +import("argcargvtest") -- import lib +v = argcargvtest + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +largs = {"hi", "hola", "hello"} +assert(v.mainc(largs) == 3, "bad main typemap") + +targs = {"hi", "hola"} +assert(v.mainv(targs, 0) == "hi", "bad main typemap") +assert(v.mainv(targs, 1) == "hola", "bad main typemap") +assert(v.mainv(targs, 2) == "<<NULL>>", "bad main typemap") + +errorVal = 0 +function try() + mainv("hello", 1) + errorVal = 1 +end +assert(not pcall(try) and errorVal == 0, "bad main typemap") + +v.initializeApp(largs) + +-- Check that an empty array works. +empty_args = {} +assert(v.mainc(empty_args) == 0, "bad main typemap") +assert(v.mainv(empty_args, 0) == "<<NULL>>", "bad main typemap") + +-- Check that empty strings are handled. +empty_string = {"hello", "", "world"} +assert(v.mainc(empty_string) == 3, "bad main typemap") +assert(v.mainv(empty_string, 0) == "hello", "bad main typemap") +assert(v.mainv(empty_string, 1) == "", "bad main typemap") +assert(v.mainv(empty_string, 2) == "world", "bad main typemap") +assert(v.mainv(empty_string, 3) == "<<NULL>>", "bad main typemap") |