Fork of https://github.com/oxigraph/oxigraph.git for the purpose of NextGraph project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.1 KiB
79 lines
3.1 KiB
use crate::files::load_store;
|
|
use crate::manifest::Test;
|
|
use crate::report::TestResult;
|
|
use anyhow::{anyhow, Result};
|
|
use chrono::Utc;
|
|
|
|
pub fn evaluate_parser_tests(
|
|
manifest: impl Iterator<Item = Result<Test>>,
|
|
) -> Result<Vec<TestResult>> {
|
|
manifest
|
|
.map(|test| {
|
|
let test = test?;
|
|
let outcome = evaluate_parser_test(&test);
|
|
Ok(TestResult {
|
|
test: test.id,
|
|
outcome,
|
|
date: Utc::now(),
|
|
})
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn evaluate_parser_test(test: &Test) -> Result<()> {
|
|
let action = test
|
|
.action
|
|
.as_deref()
|
|
.ok_or_else(|| anyhow!("No action found for test {}", test))?;
|
|
if test.kind == "http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestNQuadsPositiveSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigPositiveSyntax"
|
|
{
|
|
match load_store(action) {
|
|
Ok(_) => Ok(()),
|
|
Err(e) => Err(anyhow!(format!("Parse error: {}", e))),
|
|
}
|
|
} else if test.kind == "http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestNQuadsNegativeSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTurtleNegativeEval"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigNegativeSyntax"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigNegativeEval"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestXMLNegativeSyntax"
|
|
{
|
|
match load_store(action) {
|
|
Ok(_) => Err(anyhow!("File parsed with an error even if it should not",)),
|
|
Err(_) => Ok(()),
|
|
}
|
|
} else if test.kind == "http://www.w3.org/ns/rdftest#TestTurtleEval"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigEval"
|
|
|| test.kind == "http://www.w3.org/ns/rdftest#TestXMLEval"
|
|
{
|
|
match load_store(action) {
|
|
Ok(actual_graph) => {
|
|
if let Some(result) = &test.result {
|
|
match load_store(result) {
|
|
Ok(expected_graph) => {
|
|
if expected_graph.is_isomorphic(&actual_graph) {
|
|
Ok(())
|
|
} else {
|
|
Err(anyhow!(
|
|
"The two files are not isomorphic. Expected:\n{}\nActual:\n{}",
|
|
expected_graph,
|
|
actual_graph
|
|
))
|
|
}
|
|
}
|
|
Err(e) => Err(anyhow!("Parse error on file {}: {}", action, e)),
|
|
}
|
|
} else {
|
|
Err(anyhow!("No tests result found"))
|
|
}
|
|
}
|
|
Err(e) => Err(anyhow!("Parse error on file {}: {}", action, e)),
|
|
}
|
|
} else {
|
|
Err(anyhow!("Unsupported test type: {}", test.kind))
|
|
}
|
|
}
|
|
|