-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fzf bugfix: find by hash instead of alias
- Loading branch information
1 parent
f8b390d
commit d2385c7
Showing
6 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
use crate::{authors::author::Author, common::conf}; | ||
use parameterized::parameterized; | ||
use std::collections::hash_map::DefaultHasher; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[test] | ||
fn present_a_co_author_compliant_signature() { | ||
|
@@ -27,6 +29,15 @@ fn get_name() { | |
assert_eq!(author.name(), name); | ||
} | ||
|
||
#[test] | ||
fn get_hash() { | ||
let alias = "a"; | ||
let name = "alice"; | ||
let author = Author::from(alias, name, "[email protected]"); | ||
|
||
assert_eq!(author.hash(), hash_of(&format!("{alias}{name}"))); | ||
} | ||
|
||
#[test] | ||
fn be_equal_to_another_author_with_same_data() { | ||
let alias = "a"; | ||
|
@@ -47,3 +58,9 @@ fn be_equal_to_another_author_with_same_data() { | |
fn not_be_equal_to_another_author_with_different_data(different_author: Author) { | ||
assert_ne!(Author::from("a", "alice", "[email protected]"), different_author); | ||
} | ||
|
||
fn hash_of(str: &str) -> u64 { | ||
let mut hasher = DefaultHasher::new(); | ||
str.hash(&mut hasher); | ||
hasher.finish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ use super::provider::LoadMode; | |
use crate::authors::author::AuthorsProvider; | ||
use crate::authors::csv::provider::CSVProvider; | ||
use crate::common::fs::file_reader::MockReader; | ||
use std::collections::hash_map::DefaultHasher; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[test] | ||
fn all_authors_in_file() { | ||
|
@@ -22,7 +24,7 @@ fn only_author_matching_an_alias() { | |
"b,username,[email protected]".to_string(), | ||
]); | ||
|
||
let retrieved_authors = provider.find(&["a".to_string()]); | ||
let retrieved_authors = provider.find_by_aliases(&["a".to_string()]); | ||
|
||
assert_eq!(retrieved_authors.len(), 1); | ||
} | ||
|
@@ -35,7 +37,7 @@ fn all_authors_matching_an_alias() { | |
"b,username2,[email protected]".to_string(), | ||
]); | ||
|
||
let retrieved_authors = provider.find(&["b".to_string()]); | ||
let retrieved_authors = provider.find_by_aliases(&["b".to_string()]); | ||
|
||
assert_eq!(retrieved_authors.len(), 2); | ||
} | ||
|
@@ -44,7 +46,29 @@ fn all_authors_matching_an_alias() { | |
fn no_author_when_alias_doesnt_match() { | ||
let provider = csv_provider_with(vec!["a,Name Surname,[email protected]".to_string()]); | ||
|
||
let retrieved_authors = provider.find(&["z".to_string()]); | ||
let retrieved_authors = provider.find_by_aliases(&["z".to_string()]); | ||
|
||
assert_eq!(retrieved_authors.len(), 0); | ||
} | ||
|
||
#[test] | ||
fn only_author_matching_a_hash() { | ||
let provider = csv_provider_with(vec![ | ||
"a,Name Surname,[email protected]".to_string(), | ||
"a,Another Name Surname,[email protected]".to_string(), | ||
"b,username,[email protected]".to_string(), | ||
]); | ||
|
||
let retrieved_authors = provider.find_by_hashes(&[hash_of("aName Surname")]); | ||
|
||
assert_eq!(retrieved_authors.len(), 1); | ||
} | ||
|
||
#[test] | ||
fn no_author_when_hash_doesnt_match() { | ||
let provider = csv_provider_with(vec!["a,Name Surname,[email protected]".to_string()]); | ||
|
||
let retrieved_authors = provider.find_by_hashes(&[hash_of("zIrrelevant")]); | ||
|
||
assert_eq!(retrieved_authors.len(), 0); | ||
} | ||
|
@@ -60,3 +84,9 @@ fn csv_provider_with(authors: Vec<String>) -> CSVProvider { | |
}) | ||
.expect("Could not setup AuthorsProvider for test") | ||
} | ||
|
||
fn hash_of(str: &str) -> u64 { | ||
let mut hasher = DefaultHasher::new(); | ||
str.hash(&mut hasher); | ||
hasher.finish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters