def testRequireWalkerErrorBadOptionValue(self): ast = lua.Lua.from_lines([b'require("foo", {use_game_loop=123})'], 8) try: unused_result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.fail() except build.LuaBuildError: pass
def testRequireWalkerErrorSecondNonTable(self): ast = lua.Lua.from_lines([b'require("foo", 123)'], 8) try: unused_result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.fail() except build.LuaBuildError: pass
def testRequireWalkerErrorBadOptionName(self): ast = lua.Lua.from_lines([b'require("foo", {invalid_name=true})'], 8) try: unused_result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.fail() except build.LuaBuildError: pass
def testRequireWalkerErrorFirstNonString(self): ast = lua.Lua.from_lines([b'require(123)'], 8) try: unused_result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.fail() except build.LuaBuildError: pass
def testRequireWalkerComplexRequires(self): ast = lua.Lua.from_lines([ b'foomod = require("foo")' b'function bar()', b' require("foo", {use_game_loop=true})', b'end\n'], 8) result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.assertEquals(2, len(result))
def testRequireWalkerOptionsTable(self): ast = lua.Lua.from_lines([ b'print("hi")', b'require("foo", {use_game_loop=true})', b'x = 7\n'], 8) result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.assertEquals(1, len(result)) self.assertEquals((b'foo', True, lexer.TokSymbol(b'(')), result[0])
def testRequireWalkerExpression(self): ast = lua.Lua.from_lines([ b'print("hi")', b'foomod = require("foo")', b'x = 7\n'], 8) result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.assertEquals(1, len(result)) self.assertEquals((b'foo', False, lexer.TokSymbol(b'(')), result[0])
def testRequireWalkerNoRequires(self): ast = lua.Lua.from_lines([ b'print("hi")', b'x = 7\n'], 8) result = list(build.RequireWalker(ast.tokens, ast.root).walk()) self.assertEquals(0, len(result))