Permalink
Browse files

Tests for arrays and global vars

  • Loading branch information...
1 parent b901979 commit 14de0de5e764246a1ed68b8f3b78f7fb9db83b5f @v-for-vandal v-for-vandal committed with wsfulton Nov 7, 2013
View
30 Examples/test-suite/lua/array_member_runme.lua
@@ -0,0 +1,30 @@
+require("import") -- the import fn
+import("array_member") -- import lib
+am = array_member
+
+-- 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})
+
+assert(am.get_value(am.global_data,0) == 0)
+assert(am.get_value(am.global_data,7) == 7)
+
+foo = am.Foo()
+foo.data = am.global_data
+assert(am.get_value(foo.data,0) == 0)
+
+for i = 0, 7 do
+ assert(am.get_value(foo.data,i) == am.get_value(am.global_data,i))
+end
+
+
+for i = 0, 7 do
+ am.set_value(am.global_data,i,-i)
+end
+
+am.global_data = foo.data
+
+for i = 0, 7 do
+ assert(am.get_value(foo.data,i) == am.get_value(am.global_data,i))
+end
View
14 Examples/test-suite/lua/arrays_global_runme.lua
@@ -0,0 +1,14 @@
+require("import") -- the import fn
+import("arrays_global") -- import lib
+ag = arrays_global
+
+-- 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})
+
+assert(ag.BeginString_FIX44a == "FIX.a.a")
+assert(ag.BeginString_FIX44b == "FIX.b.b")
+
+assert(ag.BeginString_FIX44c == "FIX.c.c")
+assert(ag.BeginString_FIX44d == "FIX.d.d")
View
44 Examples/test-suite/lua/global_vars_runme.lua
@@ -0,0 +1,44 @@
+require("import") -- the import fn
+import("global_vars") -- import lib
+gv = global_vars
+
+-- 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})
+
+gv.b = "abcde"
+assert(gv.b == "abcde")
+
+gv.a.x = 7
+assert(gv.a.x == 7)
+
+a1 = gv.A()
+a1.x = 11
+gv.a = a1
+assert(gv.a.x == 11)
+
+gv.x = 10
+assert(gv.x == 10)
+
+assert(gv.Hi ~= nil)
+assert(gv.Hola ~= nil)
+
+gv.h = gv.Hi
+assert(gv.h == gv.Hi)
+
+
+-- It is not clear whether these tests should work or not
+-- Currently they don't.
+--
+-- assert(gv.c_member == 10)
+--
+-- gv.c_member = 5
+-- assert(gv.x == 5)
+--
+-- gv.h = gv.Hi
+-- assert(gv.hr == gv.Hi)
+--
+-- gv.hr = gv.Hola
+-- assert(gv.h == gv.Hola)
+-- assert(gv.hr == gv.Hola)

0 comments on commit 14de0de

Please sign in to comment.