From 60e000b7d724cf3132393fa9e041374dddeb0a88 Mon Sep 17 00:00:00 2001 From: reidspencer Date: Tue, 29 Oct 2024 11:45:13 -0400 Subject: [PATCH] Make parseRootWithURLs return URLS on Left case too --- .../riddl/language/parsing/TopLevelParserTest.scala | 13 ++++++++++++- .../language/parsing/ExtensibleTopLevelParser.scala | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/language/jvm/src/test/scala/com/ossuminc/riddl/language/parsing/TopLevelParserTest.scala b/language/jvm/src/test/scala/com/ossuminc/riddl/language/parsing/TopLevelParserTest.scala index 49de13240..c0cd0dbe4 100644 --- a/language/jvm/src/test/scala/com/ossuminc/riddl/language/parsing/TopLevelParserTest.scala +++ b/language/jvm/src/test/scala/com/ossuminc/riddl/language/parsing/TopLevelParserTest.scala @@ -83,7 +83,7 @@ class TopLevelParserTest extends ParsingTest { val rpi: RiddlParserInput = Await.result(RiddlParserInput.fromURL(url), 10.seconds) val tlp = TopLevelParser(rpi,false) tlp.parseRootWithURLs match { - case Left(messages) => fail(messages.format) + case Left((messages, _)) => fail(messages.format) case Right((root, urls)) => root.domains.head.id.value must be("Everything") val paths: Seq[String] = urls.map(_.path) @@ -92,5 +92,16 @@ class TopLevelParserTest extends ParsingTest { paths must contain("language/jvm/src/test/input/everything_full.riddl") } } + "return URLs on failure" in { (td: TestData) => + val rpi: RiddlParserInput = RiddlParserInput("some source that ain't riddl", td) + val tlp = TopLevelParser(rpi, false) + tlp.parseRootWithURLs match { + case Left((messages, urls)) => + urls must be(empty) + messages mustNot be(empty) + succeed + case Right((root, urls)) => fail("Test should have yields Left") + } + } } } diff --git a/language/shared/src/main/scala/com/ossuminc/riddl/language/parsing/ExtensibleTopLevelParser.scala b/language/shared/src/main/scala/com/ossuminc/riddl/language/parsing/ExtensibleTopLevelParser.scala index 104af80df..3ddc600ac 100644 --- a/language/shared/src/main/scala/com/ossuminc/riddl/language/parsing/ExtensibleTopLevelParser.scala +++ b/language/shared/src/main/scala/com/ossuminc/riddl/language/parsing/ExtensibleTopLevelParser.scala @@ -65,9 +65,9 @@ trait ExtensibleTopLevelParser(using PlatformContext) def parseNebula: Either[Messages, Nebula] = doParse[Nebula](nebula(_)) - def parseRootWithURLs: Either[Messages, (Root, Seq[URL])] = { + def parseRootWithURLs: Either[(Messages, Seq[URL]), (Root, Seq[URL])] = { doParse[Root](root(_)) match { - case l @ Left(messages) => Left(messages) + case l @ Left(messages) => Left(messages -> this.getURLs) case r @ Right(root) => Right(root -> this.getURLs) } }