Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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",
),
)
}
Expand Down Expand Up @@ -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 ",
)
}
}
Expand Down