Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua: support exception key in assertions => add expr_to_i_trailing test #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions spec/lua/test_expr_to_i_trailing.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ class LuaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s
}

override def runParseExpectError(exception: KSError): Unit = {
val msg = exception match {
case _: ValidationNotEqualError => "not equal, expected .*, but got .*"
case UndecidedEndiannessError => "unable to decide endianness"
case EndOfStreamError => "requested %d+ bytes, but only %d+ bytes available"
case _ => LuaCompiler.ksErrorName(exception)
}
out.puts(s"""luaunit.assertErrorMsgMatches(".+: $msg", $className.from_file, $className, "src/${spec.data}")""")
out.puts(s"""luaunit.assertErrorMsgMatches(".+: ${toPattern(exception)}", $className.from_file, $className, "src/${spec.data}")""")
}

override def footer(): Unit = {
Expand Down Expand Up @@ -68,12 +62,29 @@ class LuaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s
override def trueArrayEquality(check: TestEquals, elType: DataType, elts: Seq[Ast.expr]): Unit =
simpleEquality(check)

override def testException(actual: Ast.expr, exception: KSError): Unit = {
out.puts(s"""luaunit.assertErrorMsgMatches(".+: ${toPattern(exception)}", function()""")
out.inc
out.puts(s"local _ = ${translateAct(actual)}")
out.dec
out.puts("end)")
}

def translateAct(x: Ast.expr) =
translator.translate(x).replace("self." + Main.INIT_OBJ_NAME, "r")

def translateExp(x: Ast.expr) =
translator.translate(x).replace("self._root", className)

def toPattern(exception: KSError): String = {
exception match {
case _: ValidationNotEqualError => "not equal, expected .*, but got .*"
case UndecidedEndiannessError => "unable to decide endianness"
case EndOfStreamError => "requested %d+ bytes, but only %d+ bytes available"
case _ => LuaCompiler.ksErrorName(exception)
}
}

override def results: String =
"-- " + AUTOGEN_COMMENT + "\n\n" + super.results
}