Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds alphabetical order tests for README.md, lib.rs and Cargo.toml #84

Merged
merged 6 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ 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"]
worleynoise = ["rand","dmsort"]

# internal feature-like things
jobs = ["flume"]

[dev-dependencies]
regex = "1"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
67 changes: 67 additions & 0 deletions tests/abc-tests.rs
Original file line number Diff line number Diff line change
@@ -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",
)
}