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

Java: regenerate tests after fixing enum generation #125

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion formats_err/expr_compare_enum2.ksy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# expr_compare_enum2.ksy: /seq/1/if:
# error: can't compare EnumType(List(animal),Int1Type(false)) and Int1Type(true)
# error: can't compare EnumType(animal, List(),Int1Type(false)) and Int1Type(true)
#
meta:
id: expr_compare_enum2
Expand Down
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