Testsuite: executes C14N tests

pull/654/head
Tpt 1 year ago committed by Thomas Tanon
parent ef429e6d1b
commit 5647624012
  1. 41
      lib/oxrdf/src/literal.rs
  2. 2
      testsuite/rdf-tests
  3. 20
      testsuite/src/parser_evaluator.rs
  4. 9
      testsuite/tests/parser.rs

@ -637,7 +637,6 @@ pub fn print_quoted_str(string: &str, f: &mut impl Write) -> fmt::Result {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::str::FromStr;
#[test] #[test]
fn test_simple_literal_equality() { fn test_simple_literal_equality() {
@ -668,44 +667,4 @@ mod tests {
assert_eq!("NaN", Literal::from(f32::NAN).value()); assert_eq!("NaN", Literal::from(f32::NAN).value());
assert_eq!("NaN", Literal::from(f64::NAN).value()); assert_eq!("NaN", Literal::from(f64::NAN).value());
} }
#[test]
fn test_canoincal_escaping() {
assert_eq!(
Literal::from_str(r#""\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f""#).unwrap().to_string(),
r#""\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000B\f\r\u000E\u000F""#
);
assert_eq!(
Literal::from_str(r#""\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f""#).unwrap().to_string(),
r#""\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F""#
);
assert_eq!(
Literal::from_str(r#""\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002a\u002b\u002c\u002d\u002e\u002f""#).unwrap().to_string(),
r##"" !\"#$%&'()*+,-./""##
);
assert_eq!(
Literal::from_str(r#""\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f""#).unwrap().to_string(),
r#""0123456789:;<=>?""#
);
assert_eq!(
Literal::from_str(r#""\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f""#).unwrap().to_string(),
r#""@ABCDEFGHIJKLMNO""#
);
assert_eq!(
Literal::from_str(r#""\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057\u0058\u0059\u005a\u005b\u005c\u005d\u005e\u005f""#).unwrap().to_string(),
r#""PQRSTUVWXYZ[\\]^_""#
);
assert_eq!(
Literal::from_str(r#""\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067\u0068\u0069\u006a\u006b\u006c\u006d\u006e\u006f""#).unwrap().to_string(),
r#""`abcdefghijklmno""#
);
assert_eq!(
Literal::from_str(r#""\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u007f""#).unwrap().to_string(),
r#""pqrstuvwxyz{|}~\u007F""#
);
assert_eq!(
Literal::from_str(r#""\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f""#).unwrap().to_string(),
"\"\u{80}\u{81}\u{82}\u{83}\u{84}\u{85}\u{86}\u{87}\u{88}\u{89}\u{8a}\u{8b}\u{8c}\u{8d}\u{8e}\u{8f}\""
);
}
} }

@ -1 +1 @@
Subproject commit a0b910e0f2cff4d3a7e32f15ce0bfbc7db2768fb Subproject commit 59b0496b050e1c2397f22d94af0609d8324d95f7

@ -67,6 +67,10 @@ pub fn register_parser_tests(evaluator: &mut TestEvaluator) {
evaluator.register("http://www.w3.org/ns/rdftest#TestTrigNegativeEval", |t| { evaluator.register("http://www.w3.org/ns/rdftest#TestTrigNegativeEval", |t| {
evaluate_negative_syntax_test(t, RdfFormat::TriG) evaluate_negative_syntax_test(t, RdfFormat::TriG)
}); });
evaluator.register(
"http://www.w3.org/ns/rdftest#TestNTriplesPositiveC14N",
|t| evaluate_positive_c14n_test(t, RdfFormat::NTriples),
);
evaluator.register( evaluator.register(
"https://w3c.github.io/rdf-canon/tests/vocab#RDFC10EvalTest", "https://w3c.github.io/rdf-canon/tests/vocab#RDFC10EvalTest",
|t| evaluate_positive_syntax_test(t, RdfFormat::NQuads), //TODO: not a proper implementation! |t| evaluate_positive_syntax_test(t, RdfFormat::NQuads), //TODO: not a proper implementation!
@ -166,6 +170,22 @@ fn evaluate_n3_eval_test(test: &Test, ignore_errors: bool) -> Result<()> {
Ok(()) Ok(())
} }
fn evaluate_positive_c14n_test(test: &Test, format: RdfFormat) -> Result<()> {
let action = test.action.as_deref().context("No action found")?;
let actual = load_dataset(action, format, false)
.with_context(|| format!("Parse error on file {action}"))?
.to_string();
let results = test.result.as_ref().context("No tests result found")?;
let expected =
read_file_to_string(results).with_context(|| format!("Read error on file {results}"))?;
ensure!(
expected == actual,
"The two files are not equal. Diff:\n{}",
format_diff(&expected, &actual, "c14n")
);
Ok(())
}
fn n3_to_dataset(quads: Vec<N3Quad>) -> Dataset { fn n3_to_dataset(quads: Vec<N3Quad>) -> Dataset {
quads quads
.into_iter() .into_iter()

@ -19,6 +19,15 @@ fn rdf12_n_triples_syntax_w3c_testsuite() -> Result<()> {
) )
} }
#[cfg(not(windows))] // Tests don't like git auto "\r\n" on Windows
#[test]
fn rdf12_n_triples_c14n_w3c_testsuite() -> Result<()> {
check_testsuite(
"https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-n-triples/c14n/manifest.ttl",
&[],
)
}
#[test] #[test]
fn rdf11_n_quads_w3c_testsuite() -> Result<()> { fn rdf11_n_quads_w3c_testsuite() -> Result<()> {
check_testsuite( check_testsuite(

Loading…
Cancel
Save