diff --git a/Cargo.lock b/Cargo.lock index 558e041..0520efa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,11 +70,7 @@ name = "exile" version = "0.0.2" dependencies = [ "cargo-readme", - "lazy_static", - "serde_json", - "serde_plain", "xdoc", - "xtest", ] [[package]] diff --git a/exile/Cargo.toml b/exile/Cargo.toml index 4a15455..13db32d 100644 --- a/exile/Cargo.toml +++ b/exile/Cargo.toml @@ -14,11 +14,4 @@ readme = "README.md" xdoc = { path = "../xdoc", version = "0.0.2" } [build-dependencies] -cargo-readme = "3.2.0" -xtest = { path = "../xtest", version = "0.0.2" } - -[dev-dependencies] -lazy_static = "1.4.0" -serde_json = "1.0.48" -serde_plain = "0.3.0" -xtest = { path = "../xtest", version = "0.0.2" } \ No newline at end of file +cargo-readme = "3.2.0" \ No newline at end of file diff --git a/exile/build.rs b/exile/build.rs index f0ab289..777972c 100644 --- a/exile/build.rs +++ b/exile/build.rs @@ -3,12 +3,10 @@ use std::env; use std::fs::File; use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; fn main() { - sir_watch_alot(); generate_readme(); - generate_tests(); } fn generate_readme() { @@ -41,84 +39,3 @@ fn generate_readme() { std::fs::copy(&this_readme_path, &top_readme_path).unwrap(); } } - -fn generate_tests() { - // Check for environment variable "SKIP_TEST_GENERATION". If it is set, skip test generation. - if env::var_os("EXILE_GENERATE_TESTS").is_none() { - println!("skipping test generation..."); - return; - } - println!("generating tests..."); - let test_file_path = integ_test_dir().join("parse_tests.rs"); - xtest::gen::generate_tests(test_file_path); -} - -fn integ_test_dir() -> PathBuf { - let mycrate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - mycrate_dir.join("tests") -} - -fn xtest_test_dir() -> PathBuf { - let mut mycrate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - mycrate_dir.pop(); - mycrate_dir.join("xtest") -} - -fn exile_dir() -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) -} - -// path walking helpers for watching files - -fn list_dir(p: &Path) -> Vec { - if !p.is_dir() { - panic!("{} is not a dir", p.display()); - } - let mut vec = Vec::new(); - let paths = std::fs::read_dir(p).unwrap(); - for path in paths { - vec.append(&mut list_files_recursively(&path.unwrap().path())); - } - vec -} - -fn list_files_recursively(p: &Path) -> Vec { - let mut vec = Vec::new(); - if p.is_file() { - if let Some(ext) = p.extension() { - let ext = ext.to_str().unwrap(); - if ext == "rs" || ext == "json" || ext == "xml" { - vec.push(p.canonicalize().unwrap().to_str().unwrap().to_owned()); - } - } - } else if p.is_dir() { - vec.append(&mut list_dir(p)); - } else { - panic!("unknown path type {}", p.display()); - } - vec -} - -fn lib_rs() -> PathBuf { - exile_dir().join("src").join("lib.rs") -} - -fn readme_template() -> PathBuf { - exile_dir().join("readme.template") -} - -fn sir_watch_alot() { - let tests = xtest_test_dir(); - if !tests.is_dir() { - // The tests aren't there, so there's nothing to watch, or to do. - return; - } - let mut vec = list_files_recursively(&tests); - vec.push(lib_rs().to_str().unwrap().to_owned()); - vec.push(readme_template().to_str().unwrap().to_owned()); - for file in &vec { - println!("cargo:rerun-if-changed={}", file); - } - println!("cargo:rerun-if-env-changed=EXILE_GENERATE_TESTS"); - println!("cargo:rerun-if-env-changed=EXILE_GENERATE_README"); -} diff --git a/exile/tests/generated/exile_angle_in_attribute_value.rs b/exile/tests/generated/exile_angle_in_attribute_value.rs new file mode 100644 index 0000000..3f0b374 --- /dev/null +++ b/exile/tests/generated/exile_angle_in_attribute_value.rs @@ -0,0 +1,32 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "exile_angle_in_attribute_value.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// unescaped angle bracket in an attribute value +fn angle_in_attribute_value_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(parse_error) => { + assert_eq!(51, parse_error.xml_site.position); + assert_eq!(2, parse_error.xml_site.line); + assert_eq!(12, parse_error.xml_site.column); + } + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/exile_cd_catalog.rs b/exile/tests/generated/exile_cd_catalog.rs index 74f88e8..fc7a775 100644 --- a/exile/tests/generated/exile_cd_catalog.rs +++ b/exile/tests/generated/exile_cd_catalog.rs @@ -8,33 +8,44 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_cd_catalog.xml"; +const INPUT_FILE: &str = "exile_cd_catalog.xml"; +const OUTPUT_FILE: &str = "exile_cd_catalog.output.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn cd_catalog() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// cd_catalog example from https://www.w3schools.com/xml/xml_examples.asp +fn cd_catalog_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } +#[test] +/// Check that the serialization of this XML document matches what we expect. +fn cd_catalog_serialize() { + let doc = expected(); + let actual = doc.to_string(); + let expected = std::fs::read_to_string(path(OUTPUT_FILE)).unwrap(); + assert_eq!(expected, actual); +} + fn expected() -> Document { let mut doc = Document::new(); doc.set_declaration(Declaration { diff --git a/exile/tests/generated/exile_doctypes_comments_pis.rs b/exile/tests/generated/exile_doctypes_comments_pis.rs index 3303547..3097ee0 100644 --- a/exile/tests/generated/exile_doctypes_comments_pis.rs +++ b/exile/tests/generated/exile_doctypes_comments_pis.rs @@ -7,29 +7,30 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_doctypes_comments_pis.xml"; +const INPUT_FILE: &str = "exile_doctypes_comments_pis.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn doctypes_comments_pis() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// a file with doctypes, processing instructions and comments +fn doctypes_comments_pis_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/exile_escapes.rs b/exile/tests/generated/exile_escapes.rs index 8a401b2..3de8c5a 100644 --- a/exile/tests/generated/exile_escapes.rs +++ b/exile/tests/generated/exile_escapes.rs @@ -7,33 +7,44 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_escapes.xml"; +const INPUT_FILE: &str = "exile_escapes.xml"; +const OUTPUT_FILE: &str = "exile_escapes.output.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn escapes() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// escape sequences +fn escapes_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } +#[test] +/// Check that the serialization of this XML document matches what we expect. +fn escapes_serialize() { + let doc = expected(); + let actual = doc.to_string(); + let expected = std::fs::read_to_string(path(OUTPUT_FILE)).unwrap(); + assert_eq!(expected, actual); +} + fn expected() -> Document { let mut doc = Document::new(); doc.set_declaration(Declaration { diff --git a/exile/tests/generated/exile_e_file.rs b/exile/tests/generated/exile_ezfile.rs similarity index 58% rename from exile/tests/generated/exile_e_file.rs rename to exile/tests/generated/exile_ezfile.rs index f71c61e..666746e 100644 --- a/exile/tests/generated/exile_e_file.rs +++ b/exile/tests/generated/exile_ezfile.rs @@ -8,33 +8,44 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_e_file.xml"; +const INPUT_FILE: &str = "exile_ezfile.xml"; +const OUTPUT_FILE: &str = "exile_ezfile.output.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn e_file() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// a simple, small, well-formed xml file +fn ezfile_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } +#[test] +/// Check that the serialization of this XML document matches what we expect. +fn ezfile_serialize() { + let doc = expected(); + let actual = doc.to_string(); + let expected = std::fs::read_to_string(path(OUTPUT_FILE)).unwrap(); + assert_eq!(expected, actual); +} + fn expected() -> Document { let mut doc = Document::new(); doc.set_declaration(Declaration { diff --git a/exile/tests/generated/exile_pi.rs b/exile/tests/generated/exile_pi.rs index f203252..12cb557 100644 --- a/exile/tests/generated/exile_pi.rs +++ b/exile/tests/generated/exile_pi.rs @@ -8,29 +8,30 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_pi.xml"; +const INPUT_FILE: &str = "exile_pi.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn pi() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// a simple file with processing instructions +fn pi_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/exile_simple_musicxml.rs b/exile/tests/generated/exile_simple_musicxml.rs index 3e26e47..c2edff7 100644 --- a/exile/tests/generated/exile_simple_musicxml.rs +++ b/exile/tests/generated/exile_simple_musicxml.rs @@ -8,33 +8,44 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_simple_musicxml.xml"; +const INPUT_FILE: &str = "exile_simple_musicxml.xml"; +const OUTPUT_FILE: &str = "exile_simple_musicxml.output.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn simple_musicxml() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// cd_catalog example from https://www.w3schools.com/xml/xml_examples.asp +fn simple_musicxml_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } +#[test] +/// Check that the serialization of this XML document matches what we expect. +fn simple_musicxml_serialize() { + let doc = expected(); + let actual = doc.to_string(); + let expected = std::fs::read_to_string(path(OUTPUT_FILE)).unwrap(); + assert_eq!(expected, actual); +} + fn expected() -> Document { let mut doc = Document::new(); doc.set_declaration(Declaration { diff --git a/exile/tests/generated/exile_single_quotes.rs b/exile/tests/generated/exile_single_quotes.rs index b907b6f..4cc2101 100644 --- a/exile/tests/generated/exile_single_quotes.rs +++ b/exile/tests/generated/exile_single_quotes.rs @@ -8,29 +8,30 @@ use xdoc::Version; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "exile_single_quotes.xml"; +const INPUT_FILE: &str = "exile_single_quotes.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn single_quotes() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// a simple file with single-quoted attributes +fn single_quotes_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/exile_unescaped_angle.rs b/exile/tests/generated/exile_unescaped_angle.rs new file mode 100644 index 0000000..5e01c3b --- /dev/null +++ b/exile/tests/generated/exile_unescaped_angle.rs @@ -0,0 +1,32 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "exile_unescaped_angle.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// unescaped angle bracket inside element text +fn unescaped_angle_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(parse_error) => { + assert_eq!(95, parse_error.xml_site.position); + assert_eq!(4, parse_error.xml_site.line); + assert_eq!(39, parse_error.xml_site.column); + } + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/jclark_not_wf_sa_001.rs b/exile/tests/generated/jclark_not_wf_sa_001.rs new file mode 100644 index 0000000..1d0a0ac --- /dev/null +++ b/exile/tests/generated/jclark_not_wf_sa_001.rs @@ -0,0 +1,28 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "jclark_not_wf_sa_001.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// A not-well-formed test file from the W3C conformance test suite: not-wf-sa-001 +fn not_wf_sa_001_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(_) => {} + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/jclark_not_wf_sa_002.rs b/exile/tests/generated/jclark_not_wf_sa_002.rs new file mode 100644 index 0000000..3110f94 --- /dev/null +++ b/exile/tests/generated/jclark_not_wf_sa_002.rs @@ -0,0 +1,28 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "jclark_not_wf_sa_002.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// A not-well-formed test file from the W3C conformance test suite: not-wf-sa-002 +fn not_wf_sa_002_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(_) => {} + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/jclark_not_wf_sa_003.rs b/exile/tests/generated/jclark_not_wf_sa_003.rs new file mode 100644 index 0000000..4eaead6 --- /dev/null +++ b/exile/tests/generated/jclark_not_wf_sa_003.rs @@ -0,0 +1,28 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "jclark_not_wf_sa_003.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// A not-well-formed test file from the W3C conformance test suite: not-wf-sa-003 +fn not_wf_sa_003_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(_) => {} + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/jclark_not_wf_sa_004.rs b/exile/tests/generated/jclark_not_wf_sa_004.rs new file mode 100644 index 0000000..e05fbce --- /dev/null +++ b/exile/tests/generated/jclark_not_wf_sa_004.rs @@ -0,0 +1,28 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "jclark_not_wf_sa_004.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// A not-well-formed test file from the W3C conformance test suite: not-wf-sa-004 +fn not_wf_sa_004_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(_) => {} + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/jclark_not_wf_sa_005.rs b/exile/tests/generated/jclark_not_wf_sa_005.rs new file mode 100644 index 0000000..4318b76 --- /dev/null +++ b/exile/tests/generated/jclark_not_wf_sa_005.rs @@ -0,0 +1,28 @@ +// generated file, do not edit + +use std::path::PathBuf; + +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); +const INPUT_DATA: &str = "input_data"; +const INPUT_FILE: &str = "jclark_not_wf_sa_005.xml"; + +fn path(filename: &str) -> PathBuf { + let p = PathBuf::from(MANIFEST_DIR) + .join("tests") + .join(INPUT_DATA) + .join(filename); + p.canonicalize() + .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) +} + +#[test] +/// A not-well-formed test file from the W3C conformance test suite: not-wf-sa-005 +fn not_wf_sa_005_test() { + let result = exile::load(path(INPUT_FILE)); + assert!(result.is_err()); + let e = result.err().unwrap(); + match e { + exile::error::Error::Parse(_) => {} + _ => panic!("expected parse error."), + } +} diff --git a/exile/tests/generated/jclark_valid_sa_001.rs b/exile/tests/generated/jclark_valid_sa_001.rs index 9ac0338..75de259 100644 --- a/exile/tests/generated/jclark_valid_sa_001.rs +++ b/exile/tests/generated/jclark_valid_sa_001.rs @@ -6,29 +6,30 @@ use xdoc::Declaration; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "jclark_valid_sa_001.xml"; +const INPUT_FILE: &str = "jclark_valid_sa_001.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn valid_sa_001() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// A valid XML file from the W3C conformance test suite: valid-sa-001 +fn valid_sa_001_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/jclark_valid_sa_002.rs b/exile/tests/generated/jclark_valid_sa_002.rs index 50c4145..ebc4b52 100644 --- a/exile/tests/generated/jclark_valid_sa_002.rs +++ b/exile/tests/generated/jclark_valid_sa_002.rs @@ -6,29 +6,30 @@ use xdoc::Declaration; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "jclark_valid_sa_002.xml"; +const INPUT_FILE: &str = "jclark_valid_sa_002.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn valid_sa_002() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// A valid XML file from the W3C conformance test suite: valid-sa-002 +fn valid_sa_002_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/jclark_valid_sa_003.rs b/exile/tests/generated/jclark_valid_sa_003.rs index 79a3f58..6725a57 100644 --- a/exile/tests/generated/jclark_valid_sa_003.rs +++ b/exile/tests/generated/jclark_valid_sa_003.rs @@ -6,29 +6,30 @@ use xdoc::Declaration; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "jclark_valid_sa_003.xml"; +const INPUT_FILE: &str = "jclark_valid_sa_003.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn valid_sa_003() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// A valid XML file from the W3C conformance test suite: valid-sa-003 +fn valid_sa_003_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/jclark_valid_sa_004.rs b/exile/tests/generated/jclark_valid_sa_004.rs index fd8a717..61c425f 100644 --- a/exile/tests/generated/jclark_valid_sa_004.rs +++ b/exile/tests/generated/jclark_valid_sa_004.rs @@ -6,29 +6,30 @@ use xdoc::Declaration; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "jclark_valid_sa_004.xml"; +const INPUT_FILE: &str = "jclark_valid_sa_004.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn valid_sa_004() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// A valid XML file from the W3C conformance test suite: valid-sa-004 +fn valid_sa_004_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/jclark_valid_sa_005.rs b/exile/tests/generated/jclark_valid_sa_005.rs index 4c5a4d6..c01e9d5 100644 --- a/exile/tests/generated/jclark_valid_sa_005.rs +++ b/exile/tests/generated/jclark_valid_sa_005.rs @@ -6,29 +6,30 @@ use xdoc::Declaration; const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); const INPUT_DATA: &str = "input_data"; -const FILENAME: &str = "jclark_valid_sa_005.xml"; +const INPUT_FILE: &str = "jclark_valid_sa_005.xml"; -fn path() -> PathBuf { +fn path(filename: &str) -> PathBuf { let p = PathBuf::from(MANIFEST_DIR) .join("tests") .join(INPUT_DATA) - .join(FILENAME); + .join(filename); p.canonicalize() .unwrap_or_else(|e| panic!("bad path: {}: {}", p.display(), e)) } #[test] -fn valid_sa_005() { - let path = path(); - let loaded = exile::load(&path).unwrap(); +/// A valid XML file from the W3C conformance test suite: valid-sa-005 +fn valid_sa_005_parse() { + let path = path(INPUT_FILE); + let actual = exile::load(&path).unwrap(); let expected = expected(); - if loaded != expected { - let loaded_str = loaded.to_string(); + if actual != expected { + let actual_str = actual.to_string(); let expected_str = expected.to_string(); - if loaded_str != expected_str { - assert_eq!(loaded_str, expected_str); + if actual_str != expected_str { + assert_eq!(expected_str, actual_str); } else { - assert_eq!(loaded, expected); + assert_eq!(expected, actual); } } } diff --git a/exile/tests/generated/mod.rs b/exile/tests/generated/mod.rs index 354aacd..83d15a0 100644 --- a/exile/tests/generated/mod.rs +++ b/exile/tests/generated/mod.rs @@ -1,12 +1,19 @@ // generated file, do not edit +mod exile_angle_in_attribute_value; mod exile_cd_catalog; mod exile_doctypes_comments_pis; -mod exile_e_file; mod exile_escapes; +mod exile_ezfile; mod exile_pi; mod exile_simple_musicxml; mod exile_single_quotes; +mod exile_unescaped_angle; +mod jclark_not_wf_sa_001; +mod jclark_not_wf_sa_002; +mod jclark_not_wf_sa_003; +mod jclark_not_wf_sa_004; +mod jclark_not_wf_sa_005; mod jclark_valid_sa_001; mod jclark_valid_sa_002; mod jclark_valid_sa_003; diff --git a/xtest/data/angle-in-attribute-value.metadata.json b/exile/tests/input_data/exile_angle_in_attribute_value.metadata.json similarity index 100% rename from xtest/data/angle-in-attribute-value.metadata.json rename to exile/tests/input_data/exile_angle_in_attribute_value.metadata.json diff --git a/xtest/data/angle-in-attribute-value.xml b/exile/tests/input_data/exile_angle_in_attribute_value.xml similarity index 100% rename from xtest/data/angle-in-attribute-value.xml rename to exile/tests/input_data/exile_angle_in_attribute_value.xml diff --git a/xtest/data/cd_catalog.metadata.json b/exile/tests/input_data/exile_cd_catalog.metadata.json similarity index 100% rename from xtest/data/cd_catalog.metadata.json rename to exile/tests/input_data/exile_cd_catalog.metadata.json diff --git a/xtest/data/cd_catalog.expected.xml b/exile/tests/input_data/exile_cd_catalog.output.xml similarity index 100% rename from xtest/data/cd_catalog.expected.xml rename to exile/tests/input_data/exile_cd_catalog.output.xml diff --git a/xtest/data/disabled.comment-before-declaration.xml b/exile/tests/input_data/exile_disabled.comment_before_declaration.xml similarity index 100% rename from xtest/data/disabled.comment-before-declaration.xml rename to exile/tests/input_data/exile_disabled.comment_before_declaration.xml diff --git a/xtest/data/disabled.difficult-nodes.metadata.json b/exile/tests/input_data/exile_disabled.difficult_nodes.metadata.json similarity index 100% rename from xtest/data/disabled.difficult-nodes.metadata.json rename to exile/tests/input_data/exile_disabled.difficult_nodes.metadata.json diff --git a/xtest/data/disabled.difficult-nodes.xml b/exile/tests/input_data/exile_disabled.difficult_nodes.xml similarity index 100% rename from xtest/data/disabled.difficult-nodes.xml rename to exile/tests/input_data/exile_disabled.difficult_nodes.xml diff --git a/xtest/data/disabled.note.xml b/exile/tests/input_data/exile_disabled.note.xml similarity index 100% rename from xtest/data/disabled.note.xml rename to exile/tests/input_data/exile_disabled.note.xml diff --git a/xtest/data/disabled.note_error.xml b/exile/tests/input_data/exile_disabled.note_error.xml similarity index 100% rename from xtest/data/disabled.note_error.xml rename to exile/tests/input_data/exile_disabled.note_error.xml diff --git a/xtest/data/disabled.pi-stray-text.metadata.json b/exile/tests/input_data/exile_disabled.pi_stray_text.metadata.json similarity index 100% rename from xtest/data/disabled.pi-stray-text.metadata.json rename to exile/tests/input_data/exile_disabled.pi_stray_text.metadata.json diff --git a/xtest/data/disabled.pi-stray-text.xml b/exile/tests/input_data/exile_disabled.pi_stray_text.xml similarity index 100% rename from xtest/data/disabled.pi-stray-text.xml rename to exile/tests/input_data/exile_disabled.pi_stray_text.xml diff --git a/xtest/data/disabled.plant_catalog.xml b/exile/tests/input_data/exile_disabled.plant_catalog.xml similarity index 100% rename from xtest/data/disabled.plant_catalog.xml rename to exile/tests/input_data/exile_disabled.plant_catalog.xml diff --git a/xtest/data/disabled.simple_food_menu.xml b/exile/tests/input_data/exile_disabled.simple_food_menu.xml similarity index 100% rename from xtest/data/disabled.simple_food_menu.xml rename to exile/tests/input_data/exile_disabled.simple_food_menu.xml diff --git a/xtest/data/doctypes-comments-pis.metadata.json b/exile/tests/input_data/exile_doctypes_comments_pis.metadata.json similarity index 100% rename from xtest/data/doctypes-comments-pis.metadata.json rename to exile/tests/input_data/exile_doctypes_comments_pis.metadata.json diff --git a/xtest/data/escapes.metadata.json b/exile/tests/input_data/exile_escapes.metadata.json similarity index 100% rename from xtest/data/escapes.metadata.json rename to exile/tests/input_data/exile_escapes.metadata.json diff --git a/xtest/data/escapes.expected.xml b/exile/tests/input_data/exile_escapes.output.xml similarity index 100% rename from xtest/data/escapes.expected.xml rename to exile/tests/input_data/exile_escapes.output.xml diff --git a/xtest/data/ezfile.metadata.json b/exile/tests/input_data/exile_ezfile.metadata.json similarity index 100% rename from xtest/data/ezfile.metadata.json rename to exile/tests/input_data/exile_ezfile.metadata.json diff --git a/xtest/data/ezfile.expected.xml b/exile/tests/input_data/exile_ezfile.output.xml similarity index 100% rename from xtest/data/ezfile.expected.xml rename to exile/tests/input_data/exile_ezfile.output.xml diff --git a/exile/tests/input_data/exile_e_file.xml b/exile/tests/input_data/exile_ezfile.xml similarity index 100% rename from exile/tests/input_data/exile_e_file.xml rename to exile/tests/input_data/exile_ezfile.xml diff --git a/xtest/data/pi.metadata.json b/exile/tests/input_data/exile_pi.metadata.json similarity index 100% rename from xtest/data/pi.metadata.json rename to exile/tests/input_data/exile_pi.metadata.json diff --git a/xtest/data/simple_musicxml.metadata.json b/exile/tests/input_data/exile_simple_musicxml.metadata.json similarity index 100% rename from xtest/data/simple_musicxml.metadata.json rename to exile/tests/input_data/exile_simple_musicxml.metadata.json diff --git a/xtest/data/simple_musicxml.expected.xml b/exile/tests/input_data/exile_simple_musicxml.output.xml similarity index 100% rename from xtest/data/simple_musicxml.expected.xml rename to exile/tests/input_data/exile_simple_musicxml.output.xml diff --git a/xtest/data/single_quotes.metadata.json b/exile/tests/input_data/exile_single_quotes.metadata.json similarity index 100% rename from xtest/data/single_quotes.metadata.json rename to exile/tests/input_data/exile_single_quotes.metadata.json diff --git a/xtest/data/unescaped-angle.metadata.json b/exile/tests/input_data/exile_unescaped_angle.metadata.json similarity index 100% rename from xtest/data/unescaped-angle.metadata.json rename to exile/tests/input_data/exile_unescaped_angle.metadata.json diff --git a/xtest/data/unescaped-angle.xml b/exile/tests/input_data/exile_unescaped_angle.xml similarity index 100% rename from xtest/data/unescaped-angle.xml rename to exile/tests/input_data/exile_unescaped_angle.xml diff --git a/exile/tests/input_data/jclark_not_wf_sa_001.xml b/exile/tests/input_data/jclark_not_wf_sa_001.xml new file mode 100644 index 0000000..d33ec68 --- /dev/null +++ b/exile/tests/input_data/jclark_not_wf_sa_001.xml @@ -0,0 +1,5 @@ + + + diff --git a/exile/tests/input_data/jclark_not_wf_sa_002.xml b/exile/tests/input_data/jclark_not_wf_sa_002.xml new file mode 100644 index 0000000..0a64d52 --- /dev/null +++ b/exile/tests/input_data/jclark_not_wf_sa_002.xml @@ -0,0 +1,4 @@ + +<.doc> + + diff --git a/exile/tests/input_data/jclark_not_wf_sa_003.xml b/exile/tests/input_data/jclark_not_wf_sa_003.xml new file mode 100644 index 0000000..e0b8bae --- /dev/null +++ b/exile/tests/input_data/jclark_not_wf_sa_003.xml @@ -0,0 +1 @@ + diff --git a/exile/tests/input_data/jclark_not_wf_sa_004.xml b/exile/tests/input_data/jclark_not_wf_sa_004.xml new file mode 100644 index 0000000..e85bc96 --- /dev/null +++ b/exile/tests/input_data/jclark_not_wf_sa_004.xml @@ -0,0 +1 @@ + diff --git a/exile/tests/input_data/jclark_not_wf_sa_005.xml b/exile/tests/input_data/jclark_not_wf_sa_005.xml new file mode 100644 index 0000000..7cd44ef --- /dev/null +++ b/exile/tests/input_data/jclark_not_wf_sa_005.xml @@ -0,0 +1 @@ + diff --git a/exile/tests/manually_written_tests.rs b/exile/tests/manually_written_tests.rs deleted file mode 100644 index f85a76f..0000000 --- a/exile/tests/manually_written_tests.rs +++ /dev/null @@ -1,64 +0,0 @@ -#[test] -fn good_syntax_ezfile_test() { - let info = xtest::load("ezfile"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - assert!(parse_result.is_ok()); -} - -/* -// This is used for file generation and is checked-in while commented out intentionally. -#[test] -fn genstuff() { - use std::fs::{read_to_string, OpenOptions}; - use std::io::Cursor; - use std::path::PathBuf; - use xtest::{Metadata, Syntax}; - let name = "simple_musicxml"; - let data_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("..") - .join("xtest") - .join("data") - .canonicalize() - .unwrap(); - - let inpath = data_path.join(format!("{}.xml", name)); - let xmlout_path = data_path.join(format!("{}.expected.xml", name)); - let jsonout_path = data_path.join(format!("{}.metadata.json", name)); - println!("{}", inpath.display()); - let xml = read_to_string(inpath).unwrap(); - let doc = exile::parse(xml.as_str()).unwrap(); - let md = xtest::Metadata { - description: "cd_catalog example from https://www.w3schools.com/xml/xml_examples.asp" - .to_string(), - syntax: xtest::Syntax::Good {}, - expected: Some(doc.clone()), - }; - let json = serde_json::to_string_pretty(&md).unwrap(); - println!("{}", json); - let mut cursor = Cursor::new(Vec::new()); - let result = doc.write(&mut cursor); - assert!(result.is_ok()); - let data = cursor.into_inner(); - { - let _ = std::fs::remove_file(&xmlout_path); - let mut file = OpenOptions::new() - .read(true) - .write(true) - .create(true) - .open(xmlout_path) - .unwrap(); - file.write_all(data.as_slice()).unwrap(); - } - { - let _ = std::fs::remove_file(&jsonout_path); - let mut file = OpenOptions::new() - .read(true) - .write(true) - .create(true) - .open(jsonout_path) - .unwrap(); - file.write_all(json.as_bytes()).unwrap(); - } -} -*/ diff --git a/exile/tests/parse_tests.rs b/exile/tests/parse_tests.rs deleted file mode 100644 index f7142fd..0000000 --- a/exile/tests/parse_tests.rs +++ /dev/null @@ -1,193 +0,0 @@ -//! `parse_tests.rs` is generated by build.rs -#[test] -/// unescaped angle bracket in an attribute value -fn bad_syntax_angle_in_attribute_value_test() { - let info = xtest::load("angle-in-attribute-value"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - assert!(parse_result.is_err()); - let err = parse_result.err().unwrap(); - match err { - exile::error::Error::Parse(parse_error) => { - assert_eq!(51, parse_error.xml_site.position); - assert_eq!(2, parse_error.xml_site.line); - assert_eq!(12, parse_error.xml_site.column); - } - _ => panic!("Error was expected to be of type exile::error::Error::Parse, but was not."), - } -} - -#[test] -/// cd_catalog example from https://www.w3schools.com/xml/xml_examples.asp -fn good_syntax_cd_catalog_test() { - let info = xtest::load("cd_catalog"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } - let got_doc = parse_result.as_ref().unwrap(); - let want_doc = info.metadata.expected.as_ref().unwrap(); - let equal = want_doc == got_doc; - if !equal { - let want = want_doc.to_string(); - let got = got_doc.to_string(); - if want != got { - assert_eq!(got, want); - } else { - assert!(equal); - } - } - let wanted_serialization = info.read_expected_write().unwrap(); - assert_eq!(got_doc.to_string(), wanted_serialization); -} - -#[test] -/// a file with doctypes, processing instructions and comments -fn good_syntax_doctypes_comments_pis_test() { - let info = xtest::load("doctypes-comments-pis"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } -} - -#[test] -/// escape sequences -fn good_syntax_escapes_test() { - let info = xtest::load("escapes"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } - let got_doc = parse_result.as_ref().unwrap(); - let want_doc = info.metadata.expected.as_ref().unwrap(); - let equal = want_doc == got_doc; - if !equal { - let want = want_doc.to_string(); - let got = got_doc.to_string(); - if want != got { - assert_eq!(got, want); - } else { - assert!(equal); - } - } - let wanted_serialization = info.read_expected_write().unwrap(); - assert_eq!(got_doc.to_string(), wanted_serialization); -} - -#[test] -/// a simple, small, well-formed xml file -fn good_syntax_ezfile_test() { - let info = xtest::load("ezfile"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } - let got_doc = parse_result.as_ref().unwrap(); - let want_doc = info.metadata.expected.as_ref().unwrap(); - let equal = want_doc == got_doc; - if !equal { - let want = want_doc.to_string(); - let got = got_doc.to_string(); - if want != got { - assert_eq!(got, want); - } else { - assert!(equal); - } - } - let wanted_serialization = info.read_expected_write().unwrap(); - assert_eq!(got_doc.to_string(), wanted_serialization); -} - -#[test] -/// a simple file with processing instructions -fn good_syntax_pi_test() { - let info = xtest::load("pi"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } - let got_doc = parse_result.as_ref().unwrap(); - let want_doc = info.metadata.expected.as_ref().unwrap(); - let equal = want_doc == got_doc; - if !equal { - let want = want_doc.to_string(); - let got = got_doc.to_string(); - if want != got { - assert_eq!(got, want); - } else { - assert!(equal); - } - } -} - -#[test] -/// cd_catalog example from https://www.w3schools.com/xml/xml_examples.asp -fn good_syntax_simple_musicxml_test() { - let info = xtest::load("simple_musicxml"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } - let got_doc = parse_result.as_ref().unwrap(); - let want_doc = info.metadata.expected.as_ref().unwrap(); - let equal = want_doc == got_doc; - if !equal { - let want = want_doc.to_string(); - let got = got_doc.to_string(); - if want != got { - assert_eq!(got, want); - } else { - assert!(equal); - } - } - let wanted_serialization = info.read_expected_write().unwrap(); - assert_eq!(got_doc.to_string(), wanted_serialization); -} - -#[test] -/// a simple file with single-quoted attributes -fn good_syntax_single_quotes_test() { - let info = xtest::load("single_quotes"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - if let Err(e) = parse_result { - panic!("expected parse_result to be Ok, got Err: {}", e); - } - let got_doc = parse_result.as_ref().unwrap(); - let want_doc = info.metadata.expected.as_ref().unwrap(); - let equal = want_doc == got_doc; - if !equal { - let want = want_doc.to_string(); - let got = got_doc.to_string(); - if want != got { - assert_eq!(got, want); - } else { - assert!(equal); - } - } -} - -#[test] -/// unescaped angle bracket inside element text -fn bad_syntax_unescaped_angle_test() { - let info = xtest::load("unescaped-angle"); - let xml_str = info.read_xml_file(); - let parse_result = exile::parse(xml_str.as_str()); - assert!(parse_result.is_err()); - let err = parse_result.err().unwrap(); - match err { - exile::error::Error::Parse(parse_error) => { - assert_eq!(95, parse_error.xml_site.position); - assert_eq!(4, parse_error.xml_site.line); - assert_eq!(39, parse_error.xml_site.column); - } - _ => panic!("Error was expected to be of type exile::error::Error::Parse, but was not."), - } -} diff --git a/testgen/entrypoint.sh b/testgen/entrypoint.sh index 0661359..67abc5e 100755 --- a/testgen/entrypoint.sh +++ b/testgen/entrypoint.sh @@ -18,9 +18,8 @@ d="--custom-schema /fake" e="--xml-outdir /workspace/exile/tests" f="--schema-outdir /fake" g="--rust-root /workspace" -h="--exile-tests /workspace/xtest/data" # TODO - this will move # use maven to execute the program mvn exec:java \ -Dexec.mainClass="com.matthewjamesbriggs.xmltestgen.App" \ - -Dexec.args="${a} ${b} ${c} ${d} ${e} ${f} ${g} ${h}" + -Dexec.args="${a} ${b} ${c} ${d} ${e} ${f} ${g}" diff --git a/testgen/xmltestgen/.idea/saveactions_settings.xml b/testgen/xmltestgen/.idea/saveactions_settings.xml index 9de5690..241b920 100644 --- a/testgen/xmltestgen/.idea/saveactions_settings.xml +++ b/testgen/xmltestgen/.idea/saveactions_settings.xml @@ -24,7 +24,6 @@