File tree Expand file tree Collapse file tree
src/test/kotlin/eu/jameshamilton/klox/composer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import eu.jameshamilton.klox.compile.composer.break_
66import eu.jameshamilton.klox.compile.composer.SwitchCase
77import eu.jameshamilton.klox.compile.composer.case
88import eu.jameshamilton.klox.compile.composer.switch
9+ import eu.jameshamilton.klox.parse.FunctionExpr
910import eu.jameshamilton.klox.util.ClassPoolClassLoader
1011import io.kotest.core.spec.style.FunSpec
1112import 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 {
You can’t perform that action at this time.
0 commit comments