parent
323ad73831
commit
6375481a80
@ -1 +1 @@ |
|||||||
Subproject commit 22cfdfda79153b6dba91844e69043c019c89fd84 |
Subproject commit 7f556ae7c7d94ef63997e13a173603fba80db5d7 |
@ -1,109 +1,147 @@ |
|||||||
use crate::evaluator::TestEvaluator; |
use crate::evaluator::TestEvaluator; |
||||||
use crate::files::load_dataset; |
use crate::files::{guess_dataset_format, guess_graph_format, load_dataset, load_graph}; |
||||||
use crate::manifest::Test; |
use crate::manifest::Test; |
||||||
use crate::report::dataset_diff; |
use crate::report::{dataset_diff, graph_diff}; |
||||||
use anyhow::{anyhow, bail, Result}; |
use anyhow::{anyhow, bail, Result}; |
||||||
|
use oxigraph::io::{DatasetFormat, GraphFormat}; |
||||||
|
|
||||||
pub fn register_parser_tests(evaluator: &mut TestEvaluator) { |
pub fn register_parser_tests(evaluator: &mut TestEvaluator) { |
||||||
evaluator.register( |
evaluator.register( |
||||||
"http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax", |
"http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax", |
||||||
evaluate_positive_syntax_test, |
|t| evaluate_positive_graph_syntax_test(t, GraphFormat::NTriples), |
||||||
); |
); |
||||||
evaluator.register( |
evaluator.register( |
||||||
"http://www.w3.org/ns/rdftest#TestNQuadsPositiveSyntax", |
"http://www.w3.org/ns/rdftest#TestNQuadsPositiveSyntax", |
||||||
evaluate_positive_syntax_test, |
|t| evaluate_positive_dataset_syntax_test(t, DatasetFormat::NQuads), |
||||||
); |
); |
||||||
evaluator.register( |
evaluator.register( |
||||||
"http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax", |
"http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax", |
||||||
evaluate_positive_syntax_test, |
|t| evaluate_positive_graph_syntax_test(t, GraphFormat::Turtle), |
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestTrigPositiveSyntax", |
|
||||||
evaluate_positive_syntax_test, |
|
||||||
); |
); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestTrigPositiveSyntax", |t| { |
||||||
|
evaluate_positive_dataset_syntax_test(t, DatasetFormat::TriG) |
||||||
|
}); |
||||||
evaluator.register( |
evaluator.register( |
||||||
"http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax", |
"http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax", |
||||||
evaluate_negative_syntax_test, |
|t| evaluate_negative_graph_syntax_test(t, GraphFormat::NTriples), |
||||||
); |
); |
||||||
evaluator.register( |
evaluator.register( |
||||||
"http://www.w3.org/ns/rdftest#TestNQuadsNegativeSyntax", |
"http://www.w3.org/ns/rdftest#TestNQuadsNegativeSyntax", |
||||||
evaluate_negative_syntax_test, |
|t| evaluate_negative_dataset_syntax_test(t, DatasetFormat::NQuads), |
||||||
); |
); |
||||||
evaluator.register( |
evaluator.register( |
||||||
"http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax", |
"http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax", |
||||||
evaluate_negative_syntax_test, |
|t| evaluate_negative_graph_syntax_test(t, GraphFormat::Turtle), |
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestTurtleNegativeEval", |
|
||||||
evaluate_negative_syntax_test, |
|
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestTrigNegativeSyntax", |
|
||||||
evaluate_negative_syntax_test, |
|
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestTrigNegativeEval", |
|
||||||
evaluate_negative_syntax_test, |
|
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestXMLNegativeSyntax", |
|
||||||
evaluate_negative_syntax_test, |
|
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestTurtleEval", |
|
||||||
evaluate_eval_test, |
|
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestTrigEval", |
|
||||||
evaluate_eval_test, |
|
||||||
); |
|
||||||
evaluator.register( |
|
||||||
"http://www.w3.org/ns/rdftest#TestXMLEval", |
|
||||||
evaluate_eval_test, |
|
||||||
); |
); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestTrigNegativeSyntax", |t| { |
||||||
|
evaluate_negative_dataset_syntax_test(t, DatasetFormat::TriG) |
||||||
|
}); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestXMLNegativeSyntax", |t| { |
||||||
|
evaluate_negative_graph_syntax_test(t, GraphFormat::RdfXml) |
||||||
|
}); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestTurtleEval", |t| { |
||||||
|
evaluate_graph_eval_test(t, GraphFormat::Turtle) |
||||||
|
}); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestTrigEval", |t| { |
||||||
|
evaluate_dataset_eval_test(t, DatasetFormat::TriG) |
||||||
|
}); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestXMLEval", |t| { |
||||||
|
evaluate_graph_eval_test(t, GraphFormat::RdfXml) |
||||||
|
}); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestTurtleNegativeEval", |t| { |
||||||
|
evaluate_negative_graph_syntax_test(t, GraphFormat::Turtle) |
||||||
|
}); |
||||||
|
evaluator.register("http://www.w3.org/ns/rdftest#TestTrigNegativeEval", |t| { |
||||||
|
evaluate_negative_dataset_syntax_test(t, DatasetFormat::TriG) |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
fn evaluate_positive_syntax_test(test: &Test) -> Result<()> { |
fn evaluate_positive_graph_syntax_test(test: &Test, format: GraphFormat) -> Result<()> { |
||||||
let action = test |
let action = test |
||||||
.action |
.action |
||||||
.as_deref() |
.as_deref() |
||||||
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
||||||
load_dataset(action).map_err(|e| anyhow!("Parse error: {e}"))?; |
load_graph(action, format).map_err(|e| anyhow!("Parse error: {e}"))?; |
||||||
Ok(()) |
Ok(()) |
||||||
} |
} |
||||||
|
|
||||||
fn evaluate_negative_syntax_test(test: &Test) -> Result<()> { |
fn evaluate_positive_dataset_syntax_test(test: &Test, format: DatasetFormat) -> Result<()> { |
||||||
let action = test |
let action = test |
||||||
.action |
.action |
||||||
.as_deref() |
.as_deref() |
||||||
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
||||||
match load_dataset(action) { |
load_dataset(action, format).map_err(|e| anyhow!("Parse error: {e}"))?; |
||||||
Ok(_) => bail!("File parsed with an error even if it should not"), |
Ok(()) |
||||||
|
} |
||||||
|
|
||||||
|
fn evaluate_negative_graph_syntax_test(test: &Test, format: GraphFormat) -> Result<()> { |
||||||
|
let action = test |
||||||
|
.action |
||||||
|
.as_deref() |
||||||
|
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
||||||
|
match load_graph(action, format) { |
||||||
|
Ok(_) => bail!("File parsed without errors even if it should not"), |
||||||
|
Err(_) => Ok(()), |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fn evaluate_negative_dataset_syntax_test(test: &Test, format: DatasetFormat) -> Result<()> { |
||||||
|
let action = test |
||||||
|
.action |
||||||
|
.as_deref() |
||||||
|
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
||||||
|
match load_dataset(action, format) { |
||||||
|
Ok(_) => bail!("File parsed without errors even if it should not"), |
||||||
Err(_) => Ok(()), |
Err(_) => Ok(()), |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
fn evaluate_eval_test(test: &Test) -> Result<()> { |
fn evaluate_graph_eval_test(test: &Test, format: GraphFormat) -> Result<()> { |
||||||
let action = test |
let action = test |
||||||
.action |
.action |
||||||
.as_deref() |
.as_deref() |
||||||
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
||||||
let mut actual_graph = |
let mut actual_graph = |
||||||
load_dataset(action).map_err(|e| anyhow!("Parse error on file {action}: {e}"))?; |
load_graph(action, format).map_err(|e| anyhow!("Parse error on file {action}: {e}"))?; |
||||||
actual_graph.canonicalize(); |
actual_graph.canonicalize(); |
||||||
if let Some(result) = &test.result { |
let results = test |
||||||
let mut expected_graph = |
.result |
||||||
load_dataset(result).map_err(|e| anyhow!("Parse error on file {action}: {e}"))?; |
.as_ref() |
||||||
|
.ok_or_else(|| anyhow!("No tests result found"))?; |
||||||
|
let mut expected_graph = load_graph(results, guess_graph_format(results)?) |
||||||
|
.map_err(|e| anyhow!("Parse error on file {results}: {e}"))?; |
||||||
expected_graph.canonicalize(); |
expected_graph.canonicalize(); |
||||||
if expected_graph == actual_graph { |
if expected_graph == actual_graph { |
||||||
Ok(()) |
Ok(()) |
||||||
} else { |
} else { |
||||||
bail!( |
bail!( |
||||||
"The two files are not isomorphic. Diff:\n{}", |
"The two files are not isomorphic. Diff:\n{}", |
||||||
dataset_diff(&expected_graph, &actual_graph) |
graph_diff(&expected_graph, &actual_graph) |
||||||
) |
) |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
fn evaluate_dataset_eval_test(test: &Test, format: DatasetFormat) -> Result<()> { |
||||||
|
let action = test |
||||||
|
.action |
||||||
|
.as_deref() |
||||||
|
.ok_or_else(|| anyhow!("No action found for test {test}"))?; |
||||||
|
let mut actual_dataset = |
||||||
|
load_dataset(action, format).map_err(|e| anyhow!("Parse error on file {action}: {e}"))?; |
||||||
|
actual_dataset.canonicalize(); |
||||||
|
let results = test |
||||||
|
.result |
||||||
|
.as_ref() |
||||||
|
.ok_or_else(|| anyhow!("No tests result found"))?; |
||||||
|
let mut expected_dataset = load_dataset(results, guess_dataset_format(results)?) |
||||||
|
.map_err(|e| anyhow!("Parse error on file {results}: {e}"))?; |
||||||
|
expected_dataset.canonicalize(); |
||||||
|
if expected_dataset == actual_dataset { |
||||||
|
Ok(()) |
||||||
} else { |
} else { |
||||||
bail!("No tests result found") |
bail!( |
||||||
|
"The two files are not isomorphic. Diff:\n{}", |
||||||
|
dataset_diff(&expected_dataset, &actual_dataset) |
||||||
|
) |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue