Skip to content

Commit

Permalink
Add more coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reid-spencer committed May 12, 2024
1 parent a1db7f4 commit 788720a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ package com.ossuminc.riddl.language.parsing

import com.ossuminc.riddl.language.AST.*
import com.ossuminc.riddl.language.At
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global

/** Unit Tests For CommonParser */
class CommonParserTest extends ParsingTest {

"NonWhiteSpaceParsers" should {
"handle a literalString" in {
val text = """"This is a literal string with" """

val content = "This is a literal string with"
val text = s""""$content""""
val input = RiddlParserInput(text, "test")
val testParser = TestParser(input)
testParser.expect[LiteralString](testParser.literalString(_)) match
case Left(messages) => fail(messages.justErrors.format)
case Right(ls) => ls.s must be(s""""$text"""")
case Right(ls) => ls.s must be(content)
}
}

"CommonParser" should {
"location should construct from pair" in {
val loc = At((1, 1))
loc.line mustBe 1
val column = loc.col
column mustBe 1
}

"descriptions can be URLs" in {
val input = """domain foo is { ??? } described at
|https://www.wordnik.com/words/phi""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ossuminc.riddl.language.parsing

import org.scalatest.matchers.must.Matchers
import com.ossuminc.riddl.language.AST
import com.ossuminc.riddl.language.AST.{CodeStatement, Statement}

class StatementsTest extends ParsingTest with Matchers{

Expand All @@ -10,7 +12,7 @@ class StatementsTest extends ParsingTest with Matchers{
"""domain CodeStatements is {
| context CodeStatements is {
| handler h is {
| on initialization {
| on init {
| ```scala
| val foo: Int = 1
| ```
Expand All @@ -19,9 +21,18 @@ class StatementsTest extends ParsingTest with Matchers{
| }
|}""".stripMargin
TopLevelParser.parseString(input, origin = Some("Code Statement Test")) match
case Left(value) => ???
case Right(root) => ???
case Left(messages) => fail(messages.justErrors.format)
case Right(root) =>
val clause =
AST.getContexts(AST.getTopLevelDomains(root).head).head.handlers.head.clauses.head
val s: Statement = clause.statements.head
s.isInstanceOf[CodeStatement] must be(true)
val codeStatement = s.asInstanceOf[CodeStatement]
codeStatement.language.s must be("scala")
codeStatement.body must be(
"""val foo: Int = 1
| """.stripMargin)

}
}
}
}

0 comments on commit 788720a

Please sign in to comment.