| 225 | } |
| 226 | |
| 227 | func TestPullTableWithArraysFromLua(t *testing.T) { |
| 228 | require := func(l *lua.State) { |
| 229 | util.Open(l) |
| 230 | l.Register("validateTable", func(l *lua.State) int { |
| 231 | actual, err := util.PullTable(l, -1) |
| 232 | if err != nil { |
| 233 | t.Fatalf("failed to pull table: %s", err.Error()) |
| 234 | } |
| 235 | |
| 236 | expected := map[string]interface{}{ |
| 237 | "foo": []interface{}{ |
| 238 | "I", |
| 239 | "love", |
| 240 | map[string]interface{}{ |
| 241 | "lua": []interface{}{"LuaJIT", "go-lua"}, |
| 242 | "go": []interface{}{"6g", "gcc-go"}, |
| 243 | }, |
| 244 | }, |
| 245 | } |
| 246 | if !reflect.DeepEqual(expected, actual) { |
| 247 | t.Fatalf("expected %v, actual %v", expected, actual) |
| 248 | } |
| 249 | |
| 250 | return 0 |
| 251 | }) |
| 252 | } |
| 253 | luatesting.RunLuaTestString(t, require, ` |
| 254 | validateTable({ |
| 255 | foo = array({ |
| 256 | "I", |
| 257 | "love", |
| 258 | { |
| 259 | lua = array({"LuaJIT", "go-lua"}), |
| 260 | go = array({"6g", "gcc-go"}), |
| 261 | }, |
| 262 | }) |
| 263 | }) |
| 264 | `) |
| 265 | } |
| 266 | |
| 267 | func TestPullTableFailsWhenNotATable(t *testing.T) { |
| 268 | l := lua.NewState() |