prog8/compiler/test/TestGoldenRam.kt

63 lines
2.2 KiB
Kotlin
Raw Normal View History

package prog8tests.compiler
2022-12-02 22:58:21 +00:00
import com.github.michaelbull.result.expectError
import com.github.michaelbull.result.getOrThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import prog8.code.core.*
import prog8.code.target.VMTarget
import prog8tests.helpers.ErrorReporterForTests
class TestGoldenRam: FunSpec({
val options = CompilationOptions(
OutputType.RAW,
CbmPrgLauncherType.NONE,
ZeropageType.FULL,
listOf((0x00u..0xffu)),
CompilationOptions.AllZeropageAllowed,
2022-12-02 22:58:21 +00:00
floats = true,
noSysInit = false,
compTarget = VMTarget(),
loadAddress = 999u
)
test("empty golden ram allocations") {
val errors = ErrorReporterForTests()
val golden = GoldenRam(options, UIntRange.EMPTY)
2024-09-08 12:38:34 +00:00
val result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
2022-12-02 22:58:21 +00:00
result.expectError { "should not be able to allocate anything" }
}
test("regular golden ram allocations") {
val errors = ErrorReporterForTests()
val golden = GoldenRam(options, 0x400u until 0x800u)
2024-09-08 12:38:34 +00:00
var result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
2022-12-02 22:58:21 +00:00
var alloc = result.getOrThrow()
alloc.size shouldBe 1
alloc.address shouldBe 0x400u
2024-09-08 12:38:34 +00:00
result = golden.allocate("test", DataType.forDt(BaseDataType.STR), 100, null, errors)
2022-12-02 22:58:21 +00:00
alloc = result.getOrThrow()
alloc.size shouldBe 100
alloc.address shouldBe 0x401u
repeat(461) {
2024-09-08 12:38:34 +00:00
result = golden.allocate("test", DataType.forDt(BaseDataType.UWORD), null, null, errors)
2022-12-02 22:58:21 +00:00
alloc = result.getOrThrow()
alloc.size shouldBe 2
}
2024-09-08 12:38:34 +00:00
result = golden.allocate("test", DataType.forDt(BaseDataType.UWORD), null, null, errors)
2022-12-02 22:58:21 +00:00
result.expectError { "just 1 more byte available" }
2024-09-08 12:38:34 +00:00
result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
2022-12-02 22:58:21 +00:00
alloc = result.getOrThrow()
alloc.size shouldBe 1
alloc.address shouldBe golden.region.last
2024-09-08 12:38:34 +00:00
result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
2022-12-02 22:58:21 +00:00
result.expectError { "nothing more available" }
}
})