Skip to content

Commit

Permalink
WIP: start to cover NonWhiteSpaceParsers
Browse files Browse the repository at this point in the history
  • Loading branch information
reid-spencer committed May 12, 2024
1 parent f39ac12 commit 6dded9d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ private[parsing] trait NoWhiteSpaceParsers extends ParsingContext {

private val backslash: String = "\\"
private final val zero: String = "0"
private def octalChar[u: P]: P[String] = CharIn("0-7").!
private def octalString[u: P]: P[String] = {
P(backslash ~ zero ~ octalChar.rep(min = 1, sep = P(""), max = 3).!)
}

private def hexDigit[u: P]: P[String] = CharIn("0-9a-fA-F").!./
private def hexEscape[u: P]: P[String] = P(backslash ~ "x" ~ hexDigit.rep(min = 2)).!./
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +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

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

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

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"""")
}
}

"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
@@ -0,0 +1,27 @@
package com.ossuminc.riddl.language.parsing

import org.scalatest.matchers.must.Matchers

class StatementsTest extends ParsingTest with Matchers{

"Statements" must {
"include Code Statement" in {
val input =
"""domain CodeStatements is {
| context CodeStatements is {
| handler h is {
| on initialization {
| ```scala
| val foo: Int = 1
| ```
| }
| }
| }
|}""".stripMargin
TopLevelParser.parseString(input, origin = Some("Code Statement Test")) match
case Left(value) => ???
case Right(root) => ???

}
}
}

0 comments on commit 6dded9d

Please sign in to comment.