From a952966ab91e5b1dbf08890e7783e1dad65fcdf4 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Tue, 28 Dec 2021 15:01:17 +0200 Subject: [PATCH 1/5] Cursed tests --- Cargo.toml | 5 ++++- README.md | 2 +- tests/abc-tests.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/abc-tests.rs diff --git a/Cargo.toml b/Cargo.toml index afbbc3bc..a90362e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,10 +62,13 @@ 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"] unzip = ["zip", "jobs"] worleynoise = ["rand","dmsort"] # internal feature-like things jobs = ["flume"] + +[dev-dependencies] +regex = "1" diff --git a/README.md b/README.md index c4ed4ea3..83e41cfa 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,8 @@ 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. -* url: Faster replacements for `url_encode` and `url_decode`. * unzip: Function to download a .zip from a URL and unzip it to a directory. +* 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..3dd2d340 --- /dev/null +++ b/tests/abc-tests.rs @@ -0,0 +1,43 @@ +extern crate regex; +use regex::{Regex,RegexBuilder,CaptureMatches}; +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)*)").multi_line(true).build().unwrap(); + let linesre = RegexBuilder::new(r"^\*(.+?)$").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") +} From 24db68b9dd7de7d88be546d62214fdccef32fdce Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Tue, 28 Dec 2021 15:05:21 +0200 Subject: [PATCH 2/5] unused import --- tests/abc-tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/abc-tests.rs b/tests/abc-tests.rs index 3dd2d340..7c5fd5b8 100644 --- a/tests/abc-tests.rs +++ b/tests/abc-tests.rs @@ -1,5 +1,5 @@ extern crate regex; -use regex::{Regex,RegexBuilder,CaptureMatches}; +use regex::{RegexBuilder,CaptureMatches}; use std::cmp::Ordering; fn are_captures_sorted(matches: CaptureMatches, context: &str) -> Result<(), String> { From bde0926b10d03ea092ba6a8639fb56b635962045 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Tue, 28 Dec 2021 15:15:52 +0200 Subject: [PATCH 3/5] cargo.toml test fix --- tests/abc-tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/abc-tests.rs b/tests/abc-tests.rs index 7c5fd5b8..64a0b1b7 100644 --- a/tests/abc-tests.rs +++ b/tests/abc-tests.rs @@ -35,8 +35,8 @@ fn test_librs() -> Result<(), String> { #[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)*)").multi_line(true).build().unwrap(); - let linesre = RegexBuilder::new(r"^\*(.+?)$").multi_line(true).build().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") From 57f77e5a716eecbe7f5579dd9a272a04e6a80da4 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Thu, 30 Dec 2021 22:48:54 +0200 Subject: [PATCH 4/5] Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) 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", From b645d64af91f3a04fa51a8293a52fe6a4d222a4f Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Thu, 30 Dec 2021 23:03:22 +0200 Subject: [PATCH 5/5] rustfmt --- tests/abc-tests.rs | 48 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/tests/abc-tests.rs b/tests/abc-tests.rs index 64a0b1b7..0923c669 100644 --- a/tests/abc-tests.rs +++ b/tests/abc-tests.rs @@ -1,5 +1,5 @@ extern crate regex; -use regex::{RegexBuilder,CaptureMatches}; +use regex::{CaptureMatches, RegexBuilder}; use std::cmp::Ordering; fn are_captures_sorted(matches: CaptureMatches, context: &str) -> Result<(), String> { @@ -7,28 +7,43 @@ fn are_captures_sorted(matches: CaptureMatches, context: &str) -> Result<(), Str 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; } - }; + 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 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") + 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(); + let modsre = RegexBuilder::new(r"(^pub mod .+?$)") + .multi_line(true) + .build() + .unwrap(); are_captures_sorted(modsre.captures_iter(&librs), "lib.rs") } @@ -36,8 +51,17 @@ fn test_librs() -> Result<(), String> { 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 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") + 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", + ) }