Skip to content

Commit

Permalink
add test for parsing Program
Browse files Browse the repository at this point in the history
  • Loading branch information
mtghorbani committed Jun 19, 2024
1 parent 6186e80 commit c894330
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/test/scala/uk/ac/ed/dal/structtensor/Parser/ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,75 @@ class ParserTest extends AnyFlatSpec with Matchers with ParallelTestExecution {
)
)
}

it should "parse a program" in {
val input =
"""|foo(x, y, z):= bar(x, y, z) * baz(x, y, z) + qux(x, y, z)
|bax(x, y, z):= foo(x, y, z) * bar(x, y, z) + qux(x, y, z)
|""".stripMargin
val result = fastparse.parse(input, Parser.program(_))
result.isSuccess shouldBe true
result.get.value shouldBe Seq(
Rule(
Access("foo", Seq(Variable("x"), Variable("y"), Variable("z")), Tensor),
SoP(
Seq(
Prod(
Seq(
Access(
"bar",
Seq(Variable("x"), Variable("y"), Variable("z")),
Tensor
),
Access(
"baz",
Seq(Variable("x"), Variable("y"), Variable("z")),
Tensor
)
)
),
Prod(
Seq(
Access(
"qux",
Seq(Variable("x"), Variable("y"), Variable("z")),
Tensor
)
)
)
)
)
),
Rule(
Access("bax", Seq(Variable("x"), Variable("y"), Variable("z")), Tensor),
SoP(
Seq(
Prod(
Seq(
Access(
"foo",
Seq(Variable("x"), Variable("y"), Variable("z")),
Tensor
),
Access(
"bar",
Seq(Variable("x"), Variable("y"), Variable("z")),
Tensor
)
)
),
Prod(
Seq(
Access(
"qux",
Seq(Variable("x"), Variable("y"), Variable("z")),
Tensor
)
)
)
)
)
)
)
}
}

0 comments on commit c894330

Please sign in to comment.