Code cleanup
Rust Build / Check (pull_request) Successful in 27s
Rust Build / Test Suite (pull_request) Successful in 30s
Rust Build / Rustfmt (pull_request) Successful in 38s
Rust Build / Clippy (pull_request) Failing after 31s
Rust Build / build (pull_request) Successful in 39s
Rust Build / Check (pull_request) Successful in 27s
Rust Build / Test Suite (pull_request) Successful in 30s
Rust Build / Rustfmt (pull_request) Successful in 38s
Rust Build / Clippy (pull_request) Failing after 31s
Rust Build / build (pull_request) Successful in 39s
This commit is contained in:
+17
-10
@@ -41,7 +41,11 @@ impl NumberParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn save_file(&self, numbers: Vec<textsender_models::contact::Contact>, filename: &str) {
|
pub async fn save_file(
|
||||||
|
&self,
|
||||||
|
numbers: Vec<textsender_models::contact::Contact>,
|
||||||
|
filename: &str,
|
||||||
|
) {
|
||||||
// let filename = String::from("numbers.json");
|
// let filename = String::from("numbers.json");
|
||||||
match serde_json::to_string(&numbers) {
|
match serde_json::to_string(&numbers) {
|
||||||
Ok(json_string) => match std::fs::write(&filename, json_string) {
|
Ok(json_string) => match std::fs::write(&filename, json_string) {
|
||||||
@@ -167,6 +171,7 @@ impl NumberParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use textsender_models::contact::Contact;
|
use textsender_models::contact::Contact;
|
||||||
|
|
||||||
@@ -174,14 +179,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_dump() {
|
fn test_file_dump() {
|
||||||
let filename = String::from(TEST_NUMBERS_0);
|
|
||||||
let file_exists = {
|
let file_exists = {
|
||||||
let path = std::path::Path::new(filename.as_str());
|
let path = std::path::Path::new(TEST_NUMBERS_0);
|
||||||
path.exists()
|
path.exists()
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(true, file_exists, "File does not exists {filename:?}");
|
assert_eq!(true, file_exists, "File does not exists {TEST_NUMBERS_0:?}");
|
||||||
|
|
||||||
|
let filename = String::from(TEST_NUMBERS_0);
|
||||||
let prsr = super::NumberParser { filepath: filename };
|
let prsr = super::NumberParser { filepath: filename };
|
||||||
let original: Vec<Contact> = vec![
|
let original: Vec<Contact> = vec![
|
||||||
Contact {
|
Contact {
|
||||||
@@ -222,8 +227,10 @@ mod tests {
|
|||||||
Ok(contacts) => {
|
Ok(contacts) => {
|
||||||
assert!((contacts.len() > 0), "No contacts has been parsed");
|
assert!((contacts.len() > 0), "No contacts has been parsed");
|
||||||
|
|
||||||
let phone_numbers_1: std::collections::HashSet<_> = contacts.iter().map(|p| p.phone_number.clone()).collect();
|
let phone_numbers_1: std::collections::HashSet<_> =
|
||||||
let phone_numbers_2: std::collections::HashSet<_> = original.iter().map(|p| p.phone_number.clone()).collect();
|
contacts.iter().map(|p| p.phone_number.clone()).collect();
|
||||||
|
let phone_numbers_2: std::collections::HashSet<_> =
|
||||||
|
original.iter().map(|p| p.phone_number.clone()).collect();
|
||||||
assert_eq!(phone_numbers_1, phone_numbers_2, "No match");
|
assert_eq!(phone_numbers_1, phone_numbers_2, "No match");
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -234,9 +241,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_save_file() {
|
fn test_save_file() {
|
||||||
let filename = String::from(TEST_NUMBERS_0);
|
let prsr = super::NumberParser {
|
||||||
|
filepath: String::from(TEST_NUMBERS_0),
|
||||||
let prsr = super::NumberParser { filepath: filename };
|
};
|
||||||
let results = async_std::task::block_on(prsr.file_dump());
|
let results = async_std::task::block_on(prsr.file_dump());
|
||||||
assert!(results.is_ok(), "File dump not successful");
|
assert!(results.is_ok(), "File dump not successful");
|
||||||
let test_output_file: &str = "test-numbers.json";
|
let test_output_file: &str = "test-numbers.json";
|
||||||
@@ -244,7 +251,7 @@ mod tests {
|
|||||||
let contacts = results.unwrap();
|
let contacts = results.unwrap();
|
||||||
async_std::task::block_on(prsr.save_file(contacts, test_output_file));
|
async_std::task::block_on(prsr.save_file(contacts, test_output_file));
|
||||||
let file_exists = {
|
let file_exists = {
|
||||||
let path = std::path::Path::new("numbers.json");
|
let path = std::path::Path::new(test_output_file);
|
||||||
path.exists()
|
path.exists()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user