diff --git a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala index e3dd6f3..e88a7be 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala @@ -148,13 +148,15 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]: None, (prefix, iri) => jellyStreamConsumer.prefix(prefix, iri.getURI), ) - val x = frameIndices.slice(frames).zipWithIndex - for (frame, i) <- x do - val frameIndex = frameIndices.start.getOrElse(0) + i + val frames2 = frameIndices.end match + case Some(end) => frames.take(end) + case None => frames + val startFrom = frameIndices.start.getOrElse(0) + for (frame, i) <- frames2.zipWithIndex do for row <- frame.rows do if row.row.isOptions && row.row.options != opt then throw CriticalException( - s"Later occurrence of stream options in frame $frameIndex does not match the first", + s"Later occurrence of stream options in frame $i does not match the first", ) // Push the stream frames through the decoder // This will catch most of the errors @@ -165,16 +167,18 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]: // because it's too performance-costly. case t: Triple => if !opt.generalizedStatements && StatementUtils.isGeneralized(t) then - throw CriticalException(s"Unexpected generalized triple in frame $frameIndex: $t") + throw CriticalException(s"Unexpected generalized triple in frame $i: $t") if !opt.rdfStar && StatementUtils.isRdfStar(t) then - throw CriticalException(s"Unexpected RDF-star triple in frame $frameIndex: $t") - jellyStreamConsumer.triple(t) + throw CriticalException(s"Unexpected RDF-star triple in frame $i: $t") + // Add the triple to the comparison set, if we are in the compare range + if i >= startFrom then jellyStreamConsumer.triple(t) case q: Quad => if !opt.generalizedStatements && StatementUtils.isGeneralized(q) then - throw CriticalException(s"Unexpected generalized quad in frame $frameIndex: $q") + throw CriticalException(s"Unexpected generalized quad in frame $i: $q") if !opt.rdfStar && StatementUtils.isRdfStar(q) then - throw CriticalException(s"Unexpected RDF-star quad in frame $frameIndex: $q") - jellyStreamConsumer.quad(q) + throw CriticalException(s"Unexpected RDF-star quad in frame $i: $q") + // Add the quad to the comparison set, if we are in the compare range + if i >= startFrom then jellyStreamConsumer.quad(q) // Compare the Jelly data with the reference RDF data, if specified maybeRdfComparison.foreach { rdfComparison => val actual = jellyStreamConsumer.asInstanceOf[StreamRdfCollector] diff --git a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala index 1c74b75..1efd5e1 100644 --- a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala +++ b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala @@ -418,11 +418,14 @@ class RdfValidateSpec extends AnyWordSpec, Matchers, TestFixtureHelper: val frame1 = Using.resource(FileInputStream(jellyF)) { is => RdfStreamFrame.parseDelimitedFrom(is).get } - val frames = frame1 +: (1 to 10).map { i => - RdfStreamFrame( - Seq(RdfStreamRow(RdfTriple(RdfIri(0, i), RdfIri(0, i), RdfLiteral("aaaa")))), - ) - } + val frame2 = RdfStreamFrame( + Seq( + RdfStreamRow(RdfTriple(RdfLiteral("aaaa"), RdfLiteral("aaaa"), RdfLiteral("aaaa"))), + ), + ) + val frames = Seq(RdfStreamFrame(Seq(frame1.rows.head))) :+ frame2 :+ frame1 :++ + (1 to 10).map { _ => frame2 } + val b = { val os = ByteArrayOutputStream() frames.foreach(_.writeDelimitedTo(os)) @@ -436,7 +439,9 @@ class RdfValidateSpec extends AnyWordSpec, Matchers, TestFixtureHelper: "--compare-to-rdf-file=" + jenaF, "--compare-to-format=nt", "--compare-ordered=true", - "--compare-frame-indices=0", + // Compare frame index non-zero to check if the decoder's state is updated correctly + // even if the frame is not used in the comparison. + "--compare-frame-indices=2", ), ) } @@ -466,13 +471,13 @@ class RdfValidateSpec extends AnyWordSpec, Matchers, TestFixtureHelper: "--compare-to-rdf-file=" + jenaF, "--compare-to-format=nt", "--compare-ordered=true", - "--compare-frame-indices=0..4", + "--compare-frame-indices=1..4", ), ) } e.cause.get shouldBe a[CriticalException] e.cause.get.getMessage should include( - "Expected 37 RDF elements, but got 40", + "Expected 37 RDF elements, but got 3 ", ) } }