prog8/compiler/test/TestGoldenRam.kt

64 lines
2.1 KiB
Kotlin
Raw Permalink 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,
memtopAddress = 0xffffu
2022-12-02 22:58:21 +00:00
)
test("empty golden ram allocations") {
val errors = ErrorReporterForTests()
val golden = GoldenRam(options, UIntRange.EMPTY)
2023-02-15 23:33:37 +00:00
val result = golden.allocate("test", DataType.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)
2023-02-15 23:33:37 +00:00
var result = golden.allocate("test", DataType.UBYTE, null, null, errors)
2022-12-02 22:58:21 +00:00
var alloc = result.getOrThrow()
alloc.size shouldBe 1
alloc.address shouldBe 0x400u
2023-02-15 23:33:37 +00:00
result = golden.allocate("test", DataType.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) {
2023-02-15 23:33:37 +00:00
result = golden.allocate("test", DataType.UWORD, null, null, errors)
2022-12-02 22:58:21 +00:00
alloc = result.getOrThrow()
alloc.size shouldBe 2
}
2023-02-15 23:33:37 +00:00
result = golden.allocate("test", DataType.UWORD, null, null, errors)
2022-12-02 22:58:21 +00:00
result.expectError { "just 1 more byte available" }
2023-02-15 23:33:37 +00:00
result = golden.allocate("test", DataType.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
2023-02-15 23:33:37 +00:00
result = golden.allocate("test", DataType.UBYTE, null, null, errors)
2022-12-02 22:58:21 +00:00
result.expectError { "nothing more available" }
}
})