2020-08-15 18:38:08 +00:00
|
|
|
package com.htmlism.mos6502.dsl
|
|
|
|
|
2020-08-15 21:04:16 +00:00
|
|
|
import cats.data.NonEmptyList
|
2020-08-15 18:38:08 +00:00
|
|
|
import org.scalatest.flatspec._
|
|
|
|
import org.scalatest.matchers._
|
|
|
|
|
|
|
|
class DslSpec extends AnyFlatSpec with should.Matchers {
|
|
|
|
|
|
|
|
"the dsl" should "compile" in {
|
|
|
|
val doc =
|
|
|
|
asmDoc { implicit ctx =>
|
2020-08-15 18:44:23 +00:00
|
|
|
group("snake things") { implicit g =>
|
2020-08-15 21:04:16 +00:00
|
|
|
(define("snakeBodyStart", 0x12.z), define("snakeDirection", 0x02.z), define("snakeLength", 0x03.z))
|
2020-08-15 18:38:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 18:44:23 +00:00
|
|
|
group("ASCII values of keys controlling the snake") { implicit g =>
|
2020-08-15 21:04:16 +00:00
|
|
|
(define("ASCII_w", 0x77.z), define("ASCII_a", 0x61.z), define("ASCII_s", 0x73.z), define("ASCII_d", 0x64.z))
|
2020-08-15 18:38:08 +00:00
|
|
|
}
|
2020-08-15 18:44:23 +00:00
|
|
|
|
|
|
|
group("System variables") { implicit g =>
|
2020-08-15 21:04:16 +00:00
|
|
|
(define("sysRandom", 0xfe.z), define("sysLastKey", 0xff.z))
|
2020-08-15 18:44:23 +00:00
|
|
|
}
|
2020-08-15 20:23:36 +00:00
|
|
|
|
2020-08-15 20:29:32 +00:00
|
|
|
group("constants test") { implicit g =>
|
2020-08-15 21:04:16 +00:00
|
|
|
(constant("margin", 16), constant("secret", 42))
|
2020-08-15 20:29:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 20:23:36 +00:00
|
|
|
()
|
2020-08-15 18:38:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 21:04:16 +00:00
|
|
|
doc shouldEqual AsmDocument(
|
|
|
|
List(
|
|
|
|
DefinitionGroup(
|
|
|
|
"snake things",
|
|
|
|
List(
|
|
|
|
Definition("snakeBodyStart", 0x12.z),
|
|
|
|
Definition("snakeDirection", 0x02.z),
|
|
|
|
Definition("snakeLength", 0x03.z)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
DefinitionGroup(
|
|
|
|
"ASCII values of keys controlling the snake",
|
|
|
|
List(
|
|
|
|
Definition("ASCII_w", 0x77.z),
|
|
|
|
Definition("ASCII_a", 0x61.z),
|
|
|
|
Definition("ASCII_s", 0x73.z),
|
|
|
|
Definition("ASCII_d", 0x64.z)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
DefinitionGroup(
|
|
|
|
"System variables",
|
|
|
|
List(
|
|
|
|
Definition("sysRandom", 0xfe.z),
|
|
|
|
Definition("sysLastKey", 0xff.z)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
DefinitionGroup(
|
|
|
|
"constants test",
|
|
|
|
List(
|
|
|
|
Definition("margin", 16),
|
|
|
|
Definition("secret", 42)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2020-08-15 18:38:08 +00:00
|
|
|
}
|
2020-08-15 21:04:16 +00:00
|
|
|
|
|
|
|
"enum" should "compile" in {
|
|
|
|
val doc =
|
|
|
|
asmDoc { implicit ctx =>
|
|
|
|
enum[Foo]
|
|
|
|
}
|
|
|
|
|
|
|
|
doc shouldEqual AsmDocument(
|
|
|
|
List(
|
|
|
|
DefinitionGroup(
|
|
|
|
"foo as enum",
|
|
|
|
List(
|
|
|
|
Definition("courage", 0),
|
|
|
|
Definition("wisdom", 1),
|
|
|
|
Definition("power", 2)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
"bit field" should "compile" in {
|
|
|
|
val doc =
|
|
|
|
asmDoc { implicit ctx =>
|
|
|
|
bitField[Foo]
|
|
|
|
}
|
|
|
|
|
|
|
|
doc shouldEqual AsmDocument(
|
|
|
|
List(
|
|
|
|
DefinitionGroup(
|
|
|
|
"foo as bit field",
|
|
|
|
List(
|
|
|
|
Definition("up", 0x01),
|
|
|
|
Definition("down", 0x02),
|
|
|
|
Definition("left", 0x04),
|
|
|
|
Definition("right", 0x08)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Foo
|
|
|
|
|
|
|
|
object Foo {
|
|
|
|
implicit val enumFoo: EnumAsm[Foo] =
|
|
|
|
new EnumAsm[Foo] {
|
|
|
|
def comment: String =
|
|
|
|
"foo as enum"
|
|
|
|
|
|
|
|
def labels: NonEmptyList[String] =
|
|
|
|
NonEmptyList.of("courage", "wisdom", "power")
|
2020-08-15 21:10:37 +00:00
|
|
|
|
|
|
|
def label(x: Foo): String =
|
|
|
|
"fooNotEnum"
|
|
|
|
|
|
|
|
def comment(x: Foo): String =
|
|
|
|
"Foo not an enum"
|
2020-08-15 21:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
implicit val bitFieldFoo: BitField[Foo] =
|
|
|
|
new BitField[Foo] {
|
|
|
|
def comment: String =
|
|
|
|
"foo as bit field"
|
|
|
|
|
|
|
|
def labels: NonEmptyList[String] =
|
|
|
|
NonEmptyList.of("up", "down", "left", "right")
|
|
|
|
|
2020-08-15 21:10:37 +00:00
|
|
|
def label(x: Foo): String =
|
|
|
|
"fooNotBitField"
|
|
|
|
|
|
|
|
def comment(x: Foo): String =
|
|
|
|
"Foo not a bit field"
|
2020-08-15 21:04:16 +00:00
|
|
|
}
|
2020-08-15 18:38:08 +00:00
|
|
|
}
|