* refactor compiler tests, again prog8test.helpers (TODO: remove duplication)

This commit is contained in:
meisl 2021-07-11 18:18:27 +02:00
parent 43c5ab8ecc
commit 5e194536a8
11 changed files with 173 additions and 169 deletions

View File

@ -1,11 +1,10 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.*
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test import prog8tests.helpers.*
import org.junit.jupiter.api.TestInstance
import prog8.ast.IBuiltinFunctions
import prog8.ast.IMemSizer
import prog8.ast.Module import prog8.ast.Module
import prog8.ast.Program import prog8.ast.Program
import prog8.ast.base.* import prog8.ast.base.*
@ -17,18 +16,9 @@ import prog8.compiler.target.c64.C64MachineDefinition
import prog8.compiler.target.cpu6502.codegen.AsmGen import prog8.compiler.target.cpu6502.codegen.AsmGen
import java.nio.file.Path import java.nio.file.Path
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestAsmGen6502 { class TestAsmGen6502 {
private class DummyFunctions: IBuiltinFunctions {
override val names: Set<String> = emptySet()
override val purefunctionNames: Set<String> = emptySet()
override fun constValue(name: String, args: List<Expression>, position: Position, memsizer: IMemSizer): NumericLiteralValue? = null
override fun returnType(name: String, args: MutableList<Expression>) = InferredTypes.InferredType.unknown()
}
private class DummyMemsizer: IMemSizer {
override fun memorySize(dt: DataType): Int = 0
}
private fun createTestProgram(): Program { private fun createTestProgram(): Program {
/* /*
@ -76,7 +66,7 @@ locallabel:
val module = Module("test", mutableListOf(block), Position.DUMMY, null) val module = Module("test", mutableListOf(block), Position.DUMMY, null)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.program = program module.program = program
return program return program
} }

101
compiler/test/Helpers.kt Normal file
View File

@ -0,0 +1,101 @@
package prog8tests.helpers
import kotlin.test.*
import kotlin.io.path.*
import java.nio.file.Path
import prog8.ast.IBuiltinFunctions
import prog8.ast.IMemSizer
import prog8.ast.IStringEncoding
import prog8.ast.base.DataType
import prog8.ast.base.Position
import prog8.ast.expressions.Expression
import prog8.ast.expressions.InferredTypes
import prog8.ast.expressions.NumericLiteralValue
import prog8.compiler.CompilationResult
import prog8.compiler.compileProgram
import prog8.compiler.target.ICompilationTarget
// TODO: find a way to share with compiler/test/Helpers.kt, while still being able to amend it (-> compileFixture(..))
internal fun compileFixture(
filename: String,
platform: ICompilationTarget,
optimize: Boolean = false
) : CompilationResult {
val filepath = fixturesDir.resolve(filename)
assumeReadableFile(filepath)
val result = compileProgram(
filepath,
optimize,
writeAssembly = true,
slowCodegenWarnings = false,
platform.name,
libdirs = listOf(),
outputDir
)
assertTrue(result.success, "compilation should succeed")
return result
}
val workingDir = Path("").absolute() // Note: Path(".") does NOT work..!
val fixturesDir = workingDir.resolve("test/fixtures")
val resourcesDir = workingDir.resolve("res")
val outputDir = workingDir.resolve("build/tmp/test")
inline fun assumeReadable(path: Path) {
assertTrue(path.isReadable(), "sanity check: should be readable: ${path.absolute()}")
}
inline fun assumeReadableFile(path: Path) {
assertTrue(path.isRegularFile(), "sanity check: should be normal file: ${path.absolute()}")
}
inline fun assumeDirectory(path: Path) {
assertTrue(path.isDirectory(), "sanity check; should be directory: $path")
}
inline fun assumeNotExists(path: Path) {
assertFalse(path.exists(), "sanity check: should not exist: ${path.absolute()}")
}
inline fun sanityCheckDirectories(workingDirName: String? = null) {
if (workingDirName != null)
assertEquals(workingDirName, workingDir.fileName.toString(), "name of current working dir")
assumeDirectory(workingDir)
assumeDirectory(fixturesDir)
assumeDirectory(resourcesDir)
assumeDirectory(outputDir)
}
val DummyEncoding = object : IStringEncoding {
override fun encodeString(str: String, altEncoding: Boolean): List<Short> {
TODO("Not yet implemented")
}
override fun decodeString(bytes: List<Short>, altEncoding: Boolean): String {
TODO("Not yet implemented")
}
}
val DummyFunctions = object : IBuiltinFunctions {
override val names: Set<String> = emptySet()
override val purefunctionNames: Set<String> = emptySet()
override fun constValue(
name: String,
args: List<Expression>,
position: Position,
memsizer: IMemSizer
): NumericLiteralValue? = null
override fun returnType(name: String, args: MutableList<Expression>) = InferredTypes.InferredType.unknown()
}
val DummyMemsizer = object : IMemSizer {
override fun memorySize(dt: DataType): Int = 0
}

View File

@ -1,16 +1,14 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.*
import org.junit.jupiter.api.TestInstance
import kotlin.io.path.*
import kotlin.test.* import kotlin.test.*
import prog8tests.helpers.*
import prog8.ast.IFunctionCall import prog8.ast.IFunctionCall
import prog8.ast.base.DataType import prog8.ast.base.DataType
import prog8.ast.base.VarDeclType import prog8.ast.base.VarDeclType
import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.IdentifierReference
import prog8.ast.expressions.NumericLiteralValue import prog8.ast.expressions.NumericLiteralValue
import prog8.compiler.compileProgram
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
@ -21,31 +19,16 @@ import prog8.compiler.target.Cx16Target
*/ */
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCompilerOnCharLit { class TestCompilerOnCharLit {
val workingDir = Path("").absolute() // Note: Path(".") does NOT work..!
val fixturesDir = workingDir.resolve("test/fixtures")
val outputDir = workingDir.resolve("build/tmp/test")
@Test @BeforeAll
fun sanityCheckDirectories() { fun setUp() {
assertEquals("compiler", workingDir.fileName.toString()) sanityCheckDirectories("compiler")
assertTrue(fixturesDir.isDirectory(), "sanity check; should be directory: $fixturesDir")
assertTrue(outputDir.isDirectory(), "sanity check; should be directory: $outputDir")
} }
@Test @Test
fun testCharLitAsRomsubArg() { fun testCharLitAsRomsubArg() {
val filepath = fixturesDir.resolve("charLitAsRomsubArg.p8") val platform = Cx16Target
val compilationTarget = Cx16Target val result = compileFixture("charLitAsRomsubArg.p8", platform)
val result = compileProgram(
filepath,
optimize = false,
writeAssembly = true,
slowCodegenWarnings = false,
compilationTarget.name,
libdirs = listOf(),
outputDir
)
assertTrue(result.success, "compilation should succeed")
val program = result.programAst val program = result.programAst
val startSub = program.entrypoint() val startSub = program.entrypoint()
@ -55,23 +38,14 @@ class TestCompilerOnCharLit {
"char literal should have been replaced by ubyte literal") "char literal should have been replaced by ubyte literal")
val arg = funCall.args[0] as NumericLiteralValue val arg = funCall.args[0] as NumericLiteralValue
assertEquals(DataType.UBYTE, arg.type) assertEquals(DataType.UBYTE, arg.type)
assertEquals(compilationTarget.encodeString("\n", false)[0], arg.number) assertEquals(platform.encodeString("\n", false)[0], arg.number)
} }
@Test @Test
fun testCharVarAsRomsubArg() { fun testCharVarAsRomsubArg() {
val filepath = fixturesDir.resolve("charVarAsRomsubArg.p8") val platform = Cx16Target
val compilationTarget = Cx16Target val result = compileFixture("charVarAsRomsubArg.p8", platform)
val result = compileProgram(
filepath,
optimize = false,
writeAssembly = true,
slowCodegenWarnings = false,
compilationTarget.name,
libdirs = listOf(),
outputDir
)
assertTrue(result.success, "compilation should succeed")
val program = result.programAst val program = result.programAst
val startSub = program.entrypoint() val startSub = program.entrypoint()
val funCall = startSub.statements.filterIsInstance<IFunctionCall>()[0] val funCall = startSub.statements.filterIsInstance<IFunctionCall>()[0]
@ -91,23 +65,14 @@ class TestCompilerOnCharLit {
"char literal should have been replaced by ubyte literal") "char literal should have been replaced by ubyte literal")
val initializerValue = decl.value as NumericLiteralValue val initializerValue = decl.value as NumericLiteralValue
assertEquals(DataType.UBYTE, initializerValue.type) assertEquals(DataType.UBYTE, initializerValue.type)
assertEquals(compilationTarget.encodeString("\n", false)[0], initializerValue.number) assertEquals(platform.encodeString("\n", false)[0], initializerValue.number)
} }
@Test @Test
fun testCharConstAsRomsubArg() { fun testCharConstAsRomsubArg() {
val filepath = fixturesDir.resolve("charConstAsRomsubArg.p8") val platform = Cx16Target
val compilationTarget = Cx16Target val result = compileFixture("charConstAsRomsubArg.p8", platform)
val result = compileProgram(
filepath,
optimize = false,
writeAssembly = true,
slowCodegenWarnings = false,
compilationTarget.name,
libdirs = listOf(),
outputDir
)
assertTrue(result.success, "compilation should succeed")
val program = result.programAst val program = result.programAst
val startSub = program.entrypoint() val startSub = program.entrypoint()
val funCall = startSub.statements.filterIsInstance<IFunctionCall>()[0] val funCall = startSub.statements.filterIsInstance<IFunctionCall>()[0]
@ -119,12 +84,12 @@ class TestCompilerOnCharLit {
assertEquals(VarDeclType.CONST, decl.type) assertEquals(VarDeclType.CONST, decl.type)
assertEquals(DataType.UBYTE, decl.datatype) assertEquals(DataType.UBYTE, decl.datatype)
assertEquals( assertEquals(
compilationTarget.encodeString("\n", false)[0], platform.encodeString("\n", false)[0],
(decl.value as NumericLiteralValue).number) (decl.value as NumericLiteralValue).number)
} }
is NumericLiteralValue -> { is NumericLiteralValue -> {
assertEquals( assertEquals(
compilationTarget.encodeString("\n", false)[0], platform.encodeString("\n", false)[0],
arg.number) arg.number)
} }
else -> assertIs<IdentifierReference>(funCall.args[0]) // make test fail else -> assertIs<IdentifierReference>(funCall.args[0]) // make test fail

View File

@ -1,9 +1,8 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.*
import org.junit.jupiter.api.TestInstance
import kotlin.test.* import kotlin.test.*
import kotlin.io.path.* import prog8tests.helpers.*
import prog8.compiler.compileProgram import prog8.compiler.compileProgram
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
@ -17,21 +16,17 @@ import prog8.compiler.target.ICompilationTarget
*/ */
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCompilerOnExamples { class TestCompilerOnExamples {
val workingDir = Path("").absolute() // Note: Path(".") does NOT work..! private val examplesDir = workingDir.resolve("../examples")
val examplesDir = workingDir.resolve("../examples")
val outputDir = workingDir.resolve("build/tmp/test")
@BeforeAll
@Test fun setUp() {
fun sanityCheckDirectories() { sanityCheckDirectories("compiler")
assertEquals("compiler", workingDir.fileName.toString()) assumeDirectory(examplesDir)
assertTrue(examplesDir.isDirectory(), "sanity check; should be directory: $examplesDir")
assertTrue(outputDir.isDirectory(), "sanity check; should be directory: $outputDir")
} }
// TODO: make assembly stage testable - in case of failure (eg of 64tass) it Process.exit s // TODO: make assembly stage testable - in case of failure (eg of 64tass) it Process.exit s
fun testExample(nameWithoutExt: String, platform: ICompilationTarget, optimize: Boolean) { private fun testExample(nameWithoutExt: String, platform: ICompilationTarget, optimize: Boolean) {
val filepath = examplesDir.resolve("$nameWithoutExt.p8") val filepath = examplesDir.resolve("$nameWithoutExt.p8")
val result = compileProgram( val result = compileProgram(
filepath, filepath,

View File

@ -1,9 +1,8 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.*
import org.junit.jupiter.api.TestInstance
import kotlin.io.path.*
import kotlin.test.* import kotlin.test.*
import prog8tests.helpers.*
import prog8.ast.expressions.AddressOf import prog8.ast.expressions.AddressOf
import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.IdentifierReference
@ -12,6 +11,7 @@ import prog8.ast.statements.FunctionCallStatement
import prog8.ast.statements.Label import prog8.ast.statements.Label
import prog8.compiler.compileProgram import prog8.compiler.compileProgram
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
import kotlin.io.path.name
/** /**
@ -21,36 +21,21 @@ import prog8.compiler.target.Cx16Target
*/ */
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCompilerOnImportsAndIncludes { class TestCompilerOnImportsAndIncludes {
val workingDir = Path("").absolute() // Note: Path(".") does NOT work..!
val fixturesDir = workingDir.resolve("test/fixtures")
val outputDir = workingDir.resolve("build/tmp/test")
@Test @BeforeAll
fun sanityCheckDirectories() { fun setUp() {
assertEquals("compiler", workingDir.fileName.toString()) sanityCheckDirectories("compiler")
assertTrue(fixturesDir.isDirectory(), "sanity check; should be directory: $fixturesDir")
assertTrue(outputDir.isDirectory(), "sanity check; should be directory: $outputDir")
} }
@Test @Test
fun testImportFromSameFolder() { fun testImportFromSameFolder() {
val filepath = fixturesDir.resolve("importFromSameFolder.p8") val filepath = fixturesDir.resolve("importFromSameFolder.p8")
val imported = fixturesDir.resolve("foo_bar.p8") val imported = fixturesDir.resolve("foo_bar.p8")
assumeReadableFile(filepath)
assumeReadableFile(imported)
assertTrue(filepath.isRegularFile(), "sanity check; should be regular file: $filepath") val platform = Cx16Target
assertTrue(imported.isRegularFile(), "sanity check; should be regular file: $imported") val result = compileFixture(filepath.name, platform)
val compilationTarget = Cx16Target
val result = compileProgram(
filepath,
optimize = false,
writeAssembly = true,
slowCodegenWarnings = false,
compilationTarget.name,
libdirs = listOf(),
outputDir
)
assertTrue(result.success, "compilation should succeed")
val program = result.programAst val program = result.programAst
val startSub = program.entrypoint() val startSub = program.entrypoint()
@ -69,21 +54,11 @@ class TestCompilerOnImportsAndIncludes {
fun testAsmIncludeFromSameFolder() { fun testAsmIncludeFromSameFolder() {
val filepath = fixturesDir.resolve("asmIncludeFromSameFolder.p8") val filepath = fixturesDir.resolve("asmIncludeFromSameFolder.p8")
val included = fixturesDir.resolve("foo_bar.asm") val included = fixturesDir.resolve("foo_bar.asm")
assumeReadableFile(filepath)
assumeReadableFile(included)
assertTrue(filepath.isRegularFile(), "sanity check; should be regular file: $filepath") val platform = Cx16Target
assertTrue(included.isRegularFile(), "sanity check; should be regular file: $included") val result = compileFixture(filepath.name, platform)
val compilationTarget = Cx16Target
val result = compileProgram(
filepath,
optimize = false,
writeAssembly = true,
slowCodegenWarnings = false,
compilationTarget.name,
libdirs = listOf(),
outputDir
)
assertTrue(result.success, "compilation should succeed")
val program = result.programAst val program = result.programAst
val startSub = program.entrypoint() val startSub = program.entrypoint()

View File

@ -1,8 +1,9 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.*
import prog8.ast.IBuiltinFunctions import kotlin.test.*
import prog8.ast.IMemSizer import prog8tests.helpers.*
import prog8.ast.Module import prog8.ast.Module
import prog8.ast.Program import prog8.ast.Program
import prog8.ast.base.DataType import prog8.ast.base.DataType
@ -12,29 +13,16 @@ import prog8.ast.base.VarDeclType
import prog8.ast.expressions.* import prog8.ast.expressions.*
import prog8.ast.statements.* import prog8.ast.statements.*
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
import java.nio.file.Path
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestMemory { class TestMemory {
private class DummyFunctions: IBuiltinFunctions {
override val names: Set<String> = emptySet()
override val purefunctionNames: Set<String> = emptySet()
override fun constValue(name: String, args: List<Expression>, position: Position, memsizer: IMemSizer): NumericLiteralValue? = null
override fun returnType(name: String, args: MutableList<Expression>) = InferredTypes.InferredType.unknown()
}
private class DummyMemsizer: IMemSizer {
override fun memorySize(dt: DataType): Int = 0
}
@Test @Test
fun testInValidRamC64_memory_addresses() { fun testInValidRamC64_memory_addresses() {
var memexpr = NumericLiteralValue.optimalInteger(0x0000, Position.DUMMY) var memexpr = NumericLiteralValue.optimalInteger(0x0000, Position.DUMMY)
var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY) var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
val program = Program("test", mutableListOf(), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(), DummyFunctions, DummyMemsizer)
assertTrue(C64Target.isInRegularRAM(target, program)) assertTrue(C64Target.isInRegularRAM(target, program))
memexpr = NumericLiteralValue.optimalInteger(0x1000, Position.DUMMY) memexpr = NumericLiteralValue.optimalInteger(0x1000, Position.DUMMY)
@ -59,7 +47,7 @@ class TestMemory {
var memexpr = NumericLiteralValue.optimalInteger(0xa000, Position.DUMMY) var memexpr = NumericLiteralValue.optimalInteger(0xa000, Position.DUMMY)
var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY) var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
val program = Program("test", mutableListOf(), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(), DummyFunctions, DummyMemsizer)
assertFalse(C64Target.isInRegularRAM(target, program)) assertFalse(C64Target.isInRegularRAM(target, program))
memexpr = NumericLiteralValue.optimalInteger(0xafff, Position.DUMMY) memexpr = NumericLiteralValue.optimalInteger(0xafff, Position.DUMMY)
@ -78,7 +66,7 @@ class TestMemory {
@Test @Test
fun testInValidRamC64_memory_identifiers() { fun testInValidRamC64_memory_identifiers() {
var target = createTestProgramForMemoryRefViaVar(0x1000, VarDeclType.VAR) var target = createTestProgramForMemoryRefViaVar(0x1000, VarDeclType.VAR)
val program = Program("test", mutableListOf(), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(), DummyFunctions, DummyMemsizer)
assertTrue(C64Target.isInRegularRAM(target, program)) assertTrue(C64Target.isInRegularRAM(target, program))
target = createTestProgramForMemoryRefViaVar(0xd020, VarDeclType.VAR) target = createTestProgramForMemoryRefViaVar(0xd020, VarDeclType.VAR)
@ -107,7 +95,7 @@ class TestMemory {
fun testInValidRamC64_memory_expression() { fun testInValidRamC64_memory_expression() {
val memexpr = PrefixExpression("+", NumericLiteralValue.optimalInteger(0x1000, Position.DUMMY), Position.DUMMY) val memexpr = PrefixExpression("+", NumericLiteralValue.optimalInteger(0x1000, Position.DUMMY), Position.DUMMY)
val target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY) val target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
val program = Program("test", mutableListOf(), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(), DummyFunctions, DummyMemsizer)
assertFalse(C64Target.isInRegularRAM(target, program)) assertFalse(C64Target.isInRegularRAM(target, program))
} }
@ -118,7 +106,7 @@ class TestMemory {
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY) val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY) val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null) val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
assertTrue(C64Target.isInRegularRAM(target, program)) assertTrue(C64Target.isInRegularRAM(target, program))
} }
@ -131,7 +119,7 @@ class TestMemory {
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY) val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY) val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null) val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
assertTrue(C64Target.isInRegularRAM(target, program)) assertTrue(C64Target.isInRegularRAM(target, program))
} }
@ -144,7 +132,7 @@ class TestMemory {
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY) val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY) val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null) val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
assertFalse(C64Target.isInRegularRAM(target, program)) assertFalse(C64Target.isInRegularRAM(target, program))
} }
@ -157,7 +145,7 @@ class TestMemory {
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY) val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY) val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null) val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
assertTrue(C64Target.isInRegularRAM(target, program)) assertTrue(C64Target.isInRegularRAM(target, program))
} }
@ -171,7 +159,7 @@ class TestMemory {
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY) val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY) val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null) val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
assertTrue(C64Target.isInRegularRAM(target, program)) assertTrue(C64Target.isInRegularRAM(target, program))
} }
@ -185,7 +173,7 @@ class TestMemory {
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY) val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY) val subroutine = Subroutine("test", emptyList(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null) val module = Module("test", mutableListOf(subroutine), Position.DUMMY, null)
val program = Program("test", mutableListOf(module), DummyFunctions(), DummyMemsizer()) val program = Program("test", mutableListOf(module), DummyFunctions, DummyMemsizer)
module.linkParents(ParentSentinel) module.linkParents(ParentSentinel)
assertFalse(C64Target.isInRegularRAM(target, program)) assertFalse(C64Target.isInRegularRAM(target, program))
} }

View File

@ -1,17 +1,16 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.*
import kotlin.test.*
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.closeTo import org.hamcrest.Matchers.closeTo
import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import prog8.ast.toHex import prog8.ast.toHex
import prog8.compiler.CompilerException import prog8.compiler.CompilerException
import prog8.compiler.target.c64.C64MachineDefinition.FLOAT_MAX_NEGATIVE import prog8.compiler.target.c64.C64MachineDefinition.FLOAT_MAX_NEGATIVE
import prog8.compiler.target.c64.C64MachineDefinition.FLOAT_MAX_POSITIVE import prog8.compiler.target.c64.C64MachineDefinition.FLOAT_MAX_POSITIVE
import prog8.compiler.target.c64.C64MachineDefinition.Mflpt5 import prog8.compiler.target.c64.C64MachineDefinition.Mflpt5
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestNumbers { class TestNumbers {

View File

@ -1,19 +1,14 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.*
import org.junit.jupiter.api.TestInstance import kotlin.test.*
import prog8.ast.base.DataType import prog8.ast.base.DataType
import prog8.ast.base.Position import prog8.ast.base.Position
import prog8.ast.expressions.ArrayLiteralValue import prog8.ast.expressions.ArrayLiteralValue
import prog8.ast.expressions.InferredTypes import prog8.ast.expressions.InferredTypes
import prog8.ast.expressions.NumericLiteralValue import prog8.ast.expressions.NumericLiteralValue
import prog8.ast.expressions.StringLiteralValue import prog8.ast.expressions.StringLiteralValue
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestNumericLiteralValue { class TestNumericLiteralValue {

View File

@ -1,15 +1,15 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.*
import kotlin.test.*
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import prog8.ast.base.DataType import prog8.ast.base.DataType
import prog8.ast.base.Position import prog8.ast.base.Position
import prog8.ast.expressions.NumericLiteralValue import prog8.ast.expressions.NumericLiteralValue
import prog8.ast.expressions.StringLiteralValue import prog8.ast.expressions.StringLiteralValue
import prog8.compiler.target.cbm.Petscii import prog8.compiler.target.cbm.Petscii
import kotlin.test.*
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)

View File

@ -1,17 +1,14 @@
package prog8tests package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.*
import org.junit.jupiter.api.TestInstance import kotlin.test.*
import prog8.ast.base.DataType import prog8.ast.base.DataType
import prog8.compiler.* import prog8.compiler.*
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
import prog8.compiler.target.c64.C64MachineDefinition.C64Zeropage import prog8.compiler.target.c64.C64MachineDefinition.C64Zeropage
import prog8.compiler.target.cx16.CX16MachineDefinition.CX16Zeropage import prog8.compiler.target.cx16.CX16MachineDefinition.CX16Zeropage
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)

View File

@ -47,7 +47,6 @@ inline fun sanityCheckDirectories(workingDirName: String? = null) {
} }
val DummyEncoding = object : IStringEncoding { val DummyEncoding = object : IStringEncoding {
override fun encodeString(str: String, altEncoding: Boolean): List<Short> { override fun encodeString(str: String, altEncoding: Boolean): List<Short> {
TODO("Not yet implemented") TODO("Not yet implemented")