mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
adding tests to the new project's submodules
This commit is contained in:
parent
5ff481ce3c
commit
82da8f4946
@ -20,6 +20,11 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
||||||
|
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
|
||||||
|
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||||
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
|
@ -4,11 +4,14 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
|
||||||
<orderEntry type="module" module-name="compilerInterfaces" />
|
<orderEntry type="module" module-name="compilerInterfaces" />
|
||||||
<orderEntry type="module" module-name="compilerAst" />
|
<orderEntry type="module" module-name="compilerAst" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="hamcrest" level="project" />
|
||||||
|
<orderEntry type="library" name="junit.jupiter" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
21
codeOptimizers/test/TestOptimizers.kt
Normal file
21
codeOptimizers/test/TestOptimizers.kt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package prog8tests
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
|
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
|
class TestOptimizers {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled("for future implementation")
|
||||||
|
fun dummy() {
|
||||||
|
fail("dummy")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,11 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
||||||
|
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
|
||||||
|
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||||
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime (3)" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime (3)" level="project" />
|
||||||
<orderEntry type="module" module-name="compilerAst" />
|
<orderEntry type="module" module-name="compilerAst" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="hamcrest" level="project" />
|
||||||
|
<orderEntry type="library" name="junit.jupiter" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -74,6 +74,7 @@ fun RangeExpr.toConstantIntegerRange(encoding: IStringEncoding): IntProgression?
|
|||||||
val fromString = from as? StringLiteralValue
|
val fromString = from as? StringLiteralValue
|
||||||
val toString = to as? StringLiteralValue
|
val toString = to as? StringLiteralValue
|
||||||
if(fromString!=null && toString!=null ) {
|
if(fromString!=null && toString!=null ) {
|
||||||
|
// TODO WHAT IS A STRING RANGE??????
|
||||||
// string range -> int range over character values
|
// string range -> int range over character values
|
||||||
fromVal = encoding.encodeString(fromString.value, fromString.altEncoding)[0].toInt()
|
fromVal = encoding.encodeString(fromString.value, fromString.altEncoding)[0].toInt()
|
||||||
toVal = encoding.encodeString(toString.value, fromString.altEncoding)[0].toInt()
|
toVal = encoding.encodeString(toString.value, fromString.altEncoding)[0].toInt()
|
||||||
|
36
compilerInterfaces/test/TestAstExtensions.kt
Normal file
36
compilerInterfaces/test/TestAstExtensions.kt
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package prog8tests
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
import prog8.ast.base.Position
|
||||||
|
import prog8.ast.expressions.NumericLiteralValue
|
||||||
|
import prog8.ast.expressions.RangeExpr
|
||||||
|
import prog8.compilerinterface.*
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
|
class TestAstExtensions {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testRangeExprNumericSize() {
|
||||||
|
val expr = RangeExpr(
|
||||||
|
NumericLiteralValue.optimalInteger(10, Position.DUMMY),
|
||||||
|
NumericLiteralValue.optimalInteger(20, Position.DUMMY),
|
||||||
|
NumericLiteralValue.optimalInteger(2, Position.DUMMY),
|
||||||
|
Position.DUMMY)
|
||||||
|
val encoding = DummyStringEncoding()
|
||||||
|
assertEquals(6, expr.size(encoding))
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyStringEncoding : 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")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
71
compilerInterfaces/test/TestZeropage.kt
Normal file
71
compilerInterfaces/test/TestZeropage.kt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package prog8tests
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
import prog8.ast.base.DataType
|
||||||
|
import prog8.compilerinterface.*
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
|
class TestZeropage {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testAbstractZeropage() {
|
||||||
|
val compTarget = DummyCompilationTarget()
|
||||||
|
val zp = DummyZeropage(
|
||||||
|
CompilationOptions(
|
||||||
|
OutputType.RAW,
|
||||||
|
LauncherType.NONE,
|
||||||
|
ZeropageType.FULL,
|
||||||
|
listOf((0x50..0x5f)),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
compTarget
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertEquals(256-4-16, zp.free.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyCompilationTarget: ICompilationTarget {
|
||||||
|
override val name: String
|
||||||
|
get() = TODO("Not yet implemented")
|
||||||
|
override val machine: IMachineDefinition
|
||||||
|
get() = TODO("Not yet implemented")
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun memorySize(dt: DataType): Int {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyZeropage(options: CompilationOptions) : Zeropage(options) {
|
||||||
|
override val SCRATCH_B1: Int = 0x10
|
||||||
|
override val SCRATCH_REG: Int = 0x11
|
||||||
|
override val SCRATCH_W1: Int= 0x12
|
||||||
|
override val SCRATCH_W2: Int = 0x13
|
||||||
|
|
||||||
|
init {
|
||||||
|
free.addAll(0..255)
|
||||||
|
|
||||||
|
// TODO should be in class:
|
||||||
|
free.remove(SCRATCH_B1)
|
||||||
|
free.remove(SCRATCH_REG)
|
||||||
|
free.remove(SCRATCH_W1)
|
||||||
|
free.remove(SCRATCH_W2)
|
||||||
|
|
||||||
|
// TODO should be in class:
|
||||||
|
for (reserved in options.zpReserved)
|
||||||
|
reserve(reserved)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user