Skip to content

Commit

Permalink
Change test generator to correctly handle unknown enum values and reg…
Browse files Browse the repository at this point in the history
…enerate tests
  • Loading branch information
Mingun committed Sep 8, 2024
1 parent 3cf422f commit 85049ab
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
10 changes: 6 additions & 4 deletions spec/java/src/io/kaitai/struct/spec/TestEnumInvalid.java

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

3 changes: 2 additions & 1 deletion spec/java/src/io/kaitai/struct/spec/TestEnumToIInvalid.java

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

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

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 @@ -65,11 +65,24 @@ class JavaSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(

override def simpleEquality(check: TestEquals): Unit = {
val actType = translator.detectType(check.actual)
val expType = translator.detectType(check.expected)

val actStr = translateAct(check.actual)
val expStr = translator.translate(check.expected)
actType match {
case _: IntType | _: BooleanType =>

(actType, expType) match {
case (_: IntType | _: BooleanType, _) =>
out.puts(s"assertIntEquals($actStr, $expStr);")
case (et: EnumType, _: IntType) => {
// When we expect unknown value of enumeration, in KST we uses just it integer value
// That expression would be translated to number. Wh should wrap it to enum
val enumSpec = et.enumSpec.get
val expEnum = translator.doEnumById(enumSpec, expStr)
val enumName = translator.enumClass(enumSpec.name)

out.puts(s"assertEquals($actStr, $expEnum);")
out.puts(s"assertTrue($expEnum instanceof $enumName.Unknown);")
}
case _ =>
out.puts(s"assertEquals($actStr, $expStr);")
}
Expand Down

0 comments on commit 85049ab

Please sign in to comment.