Skip to content

Commit c1cfe2e

Browse files
test: Add generated tests for eu.jameshamilton.klox.compile.composer.SwitchKt.switch(LComposer;LFunctionExpr;[Leu/jameshamilton/klox/compile/composer/SwitchCase;Lkotlin/jvm/functions/Function1;)LComposer;
1 parent 6b1b238 commit c1cfe2e

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/test/kotlin/eu/jameshamilton/klox/composer/SwitchComposerTest.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import eu.jameshamilton.klox.compile.composer.break_
66
import eu.jameshamilton.klox.compile.composer.SwitchCase
77
import eu.jameshamilton.klox.compile.composer.case
88
import eu.jameshamilton.klox.compile.composer.switch
9+
import eu.jameshamilton.klox.parse.FunctionExpr
910
import eu.jameshamilton.klox.util.ClassPoolClassLoader
1011
import io.kotest.core.spec.style.FunSpec
1112
import io.kotest.matchers.shouldBe
@@ -242,6 +243,50 @@ class SwitchComposerTest : FunSpec({
242243
} shouldBe "B!"
243244
}
244245

246+
test("Integer switch with FunctionExpr overload") {
247+
val function = FunctionExpr()
248+
execute {
249+
ldc(1)
250+
switch(
251+
function,
252+
1 case {
253+
ldc("A!")
254+
break_()
255+
},
256+
2 case {
257+
ldc("B!")
258+
break_()
259+
},
260+
default = {
261+
ldc("default")
262+
}
263+
)
264+
areturn()
265+
} shouldBe "A!"
266+
}
267+
268+
test("Integer switch with FunctionExpr overload default") {
269+
val function = FunctionExpr()
270+
execute {
271+
ldc(3)
272+
switch(
273+
function,
274+
1 case {
275+
ldc("A!")
276+
break_()
277+
},
278+
2 case {
279+
ldc("B!")
280+
break_()
281+
},
282+
default = {
283+
ldc("default")
284+
}
285+
)
286+
areturn()
287+
} shouldBe "default"
288+
}
289+
245290
test("Mixed type cases should throw IllegalStateException") {
246291
io.kotest.assertions.throwables.shouldThrow<IllegalStateException> {
247292
execute {

0 commit comments

Comments
 (0)