@@ -34,13 +34,7 @@ class LuaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s
34
34
}
35
35
36
36
override def runParseExpectError (exception : KSError ): Unit = {
37
- val msg = exception match {
38
- case _ : ValidationNotEqualError => " not equal, expected .*, but got .*"
39
- case UndecidedEndiannessError => " unable to decide endianness"
40
- case EndOfStreamError => " requested %d+ bytes, but only %d+ bytes available"
41
- case _ => LuaCompiler .ksErrorName(exception)
42
- }
43
- out.puts(s """ luaunit.assertErrorMsgMatches(".+: $msg", $className.from_file, $className, "src/ ${spec.data}") """ )
37
+ out.puts(s """ luaunit.assertErrorMsgMatches(".+: ${toPattern(exception)}", $className.from_file, $className, "src/ ${spec.data}") """ )
44
38
}
45
39
46
40
override def footer (): Unit = {
@@ -68,12 +62,29 @@ class LuaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(s
68
62
override def trueArrayEquality (check : TestEquals , elType : DataType , elts : Seq [Ast .expr]): Unit =
69
63
simpleEquality(check)
70
64
65
+ override def testException (actual : Ast .expr, exception : KSError ): Unit = {
66
+ out.puts(s """ luaunit.assertErrorMsgMatches(".+: ${toPattern(exception)}", function() """ )
67
+ out.inc
68
+ out.puts(s " local _ = ${translateAct(actual)}" )
69
+ out.dec
70
+ out.puts(" end)" )
71
+ }
72
+
71
73
def translateAct (x : Ast .expr) =
72
74
translator.translate(x).replace(" self." + Main .INIT_OBJ_NAME , " r" )
73
75
74
76
def translateExp (x : Ast .expr) =
75
77
translator.translate(x).replace(" self._root" , className)
76
78
79
+ def toPattern (exception : KSError ): String = {
80
+ exception match {
81
+ case _ : ValidationNotEqualError => " not equal, expected .*, but got .*"
82
+ case UndecidedEndiannessError => " unable to decide endianness"
83
+ case EndOfStreamError => " requested %d+ bytes, but only %d+ bytes available"
84
+ case _ => LuaCompiler .ksErrorName(exception)
85
+ }
86
+ }
87
+
77
88
override def results : String =
78
89
" -- " + AUTOGEN_COMMENT + " \n\n " + super .results
79
90
}
0 commit comments