|
|
|
@ -73,18 +73,26 @@ impl Iterator for TestManifest { |
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<Test>> { |
|
|
|
|
loop { |
|
|
|
|
return match self.tests_to_do.pop_front().map(|term| match term { |
|
|
|
|
Term::NamedNode(n) => Ok(n), |
|
|
|
|
Term::BlankNode(n) => Ok(NamedNode::new(format!( |
|
|
|
|
"http://oxigraph.org/.well-known/genid/{}", |
|
|
|
|
n.as_str() |
|
|
|
|
))?), |
|
|
|
|
_ => Err(anyhow!("Invalid test identifier. Got {}", term)), |
|
|
|
|
}) { |
|
|
|
|
Some(Ok(test_node)) => { |
|
|
|
|
if self.graph.triples_for_subject(&test_node).next().is_none() { |
|
|
|
|
continue; // This test does not exists
|
|
|
|
|
if let Some(next) = self.next_test() { |
|
|
|
|
return Some(next); |
|
|
|
|
} |
|
|
|
|
if let Err(e) = self.load_next_manifest()? { |
|
|
|
|
return Some(Err(e)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl TestManifest { |
|
|
|
|
fn next_test(&mut self) -> Option<Result<Test>> { |
|
|
|
|
let test_node = self.tests_to_do.pop_front()?; |
|
|
|
|
let test_node = match test_node { |
|
|
|
|
Term::NamedNode(n) => n, |
|
|
|
|
_ => { |
|
|
|
|
return Some(Err(anyhow!("Invalid test identifier. Got {}", test_node))); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let name = match self |
|
|
|
|
.graph |
|
|
|
|
.object_for_subject_predicate(&test_node, mf::NAME) |
|
|
|
@ -98,11 +106,18 @@ impl Iterator for TestManifest { |
|
|
|
|
{ |
|
|
|
|
Some(TermRef::NamedNode(c)) => c.into_owned(), |
|
|
|
|
_ => { |
|
|
|
|
return Some(Err(anyhow!( |
|
|
|
|
return if test_node |
|
|
|
|
.as_str() |
|
|
|
|
.starts_with("http://www.w3.org/2001/sw/DataAccess/tests/data-r2") |
|
|
|
|
{ |
|
|
|
|
self.next_test() //TODO: hack to ignore invalid tests: https://github.com/w3c/rdf-tests/pull/82
|
|
|
|
|
} else { |
|
|
|
|
Some(Err(anyhow!( |
|
|
|
|
"The test {} named {} has no rdf:type", |
|
|
|
|
test_node, |
|
|
|
|
name.as_deref().unwrap_or("") |
|
|
|
|
))) |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
let comment = match self |
|
|
|
@ -125,13 +140,11 @@ impl Iterator for TestManifest { |
|
|
|
|
vec![], |
|
|
|
|
), |
|
|
|
|
Some(TermRef::BlankNode(n)) => { |
|
|
|
|
let query = match self.graph.object_for_subject_predicate(n, qt::QUERY) |
|
|
|
|
{ |
|
|
|
|
let query = match self.graph.object_for_subject_predicate(n, qt::QUERY) { |
|
|
|
|
Some(TermRef::NamedNode(q)) => Some(q.as_str().to_owned()), |
|
|
|
|
_ => None, |
|
|
|
|
}; |
|
|
|
|
let update = |
|
|
|
|
match self.graph.object_for_subject_predicate(n, ut::REQUEST) { |
|
|
|
|
let update = match self.graph.object_for_subject_predicate(n, ut::REQUEST) { |
|
|
|
|
Some(TermRef::NamedNode(q)) => Some(q.as_str().to_owned()), |
|
|
|
|
_ => None, |
|
|
|
|
}; |
|
|
|
@ -148,26 +161,20 @@ impl Iterator for TestManifest { |
|
|
|
|
.objects_for_subject_predicate(n, qt::GRAPH_DATA) |
|
|
|
|
.chain(self.graph.objects_for_subject_predicate(n, ut::GRAPH_DATA)) |
|
|
|
|
.filter_map(|g| match g { |
|
|
|
|
TermRef::NamedNode(q) => { |
|
|
|
|
Some((q.into_owned(), q.as_str().to_owned())) |
|
|
|
|
} |
|
|
|
|
TermRef::NamedNode(q) => Some((q.into_owned(), q.as_str().to_owned())), |
|
|
|
|
TermRef::BlankNode(node) => { |
|
|
|
|
if let Some(TermRef::NamedNode(graph)) = |
|
|
|
|
self.graph.object_for_subject_predicate(node, ut::GRAPH) |
|
|
|
|
{ |
|
|
|
|
if let Some(TermRef::Literal(name)) = self |
|
|
|
|
.graph |
|
|
|
|
.object_for_subject_predicate(node, rdfs::LABEL) |
|
|
|
|
if let Some(TermRef::Literal(name)) = |
|
|
|
|
self.graph.object_for_subject_predicate(node, rdfs::LABEL) |
|
|
|
|
{ |
|
|
|
|
Some(( |
|
|
|
|
NamedNode::new(name.value()).unwrap(), |
|
|
|
|
graph.as_str().to_owned(), |
|
|
|
|
)) |
|
|
|
|
} else { |
|
|
|
|
Some(( |
|
|
|
|
graph.into_owned(), |
|
|
|
|
graph.as_str().to_owned(), |
|
|
|
|
)) |
|
|
|
|
Some((graph.into_owned(), graph.as_str().to_owned())) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
None |
|
|
|
@ -192,10 +199,7 @@ impl Iterator for TestManifest { |
|
|
|
|
self.graph.object_for_subject_predicate(g, qt::ENDPOINT), |
|
|
|
|
self.graph.object_for_subject_predicate(g, qt::DATA), |
|
|
|
|
) { |
|
|
|
|
Some(( |
|
|
|
|
endpoint.as_str().to_owned(), |
|
|
|
|
data.as_str().to_owned(), |
|
|
|
|
)) |
|
|
|
|
Some((endpoint.as_str().to_owned(), data.as_str().to_owned())) |
|
|
|
|
} else { |
|
|
|
|
None |
|
|
|
|
} |
|
|
|
@ -224,26 +228,20 @@ impl Iterator for TestManifest { |
|
|
|
|
self.graph |
|
|
|
|
.objects_for_subject_predicate(n, ut::GRAPH_DATA) |
|
|
|
|
.filter_map(|g| match g { |
|
|
|
|
TermRef::NamedNode(q) => { |
|
|
|
|
Some((q.into_owned(), q.as_str().to_owned())) |
|
|
|
|
} |
|
|
|
|
TermRef::NamedNode(q) => Some((q.into_owned(), q.as_str().to_owned())), |
|
|
|
|
TermRef::BlankNode(node) => { |
|
|
|
|
if let Some(TermRef::NamedNode(graph)) = |
|
|
|
|
self.graph.object_for_subject_predicate(node, ut::GRAPH) |
|
|
|
|
{ |
|
|
|
|
if let Some(TermRef::Literal(name)) = self |
|
|
|
|
.graph |
|
|
|
|
.object_for_subject_predicate(node, rdfs::LABEL) |
|
|
|
|
if let Some(TermRef::Literal(name)) = |
|
|
|
|
self.graph.object_for_subject_predicate(node, rdfs::LABEL) |
|
|
|
|
{ |
|
|
|
|
Some(( |
|
|
|
|
NamedNode::new(name.value()).unwrap(), |
|
|
|
|
graph.as_str().to_owned(), |
|
|
|
|
)) |
|
|
|
|
} else { |
|
|
|
|
Some(( |
|
|
|
|
graph.into_owned(), |
|
|
|
|
graph.as_str().to_owned(), |
|
|
|
|
)) |
|
|
|
|
Some((graph.into_owned(), graph.as_str().to_owned())) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
None |
|
|
|
@ -271,27 +269,32 @@ impl Iterator for TestManifest { |
|
|
|
|
result_graph_data, |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
Some(Err(error)) => Some(Err(error)), |
|
|
|
|
None => { |
|
|
|
|
match self.manifests_to_do.pop_front() { |
|
|
|
|
Some(url) => { |
|
|
|
|
|
|
|
|
|
fn load_next_manifest(&mut self) -> Option<Result<()>> { |
|
|
|
|
let url = self.manifests_to_do.pop_front()?; |
|
|
|
|
self.graph.clear(); |
|
|
|
|
if let Err(error) = load_to_graph(&url, &mut self.graph) { |
|
|
|
|
return Some(Err(error)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for manifest in self |
|
|
|
|
let manifests = self |
|
|
|
|
.graph |
|
|
|
|
.subjects_for_predicate_object(rdf::TYPE, mf::MANIFEST) |
|
|
|
|
{ |
|
|
|
|
.collect::<Vec<_>>(); |
|
|
|
|
if manifests.len() != 1 { |
|
|
|
|
return Some(Err(anyhow!( |
|
|
|
|
"The file {} should contain a single manifest", |
|
|
|
|
url |
|
|
|
|
))); |
|
|
|
|
} |
|
|
|
|
for manifest in manifests { |
|
|
|
|
match self |
|
|
|
|
.graph |
|
|
|
|
.object_for_subject_predicate(manifest, mf::INCLUDE) |
|
|
|
|
{ |
|
|
|
|
Some(TermRef::BlankNode(list)) => { |
|
|
|
|
self.manifests_to_do.extend( |
|
|
|
|
RdfListIterator::iter(&self.graph, list.into()) |
|
|
|
|
.filter_map(|m| match m { |
|
|
|
|
RdfListIterator::iter(&self.graph, list.into()).filter_map(|m| match m { |
|
|
|
|
Term::NamedNode(nm) => Some(nm.into_string()), |
|
|
|
|
_ => None, |
|
|
|
|
}), |
|
|
|
@ -307,27 +310,16 @@ impl Iterator for TestManifest { |
|
|
|
|
.object_for_subject_predicate(manifest, mf::ENTRIES) |
|
|
|
|
{ |
|
|
|
|
Some(TermRef::BlankNode(list)) => { |
|
|
|
|
self.tests_to_do.extend(RdfListIterator::iter( |
|
|
|
|
&self.graph, |
|
|
|
|
list.into(), |
|
|
|
|
)); |
|
|
|
|
self.tests_to_do |
|
|
|
|
.extend(RdfListIterator::iter(&self.graph, list.into())); |
|
|
|
|
} |
|
|
|
|
Some(term) => { |
|
|
|
|
return Some(Err(anyhow!( |
|
|
|
|
"Invalid tests list. Got term {}", |
|
|
|
|
term |
|
|
|
|
))); |
|
|
|
|
return Some(Err(anyhow!("Invalid tests list. Got term {}", term))); |
|
|
|
|
} |
|
|
|
|
None => (), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
None => None, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
Some(Ok(())) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|