mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
* split up test helpers into separate files, move mapCombinations(..) down to compilerAst/test/helpers since they're generic and don't depend on compiler
This commit is contained in:
parent
4c615e4fac
commit
e1026584c8
@ -4,17 +4,11 @@ import kotlin.test.*
|
|||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
import prog8.ast.IBuiltinFunctions
|
|
||||||
import prog8.ast.IMemSizer
|
|
||||||
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.CompilationResult
|
||||||
import prog8.compiler.compileProgram
|
import prog8.compiler.compileProgram
|
||||||
import prog8.compiler.target.ICompilationTarget
|
import prog8.compiler.target.ICompilationTarget
|
||||||
|
|
||||||
|
|
||||||
internal fun CompilationResult.assertSuccess(description: String = ""): CompilationResult {
|
internal fun CompilationResult.assertSuccess(description: String = ""): CompilationResult {
|
||||||
assertTrue(success, "expected successful compilation but failed $description")
|
assertTrue(success, "expected successful compilation but failed $description")
|
||||||
return this
|
return this
|
||||||
@ -64,28 +58,3 @@ internal fun compileText(
|
|||||||
filePath.toFile().writeText(sourceText)
|
filePath.toFile().writeText(sourceText)
|
||||||
return compileFile(platform, optimize, filePath.parent, filePath.name)
|
return compileFile(platform, optimize, filePath.parent, filePath.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun <A, B, R> mapCombinations(dim1: Iterable<A>, dim2: Iterable<B>, combine2: (A, B) -> R) =
|
|
||||||
sequence {
|
|
||||||
for (a in dim1)
|
|
||||||
for (b in dim2)
|
|
||||||
yield(combine2(a, b))
|
|
||||||
}.toList()
|
|
||||||
|
|
||||||
fun <A, B, C, R> mapCombinations(dim1: Iterable<A>, dim2: Iterable<B>, dim3: Iterable<C>, combine3: (A, B, C) -> R) =
|
|
||||||
sequence {
|
|
||||||
for (a in dim1)
|
|
||||||
for (b in dim2)
|
|
||||||
for (c in dim3)
|
|
||||||
yield(combine3(a, b, c))
|
|
||||||
}.toList()
|
|
||||||
|
|
||||||
fun <A, B, C, D, R> mapCombinations(dim1: Iterable<A>, dim2: Iterable<B>, dim3: Iterable<C>, dim4: Iterable<D>, combine4: (A, B, C, D) -> R) =
|
|
||||||
sequence {
|
|
||||||
for (a in dim1)
|
|
||||||
for (b in dim2)
|
|
||||||
for (c in dim3)
|
|
||||||
for (d in dim4)
|
|
||||||
yield(combine4(a, b, c, d))
|
|
||||||
}.toList()
|
|
21
compilerAst/test/helpers/DummyFunctions.kt
Normal file
21
compilerAst/test/helpers/DummyFunctions.kt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package prog8tests.helpers
|
||||||
|
|
||||||
|
import prog8.ast.IBuiltinFunctions
|
||||||
|
import prog8.ast.IMemSizer
|
||||||
|
import prog8.ast.base.Position
|
||||||
|
import prog8.ast.expressions.Expression
|
||||||
|
import prog8.ast.expressions.InferredTypes
|
||||||
|
import prog8.ast.expressions.NumericLiteralValue
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
8
compilerAst/test/helpers/DummyMemsizer.kt
Normal file
8
compilerAst/test/helpers/DummyMemsizer.kt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package prog8tests.helpers
|
||||||
|
|
||||||
|
import prog8.ast.IMemSizer
|
||||||
|
import prog8.ast.base.DataType
|
||||||
|
|
||||||
|
val DummyMemsizer = object : IMemSizer {
|
||||||
|
override fun memorySize(dt: DataType): Int = 0
|
||||||
|
}
|
25
compilerAst/test/helpers/mapCombinations.kt
Normal file
25
compilerAst/test/helpers/mapCombinations.kt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package prog8tests.helpers
|
||||||
|
|
||||||
|
fun <A, B, R> mapCombinations(dim1: Iterable<A>, dim2: Iterable<B>, combine2: (A, B) -> R) =
|
||||||
|
sequence {
|
||||||
|
for (a in dim1)
|
||||||
|
for (b in dim2)
|
||||||
|
yield(combine2(a, b))
|
||||||
|
}.toList()
|
||||||
|
|
||||||
|
fun <A, B, C, R> mapCombinations(dim1: Iterable<A>, dim2: Iterable<B>, dim3: Iterable<C>, combine3: (A, B, C) -> R) =
|
||||||
|
sequence {
|
||||||
|
for (a in dim1)
|
||||||
|
for (b in dim2)
|
||||||
|
for (c in dim3)
|
||||||
|
yield(combine3(a, b, c))
|
||||||
|
}.toList()
|
||||||
|
|
||||||
|
fun <A, B, C, D, R> mapCombinations(dim1: Iterable<A>, dim2: Iterable<B>, dim3: Iterable<C>, dim4: Iterable<D>, combine4: (A, B, C, D) -> R) =
|
||||||
|
sequence {
|
||||||
|
for (a in dim1)
|
||||||
|
for (b in dim2)
|
||||||
|
for (c in dim3)
|
||||||
|
for (d in dim4)
|
||||||
|
yield(combine4(a, b, c, d))
|
||||||
|
}.toList()
|
@ -3,13 +3,6 @@ package prog8tests.helpers
|
|||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
import prog8.ast.IBuiltinFunctions
|
|
||||||
import prog8.ast.IMemSizer
|
|
||||||
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 java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
|
||||||
@ -43,22 +36,3 @@ fun sanityCheckDirectories(workingDirName: String? = null) {
|
|||||||
assumeDirectory(resourcesDir)
|
assumeDirectory(resourcesDir)
|
||||||
assumeDirectory(outputDir)
|
assumeDirectory(outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user