From ba5d7c3edd8e33a80668476033febb3bdd1fb4d3 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 24 May 2020 15:31:17 +0200 Subject: [PATCH] Separate the testing OPML samples out into files. --- tests/errors.rs | 44 +++--------- tests/samples/invalid_opml_no_outlines.opml | 4 ++ tests/samples/invalid_opml_version.opml | 6 ++ tests/samples/invalid_opml_version_1_0.opml | 6 ++ tests/samples/invalid_opml_version_1_1.opml | 6 ++ tests/samples/invalid_xml.opml | 1 + tests/samples/minimum_valid_opml.opml | 6 ++ tests/samples/valid_opml_with_everything.opml | 46 +++++++++++++ tests/valid.rs | 67 ++----------------- 9 files changed, 90 insertions(+), 96 deletions(-) create mode 100644 tests/samples/invalid_opml_no_outlines.opml create mode 100644 tests/samples/invalid_opml_version.opml create mode 100644 tests/samples/invalid_opml_version_1_0.opml create mode 100644 tests/samples/invalid_opml_version_1_1.opml create mode 100644 tests/samples/invalid_xml.opml create mode 100644 tests/samples/minimum_valid_opml.opml create mode 100644 tests/samples/valid_opml_with_everything.opml diff --git a/tests/errors.rs b/tests/errors.rs index ac39e1d..0b1cdbe 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -1,60 +1,38 @@ -// TODO: Extract all the OPML strings out and put them into their own files. +use std::fs::read_to_string as read; use opml::*; #[test] #[should_panic] fn test_invalid_xml() { - OPML::new(r#"{not xml :)"#).unwrap(); + let sample = read("tests/samples/invalid_xml.opml").unwrap(); + OPML::new(sample.as_str()).unwrap(); } #[test] #[should_panic(expected = "Unsupported OPML version detected: 1.0")] fn test_invalid_opml_version_1_0() { - OPML::new( - r#" - - - - - -"#, - ) - .unwrap(); + let sample = read("tests/samples/invalid_opml_version_1_0.opml").unwrap(); + OPML::new(sample.as_str()).unwrap(); } #[test] #[should_panic(expected = "Unsupported OPML version detected: 1.1")] fn test_invalid_opml_version_1_1() { - OPML::new( - r#" - - - - - -"#, - ) - .unwrap(); + let sample = read("tests/samples/invalid_opml_version_1_1.opml").unwrap(); + OPML::new(sample.as_str()).unwrap(); } #[test] #[should_panic(expected = "Unsupported OPML version detected: invalid")] fn test_invalid_opml_version() { - OPML::new( - r#" - - - - - -"#, - ) - .unwrap(); + let sample = read("tests/samples/invalid_opml_version.opml").unwrap(); + OPML::new(sample.as_str()).unwrap(); } #[test] #[should_panic(expected = "OPML body has no outlines.")] fn test_invalid_opml_no_outlines() { - OPML::new(r#""#).unwrap(); + let sample = read("tests/samples/invalid_opml_no_outlines.opml").unwrap(); + OPML::new(sample.as_str()).unwrap(); } diff --git a/tests/samples/invalid_opml_no_outlines.opml b/tests/samples/invalid_opml_no_outlines.opml new file mode 100644 index 0000000..38ec846 --- /dev/null +++ b/tests/samples/invalid_opml_no_outlines.opml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/samples/invalid_opml_version.opml b/tests/samples/invalid_opml_version.opml new file mode 100644 index 0000000..4aff51a --- /dev/null +++ b/tests/samples/invalid_opml_version.opml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/samples/invalid_opml_version_1_0.opml b/tests/samples/invalid_opml_version_1_0.opml new file mode 100644 index 0000000..94b663d --- /dev/null +++ b/tests/samples/invalid_opml_version_1_0.opml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/samples/invalid_opml_version_1_1.opml b/tests/samples/invalid_opml_version_1_1.opml new file mode 100644 index 0000000..fc5748d --- /dev/null +++ b/tests/samples/invalid_opml_version_1_1.opml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/samples/invalid_xml.opml b/tests/samples/invalid_xml.opml new file mode 100644 index 0000000..dcd8672 --- /dev/null +++ b/tests/samples/invalid_xml.opml @@ -0,0 +1 @@ +{not xml :) diff --git a/tests/samples/minimum_valid_opml.opml b/tests/samples/minimum_valid_opml.opml new file mode 100644 index 0000000..56d3530 --- /dev/null +++ b/tests/samples/minimum_valid_opml.opml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/samples/valid_opml_with_everything.opml b/tests/samples/valid_opml_with_everything.opml new file mode 100644 index 0000000..aed3d69 --- /dev/null +++ b/tests/samples/valid_opml_with_everything.opml @@ -0,0 +1,46 @@ + + + Title + Date Created + Date Modified + Owner Name + Owner Email + Owner ID + http://dev.opml.org/spec2.html + 0,1 + 0 + 1 + 2 + 3 + 4 + + + + + + + diff --git a/tests/valid.rs b/tests/valid.rs index 7610c7d..d8f2497 100644 --- a/tests/valid.rs +++ b/tests/valid.rs @@ -1,20 +1,11 @@ -// TODO: Extract all the OPML strings out and put them into their own files. +use std::fs::read_to_string as read; use opml::*; #[test] fn test_minimum_valid_opml() { assert_eq!( - OPML::new( - r#" - - - - - -"# - ) - .unwrap(), + OPML::new(&read("tests/samples/minimum_valid_opml.opml").unwrap()).unwrap(), OPML { version: "2.0".to_string(), head: Head { @@ -57,58 +48,8 @@ fn test_minimum_valid_opml() { #[test] fn test_valid_opml_with_everything() { assert_eq!( - OPML::new( - r#" - - - Title - Date Created - Date Modified - Owner Name - Owner Email - Owner ID - http://dev.opml.org/spec2.html - 0,1 - 0 - 1 - 2 - 3 - 4 - - - - - - -"# - ) - .unwrap(), + OPML::new(&read("tests/samples/valid_opml_with_everything.opml").unwrap()) + .unwrap(), OPML { version: "2.0".to_string(), head: Head {