mirror of
https://github.com/irmen/prog8.git
synced 2024-11-30 08:52:30 +00:00
af7cc9c761
# Conflicts: # codeCore/src/prog8/code/ast/AstExpressions.kt # codeCore/src/prog8/code/core/BuiltinFunctions.kt # codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt # codeGenCpu6502/src/prog8/codegen/cpu6502/BuiltinFunctionsAsmGen.kt # compiler/test/ast/TestIntermediateAst.kt
46 lines
2.2 KiB
Kotlin
46 lines
2.2 KiB
Kotlin
package prog8tests.ast
|
|
|
|
import io.kotest.assertions.fail
|
|
import io.kotest.core.spec.style.FunSpec
|
|
import io.kotest.matchers.ints.shouldBeGreaterThan
|
|
import io.kotest.matchers.shouldBe
|
|
import io.kotest.matchers.types.instanceOf
|
|
import prog8.code.ast.*
|
|
import prog8.code.core.BaseDataType
|
|
import prog8.code.core.DataType
|
|
import prog8.code.core.Position
|
|
import prog8.code.target.C64Target
|
|
import prog8.compiler.astprocessing.IntermediateAstMaker
|
|
import prog8tests.helpers.ErrorReporterForTests
|
|
import prog8tests.helpers.compileText
|
|
|
|
class TestIntermediateAst: FunSpec({
|
|
|
|
test("isSame on binaryExpressions") {
|
|
val expr1 = PtBinaryExpression("/", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
|
|
expr1.add(PtNumber(BaseDataType.UBYTE, 1.0, Position.DUMMY))
|
|
expr1.add(PtNumber(BaseDataType.UBYTE, 2.0, Position.DUMMY))
|
|
val expr2 = PtBinaryExpression("/", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
|
|
expr2.add(PtNumber(BaseDataType.UBYTE, 1.0, Position.DUMMY))
|
|
expr2.add(PtNumber(BaseDataType.UBYTE, 2.0, Position.DUMMY))
|
|
(expr1 isSameAs expr2) shouldBe true
|
|
val expr3 = PtBinaryExpression("/", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
|
|
expr3.add(PtNumber(BaseDataType.UBYTE, 2.0, Position.DUMMY))
|
|
expr3.add(PtNumber(BaseDataType.UBYTE, 1.0, Position.DUMMY))
|
|
(expr1 isSameAs expr3) shouldBe false
|
|
}
|
|
|
|
test("isSame on binaryExpressions with associative operators") {
|
|
val expr1 = PtBinaryExpression("+", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
|
|
expr1.add(PtNumber(BaseDataType.UBYTE, 1.0, Position.DUMMY))
|
|
expr1.add(PtNumber(BaseDataType.UBYTE, 2.0, Position.DUMMY))
|
|
val expr2 = PtBinaryExpression("+", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
|
|
expr2.add(PtNumber(BaseDataType.UBYTE, 1.0, Position.DUMMY))
|
|
expr2.add(PtNumber(BaseDataType.UBYTE, 2.0, Position.DUMMY))
|
|
(expr1 isSameAs expr2) shouldBe true
|
|
val expr3 = PtBinaryExpression("+", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
|
|
expr3.add(PtNumber(BaseDataType.UBYTE, 2.0, Position.DUMMY))
|
|
expr3.add(PtNumber(BaseDataType.UBYTE, 1.0, Position.DUMMY))
|
|
(expr1 isSameAs expr3) shouldBe true
|
|
}
|
|
}) |