Merge branch 'v7.1' into v7.2

This commit is contained in:
Irmen de Jong 2021-10-20 22:51:14 +02:00
commit 8f2fb20934

View File

@ -1,14 +1,18 @@
package prog8tests package prog8tests
import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import prog8.ast.statements.Block import prog8.ast.statements.Block
import prog8.ast.statements.Return
import prog8.ast.statements.Subroutine import prog8.ast.statements.Subroutine
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
import prog8tests.helpers.assertSuccess import prog8tests.helpers.assertSuccess
import prog8tests.helpers.compileText import prog8tests.helpers.compileText
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertSame import kotlin.test.assertSame
import kotlin.test.assertTrue
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestOptimization { class TestOptimization {
@ -26,11 +30,10 @@ class TestOptimization {
val result = compileText(C64Target, true, sourcecode).assertSuccess() val result = compileText(C64Target, true, sourcecode).assertSuccess()
val toplevelModule = result.programAst.toplevelModule val toplevelModule = result.programAst.toplevelModule
val mainBlock = toplevelModule.statements.single() as Block val mainBlock = toplevelModule.statements.single() as Block
assertEquals(1, mainBlock.statements.size) val startSub = mainBlock.statements.single() as Subroutine
val startSub = mainBlock.statements[0] as Subroutine
assertSame(result.programAst.entrypoint, startSub) assertSame(result.programAst.entrypoint, startSub)
assertEquals("start", startSub.name) assertEquals("start", startSub.name, "only start sub should remain")
assertEquals(0, startSub.statements.size) assertTrue(startSub.statements.single() is Return, "compiler has inserted return in empty subroutines")
} }
@Test @Test
@ -54,6 +57,6 @@ class TestOptimization {
assertSame(result.programAst.entrypoint, startSub) assertSame(result.programAst.entrypoint, startSub)
assertEquals("start", startSub.name) assertEquals("start", startSub.name)
assertEquals("empty", emptySub.name) assertEquals("empty", emptySub.name)
assertEquals(0, emptySub.statements.size) assertTrue(emptySub.statements.single() is Return, "compiler has inserted return in empty subroutines")
} }
} }