mirror of
https://github.com/KarolS/millfork.git
synced 2025-02-11 18:30:52 +00:00
Tests for recent parser improvements
This commit is contained in:
parent
33405ffcd6
commit
4214f1f6f5
@ -22,14 +22,17 @@ class ConsoleLogger extends Logger {
|
|||||||
private def printErrorContext(pos: Option[Position]): Unit = synchronized {
|
private def printErrorContext(pos: Option[Position]): Unit = synchronized {
|
||||||
pos.foreach { position =>
|
pos.foreach { position =>
|
||||||
sourceLines.get(position.moduleName).foreach { lines =>
|
sourceLines.get(position.moduleName).foreach { lines =>
|
||||||
val line = lines.apply(pos.get.line - 1)
|
val lineIx = pos.get.line - 1
|
||||||
val column = pos.get.column - 1
|
if (lineIx < lines.length) {
|
||||||
val margin = " "
|
val line = lines.apply(lineIx)
|
||||||
print(margin)
|
val column = pos.get.column - 1
|
||||||
println(line)
|
val margin = " "
|
||||||
print(margin)
|
print(margin)
|
||||||
print(" " * column)
|
println(line)
|
||||||
println("^")
|
print(margin)
|
||||||
|
print(" " * column)
|
||||||
|
println("^")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,10 +147,14 @@ class BasicSymonTest extends FunSuite with Matchers {
|
|||||||
test("Segment syntax") {
|
test("Segment syntax") {
|
||||||
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)(
|
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)(
|
||||||
"""
|
"""
|
||||||
| segment(default)byte output @$c000
|
| segment ( default ) byte output @$c000
|
||||||
| segment(default)array x[3]
|
| segment(default)array x[3]
|
||||||
| segment(default)void main () {
|
| segment(default)void main () {
|
||||||
| }
|
| }
|
||||||
|
| segment (default) {
|
||||||
|
| const byte a = 1
|
||||||
|
| //
|
||||||
|
| }
|
||||||
""".stripMargin){ m => () }
|
""".stripMargin){ m => () }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
56
src/test/scala/millfork/test/ParserSuite.scala
Normal file
56
src/test/scala/millfork/test/ParserSuite.scala
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package millfork.test
|
||||||
|
|
||||||
|
import millfork.Cpu
|
||||||
|
import millfork.test.emu.{EmuUnoptimizedCrossPlatformRun, ShouldNotCompile}
|
||||||
|
import org.scalatest.{FunSuite, Matchers}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karol Stasiak
|
||||||
|
*/
|
||||||
|
class ParserSuite extends FunSuite with Matchers {
|
||||||
|
|
||||||
|
test("Require space between flags and types") {
|
||||||
|
ShouldNotCompile(
|
||||||
|
"""
|
||||||
|
| constbyte a = 2
|
||||||
|
|
|
||||||
|
""".stripMargin)
|
||||||
|
}
|
||||||
|
|
||||||
|
test("Comment after last constant") {
|
||||||
|
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
|
||||||
|
"""
|
||||||
|
|
|
||||||
|
| byte __panic() = 1
|
||||||
|
| const byte x = 5;
|
||||||
|
| const byte a = 2;
|
||||||
|
|
|
||||||
|
|void main () {}//
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|//
|
||||||
|
|
|
||||||
|
""".stripMargin){ m =>
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test("Allow negation") {
|
||||||
|
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
|
||||||
|
"""
|
||||||
|
| array output[100] @$c000
|
||||||
|
| const byte x = 5
|
||||||
|
| void main() {
|
||||||
|
| output[0] = -x
|
||||||
|
| output[1] = 0 | (-x)
|
||||||
|
| output[2] = 1 * (-x)
|
||||||
|
| if (x != -x) { output[3] = 5 }
|
||||||
|
| }
|
||||||
|
""".stripMargin){ m =>
|
||||||
|
m.readByte(0xc000) should equal(251)
|
||||||
|
m.readByte(0xc001) should equal(251)
|
||||||
|
m.readByte(0xc002) should equal(251)
|
||||||
|
m.readByte(0xc003) should equal(5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user