#[cfg(test)]
mod test {
use std::collections::HashMap;
#[test]
#[should_panic]
fn http_get() {
assert_ne!(blindfold::http_get("https://api.github.com/repos/toptal/gitignore/\
contents/templates?ref=master"), "");
panic!(blindfold::http_get("www.notarealsite/foo/bar"));
}
#[test]
fn generate_gitignore_file() {
let mut map: HashMap<String, String> = HashMap::new();
map.insert(String::from("rust"),
String::from("https://raw.githubusercontent.com/toptal/gitignore/\
master/templates/Rust.gitignore"));
let langs = vec!["rust"];
let empty_lang = vec![""];
let has_empty_lang = vec!["", "rust"];
assert_eq!(blindfold::generate_gitignore_file(langs, &map),
"# RUST gitignore generated by Blindfold\n\n# Generated by Cargo\n# will have compiled files and executables\n/target/\n\n# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries\n# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html\nCargo.lock\n\n# These are backup files generated by rustfmt\n**/*.rs.bk\n\n\n");
assert_eq!(blindfold::generate_gitignore_file(empty_lang, &map), "");
assert_eq!(blindfold::generate_gitignore_file(has_empty_lang, &map),
"# RUST gitignore generated by Blindfold\n\n# Generated by Cargo\n# will have compiled files and executables\n/target/\n\n# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries\n# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html\nCargo.lock\n\n# These are backup files generated by rustfmt\n**/*.rs.bk\n\n\n");
}
#[test]
fn get_gitignore_file() {
let mut map: HashMap<String, String> = HashMap::new();
map.insert(String::from("rust"), String::from("https://raw.githubusercontent.com/toptal/gitignore/\
master/templates/Rust.gitignore"));
let language = "rust";
assert_eq!(blindfold::get_raw_ignore_file(&map, language),
"# Generated by Cargo\n# will have compiled files and executables\n/target/\n\n# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries\n# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html\nCargo.lock\n\n# These are backup files generated by rustfmt\n**/*.rs.bk\n");
assert_eq!(blindfold::get_raw_ignore_file(&map, ""), "");
}
#[test]
fn suggest_most_similar() {
let mut map: HashMap<String, String> = HashMap::new();
map.insert(String::from("rust"), String::from("rust gitignore url"));
map.insert(String::from("c++"), String::from("c++ gitignore url"));
let language = "roost";
let dissimilar_language = "this is not a language, but should still give a suggestion";
let yes_input = b"y";
let no_input = b"n";
let mut output = Vec::new();
let yes_answer = blindfold::suggest_most_similar(&yes_input[..],
&mut output,
&language,
map.clone());
let no_answer = blindfold::suggest_most_similar(&no_input[..],
&mut output,
&language,
map.clone());
let yes_answer_dissimilar = blindfold::suggest_most_similar(&yes_input[..],
&mut output,
&dissimilar_language,
map.clone());
assert_eq!(yes_answer, Some(String::from("rust")));
assert_eq!(no_answer, None);
assert_ne!(yes_answer_dissimilar, None);
}
}