2022-03-06 16:29:30 +00:00
|
|
|
package prog8tests.ast
|
|
|
|
|
2022-03-06 19:35:15 +00:00
|
|
|
import io.kotest.assertions.fail
|
2022-03-06 16:29:30 +00:00
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2022-03-06 19:35:15 +00:00
|
|
|
import io.kotest.matchers.ints.shouldBeGreaterThan
|
2022-03-06 16:29:30 +00:00
|
|
|
import io.kotest.matchers.shouldBe
|
2024-02-04 22:41:01 +00:00
|
|
|
import io.kotest.matchers.types.instanceOf
|
2022-03-21 00:01:21 +00:00
|
|
|
import prog8.code.ast.*
|
2023-08-13 22:50:40 +00:00
|
|
|
import prog8.code.core.DataType
|
2024-01-01 13:55:29 +00:00
|
|
|
import prog8.code.core.Position
|
2022-03-11 19:35:25 +00:00
|
|
|
import prog8.code.target.C64Target
|
2022-08-14 11:06:11 +00:00
|
|
|
import prog8.compiler.astprocessing.IntermediateAstMaker
|
2023-10-03 20:54:28 +00:00
|
|
|
import prog8tests.helpers.ErrorReporterForTests
|
2022-03-06 16:29:30 +00:00
|
|
|
import prog8tests.helpers.compileText
|
|
|
|
|
|
|
|
class TestIntermediateAst: FunSpec({
|
|
|
|
|
2024-01-01 13:55:29 +00:00
|
|
|
test("isSame on binaryExpressions") {
|
|
|
|
val expr1 = PtBinaryExpression("/", DataType.UBYTE, Position.DUMMY)
|
|
|
|
expr1.add(PtNumber(DataType.UBYTE, 1.0, Position.DUMMY))
|
|
|
|
expr1.add(PtNumber(DataType.UBYTE, 2.0, Position.DUMMY))
|
|
|
|
val expr2 = PtBinaryExpression("/", DataType.UBYTE, Position.DUMMY)
|
|
|
|
expr2.add(PtNumber(DataType.UBYTE, 1.0, Position.DUMMY))
|
|
|
|
expr2.add(PtNumber(DataType.UBYTE, 2.0, Position.DUMMY))
|
|
|
|
(expr1 isSameAs expr2) shouldBe true
|
|
|
|
val expr3 = PtBinaryExpression("/", DataType.UBYTE, Position.DUMMY)
|
|
|
|
expr3.add(PtNumber(DataType.UBYTE, 2.0, Position.DUMMY))
|
|
|
|
expr3.add(PtNumber(DataType.UBYTE, 1.0, Position.DUMMY))
|
|
|
|
(expr1 isSameAs expr3) shouldBe false
|
|
|
|
}
|
|
|
|
|
|
|
|
test("isSame on binaryExpressions with associative operators") {
|
|
|
|
val expr1 = PtBinaryExpression("+", DataType.UBYTE, Position.DUMMY)
|
|
|
|
expr1.add(PtNumber(DataType.UBYTE, 1.0, Position.DUMMY))
|
|
|
|
expr1.add(PtNumber(DataType.UBYTE, 2.0, Position.DUMMY))
|
|
|
|
val expr2 = PtBinaryExpression("+", DataType.UBYTE, Position.DUMMY)
|
|
|
|
expr2.add(PtNumber(DataType.UBYTE, 1.0, Position.DUMMY))
|
|
|
|
expr2.add(PtNumber(DataType.UBYTE, 2.0, Position.DUMMY))
|
|
|
|
(expr1 isSameAs expr2) shouldBe true
|
|
|
|
val expr3 = PtBinaryExpression("+", DataType.UBYTE, Position.DUMMY)
|
|
|
|
expr3.add(PtNumber(DataType.UBYTE, 2.0, Position.DUMMY))
|
|
|
|
expr3.add(PtNumber(DataType.UBYTE, 1.0, Position.DUMMY))
|
|
|
|
(expr1 isSameAs expr3) shouldBe true
|
|
|
|
}
|
2022-03-06 16:29:30 +00:00
|
|
|
})
|