From e1026584c84516d4a9e24cb05be75b5ec9676bfc Mon Sep 17 00:00:00 2001 From: meisl Date: Fri, 30 Jul 2021 17:39:43 +0200 Subject: [PATCH] * split up test helpers into separate files, move mapCombinations(..) down to compilerAst/test/helpers since they're generic and don't depend on compiler --- .../{Helpers@compiler.kt => compileXyz.kt} | 33 +------------------ compilerAst/test/helpers/DummyFunctions.kt | 21 ++++++++++++ compilerAst/test/helpers/DummyMemsizer.kt | 8 +++++ compilerAst/test/helpers/mapCombinations.kt | 25 ++++++++++++++ .../{Helpers@compilerAst.kt => paths.kt} | 26 --------------- 5 files changed, 55 insertions(+), 58 deletions(-) rename compiler/test/helpers/{Helpers@compiler.kt => compileXyz.kt} (61%) create mode 100644 compilerAst/test/helpers/DummyFunctions.kt create mode 100644 compilerAst/test/helpers/DummyMemsizer.kt create mode 100644 compilerAst/test/helpers/mapCombinations.kt rename compilerAst/test/helpers/{Helpers@compilerAst.kt => paths.kt} (59%) diff --git a/compiler/test/helpers/Helpers@compiler.kt b/compiler/test/helpers/compileXyz.kt similarity index 61% rename from compiler/test/helpers/Helpers@compiler.kt rename to compiler/test/helpers/compileXyz.kt index 85c1f5934..1862b7e01 100644 --- a/compiler/test/helpers/Helpers@compiler.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -4,17 +4,11 @@ import kotlin.test.* import kotlin.io.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.compileProgram import prog8.compiler.target.ICompilationTarget + internal fun CompilationResult.assertSuccess(description: String = ""): CompilationResult { assertTrue(success, "expected successful compilation but failed $description") return this @@ -64,28 +58,3 @@ internal fun compileText( filePath.toFile().writeText(sourceText) return compileFile(platform, optimize, filePath.parent, filePath.name) } - - -fun mapCombinations(dim1: Iterable, dim2: Iterable, combine2: (A, B) -> R) = - sequence { - for (a in dim1) - for (b in dim2) - yield(combine2(a, b)) - }.toList() - -fun mapCombinations(dim1: Iterable, dim2: Iterable, dim3: Iterable, 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 mapCombinations(dim1: Iterable, dim2: Iterable, dim3: Iterable, dim4: Iterable, 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() diff --git a/compilerAst/test/helpers/DummyFunctions.kt b/compilerAst/test/helpers/DummyFunctions.kt new file mode 100644 index 000000000..e212ea9ea --- /dev/null +++ b/compilerAst/test/helpers/DummyFunctions.kt @@ -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 = emptySet() + override val purefunctionNames: Set = emptySet() + override fun constValue( + name: String, + args: List, + position: Position, + memsizer: IMemSizer + ): NumericLiteralValue? = null + + override fun returnType(name: String, args: MutableList) = InferredTypes.InferredType.unknown() +} \ No newline at end of file diff --git a/compilerAst/test/helpers/DummyMemsizer.kt b/compilerAst/test/helpers/DummyMemsizer.kt new file mode 100644 index 000000000..3d226437d --- /dev/null +++ b/compilerAst/test/helpers/DummyMemsizer.kt @@ -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 +} \ No newline at end of file diff --git a/compilerAst/test/helpers/mapCombinations.kt b/compilerAst/test/helpers/mapCombinations.kt new file mode 100644 index 000000000..e96734cb1 --- /dev/null +++ b/compilerAst/test/helpers/mapCombinations.kt @@ -0,0 +1,25 @@ +package prog8tests.helpers + +fun mapCombinations(dim1: Iterable, dim2: Iterable, combine2: (A, B) -> R) = + sequence { + for (a in dim1) + for (b in dim2) + yield(combine2(a, b)) + }.toList() + +fun mapCombinations(dim1: Iterable, dim2: Iterable, dim3: Iterable, 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 mapCombinations(dim1: Iterable, dim2: Iterable, dim3: Iterable, dim4: Iterable, 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() \ No newline at end of file diff --git a/compilerAst/test/helpers/Helpers@compilerAst.kt b/compilerAst/test/helpers/paths.kt similarity index 59% rename from compilerAst/test/helpers/Helpers@compilerAst.kt rename to compilerAst/test/helpers/paths.kt index 1a59142a9..65c5de9fd 100644 --- a/compilerAst/test/helpers/Helpers@compilerAst.kt +++ b/compilerAst/test/helpers/paths.kt @@ -3,13 +3,6 @@ package prog8tests.helpers import kotlin.test.* 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 @@ -43,22 +36,3 @@ fun sanityCheckDirectories(workingDirName: String? = null) { assumeDirectory(resourcesDir) assumeDirectory(outputDir) } - - -val DummyFunctions = object : IBuiltinFunctions { - override val names: Set = emptySet() - override val purefunctionNames: Set = emptySet() - override fun constValue( - name: String, - args: List, - position: Position, - memsizer: IMemSizer - ): NumericLiteralValue? = null - - override fun returnType(name: String, args: MutableList) = InferredTypes.InferredType.unknown() -} - -val DummyMemsizer = object : IMemSizer { - override fun memorySize(dt: DataType): Int = 0 -} -