Test cleanup
Rust Build / Check (pull_request) Failing after 26s
Rust Build / Test Suite (pull_request) Failing after 34s
Rust Build / build (pull_request) Failing after 26s
Rust Build / Rustfmt (pull_request) Failing after 25s
Rust Build / Clippy (pull_request) Failing after 30s
Rust Build / Check (pull_request) Failing after 26s
Rust Build / Test Suite (pull_request) Failing after 34s
Rust Build / build (pull_request) Failing after 26s
Rust Build / Rustfmt (pull_request) Failing after 25s
Rust Build / Clippy (pull_request) Failing after 30s
This commit is contained in:
Generated
+1
-1
@@ -214,7 +214,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clean_file"
|
name = "clean_file"
|
||||||
version = "0.8.3"
|
version = "0.8.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"futures",
|
"futures",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "clean_file"
|
name = "clean_file"
|
||||||
version = "0.8.3"
|
version = "0.8.4"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ async fn main() {
|
|||||||
match prsr.file_dump().await {
|
match prsr.file_dump().await {
|
||||||
Ok(contacts) => {
|
Ok(contacts) => {
|
||||||
prsr.print_phone_numbers(&contacts);
|
prsr.print_phone_numbers(&contacts);
|
||||||
prsr.save_file(contacts).await;
|
prsr.save_file(contacts, parser::DEFAULT_OUTPUT_FILE).await;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
|
|||||||
+32
-9
@@ -1,5 +1,6 @@
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
|
||||||
|
pub const DEFAULT_OUTPUT_FILE: &str = "numbers.json";
|
||||||
const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
@@ -40,9 +41,8 @@ impl NumberParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn save_file(&self, numbers: Vec<textsender_models::contact::Contact>) {
|
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) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
@@ -170,9 +170,11 @@ impl NumberParser {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use textsender_models::contact::Contact;
|
use textsender_models::contact::Contact;
|
||||||
|
|
||||||
|
const TEST_NUMBERS_0: &str = "tests/numbers-0.txt";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_dump() {
|
fn test_file_dump() {
|
||||||
let filename = String::from("tests/numbers-0.txt");
|
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(filename.as_str());
|
||||||
path.exists()
|
path.exists()
|
||||||
@@ -181,7 +183,7 @@ mod tests {
|
|||||||
assert_eq!(true, file_exists, "File does not exists {filename:?}");
|
assert_eq!(true, file_exists, "File does not exists {filename:?}");
|
||||||
|
|
||||||
let prsr = super::NumberParser { filepath: filename };
|
let prsr = super::NumberParser { filepath: filename };
|
||||||
let original: Vec<textsender_models::contact::Contact> = vec![
|
let original: Vec<Contact> = vec![
|
||||||
Contact {
|
Contact {
|
||||||
phone_number: String::from("+13055550112"),
|
phone_number: String::from("+13055550112"),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -216,9 +218,6 @@ mod tests {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
match async_std::task::block_on(prsr.file_dump()) {
|
match async_std::task::block_on(prsr.file_dump()) {
|
||||||
Ok(contacts) => {
|
Ok(contacts) => {
|
||||||
assert!((contacts.len() > 0), "No contacts has been parsed");
|
assert!((contacts.len() > 0), "No contacts has been parsed");
|
||||||
@@ -234,5 +233,29 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_save_file() {}
|
fn test_save_file() {
|
||||||
|
let filename = String::from(TEST_NUMBERS_0);
|
||||||
|
|
||||||
|
let prsr = super::NumberParser { filepath: filename };
|
||||||
|
let results = async_std::task::block_on(prsr.file_dump());
|
||||||
|
assert!(results.is_ok(), "File dump not successful");
|
||||||
|
let test_output_file: &str = "test-numbers.json";
|
||||||
|
|
||||||
|
let contacts = results.unwrap();
|
||||||
|
async_std::task::block_on(prsr.save_file(contacts, test_output_file));
|
||||||
|
let file_exists = {
|
||||||
|
let path = std::path::Path::new("numbers.json");
|
||||||
|
path.exists()
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(file_exists, "Contacts were not saved");
|
||||||
|
match std::fs::remove_file(test_output_file) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("File removed");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user