diff --git a/Cargo.lock b/Cargo.lock index ab58486c..9dd4ffc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1565,6 +1565,7 @@ dependencies = [ "png", "rand 0.8.4", "redis", + "regex", "reqwest", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 3e6b6ff6..6555ddd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ time = [] toml = ["serde", "serde_json", "toml-dep"] url = ["url-dep", "percent-encoding"] -# non-default features +# additional features hash = ["base64", "const-random", "md-5", "hex", "sha-1", "sha2", "twox-hash", "serde", "serde_json"] redis_pubsub = ["flume", "redis", "serde", "serde_json"] unzip = ["zip", "jobs"] @@ -71,3 +71,6 @@ worleynoise = ["rand","dmsort"] # internal feature-like things jobs = ["flume"] + +[dev-dependencies] +regex = "1" diff --git a/README.md b/README.md index 5a53e57e..92cf6c81 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,9 @@ The default features are: Additional features are: * hash: Faster replacement for `md5`, support for SHA-1, SHA-256, and SHA-512. Requires OpenSSL on Linux. * redis_pubsub: Library for sending and receiving messages through Redis. -* url: Faster replacements for `url_encode` and `url_decode`. * unzip: Function to download a .zip from a URL and unzip it to a directory. -* worleynoise: Function that generates a type of nice looking cellular noise, more expensive than cellularnoise. +* url: Faster replacements for `url_encode` and `url_decode`. +* worleynoise: Function that generates a type of nice looking cellular noise, more expensive than cellularnoise ## Installing diff --git a/tests/abc-tests.rs b/tests/abc-tests.rs new file mode 100644 index 00000000..0923c669 --- /dev/null +++ b/tests/abc-tests.rs @@ -0,0 +1,67 @@ +extern crate regex; +use regex::{CaptureMatches, RegexBuilder}; +use std::cmp::Ordering; + +fn are_captures_sorted(matches: CaptureMatches, context: &str) -> Result<(), String> { + let mut prev_string = ""; + for cap in matches { + let capstring = cap.get(0).unwrap().as_str(); + match prev_string.cmp(&capstring) { + Ordering::Greater => { + return Err(format!("{} is not sorted in {}", &capstring, &context)) + } + _ => { + prev_string = capstring; + } + }; + } + Ok(()) +} + +#[test] +fn test_readme() -> Result<(), String> { + let readme = std::fs::read_to_string("README.md").unwrap(); + let blocksre = RegexBuilder::new(r"^The default features are:\r?\n((:?^.+?\r?\n)*)\r?\nAdditional features are:\r?\n((:?^.+?\r?\n)*)").multi_line(true).build().unwrap(); + let linesre = RegexBuilder::new(r"^\*(.+?)$") + .multi_line(true) + .build() + .unwrap(); + let blocks = blocksre.captures(&readme).unwrap(); + are_captures_sorted( + linesre.captures_iter(blocks.get(1).unwrap().as_str()), + "README.md default features", + )?; + are_captures_sorted( + linesre.captures_iter(blocks.get(3).unwrap().as_str()), + "README.md additional features", + ) +} + +#[test] +fn test_librs() -> Result<(), String> { + let librs = std::fs::read_to_string("src/lib.rs").unwrap(); + let modsre = RegexBuilder::new(r"(^pub mod .+?$)") + .multi_line(true) + .build() + .unwrap(); + are_captures_sorted(modsre.captures_iter(&librs), "lib.rs") +} + +#[test] +fn test_cargotoml() -> Result<(), String> { + let cargotoml = std::fs::read_to_string("Cargo.toml").unwrap(); + let blocksre = RegexBuilder::new(r"^# default features\r?\n((:?^.+?\r?\n)*)\r?\n# additional features\r?\n((:?^.+?\r?\n)*)\r?\n#").multi_line(true).build().unwrap(); + let linesre = RegexBuilder::new(r"^(\w.+?)$") + .multi_line(true) + .build() + .unwrap(); + let blocks = blocksre.captures(&cargotoml).unwrap(); + are_captures_sorted( + linesre.captures_iter(blocks.get(1).unwrap().as_str()), + "Cargo.toml default features", + )?; + are_captures_sorted( + linesre.captures_iter(blocks.get(3).unwrap().as_str()), + "Cargo.toml additional features", + ) +}