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

This commit is contained in:
2026-06-06 13:52:00 -04:00
parent cbbd6298ec
commit 84f19e6b16
4 changed files with 35 additions and 12 deletions
Generated
+1 -1
View File
@@ -214,7 +214,7 @@ dependencies = [
[[package]]
name = "clean_file"
version = "0.8.3"
version = "0.8.4"
dependencies = [
"async-std",
"futures",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "clean_file"
version = "0.8.3"
version = "0.8.4"
edition = "2024"
rust-version = "1.95"
+1 -1
View File
@@ -23,7 +23,7 @@ async fn main() {
match prsr.file_dump().await {
Ok(contacts) => {
prsr.print_phone_numbers(&contacts);
prsr.save_file(contacts).await;
prsr.save_file(contacts, parser::DEFAULT_OUTPUT_FILE).await;
}
Err(err) => {
eprintln!("Error: {err:?}");
+32 -9
View File
@@ -1,5 +1,6 @@
use std::io::BufRead;
pub const DEFAULT_OUTPUT_FILE: &str = "numbers.json";
const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
#[derive(Clone, Debug, Default)]
@@ -40,9 +41,8 @@ impl NumberParser {
}
}
pub async fn save_file(&self, numbers: Vec<textsender_models::contact::Contact>) {
let filename = String::from("numbers.json");
pub async fn save_file(&self, numbers: Vec<textsender_models::contact::Contact>, filename: &str) {
// let filename = String::from("numbers.json");
match serde_json::to_string(&numbers) {
Ok(json_string) => match std::fs::write(&filename, json_string) {
Ok(_) => {
@@ -170,9 +170,11 @@ impl NumberParser {
mod tests {
use textsender_models::contact::Contact;
const TEST_NUMBERS_0: &str = "tests/numbers-0.txt";
#[test]
fn test_file_dump() {
let filename = String::from("tests/numbers-0.txt");
let filename = String::from(TEST_NUMBERS_0);
let file_exists = {
let path = std::path::Path::new(filename.as_str());
path.exists()
@@ -181,7 +183,7 @@ mod tests {
assert_eq!(true, file_exists, "File does not exists {filename:?}");
let prsr = super::NumberParser { filepath: filename };
let original: Vec<textsender_models::contact::Contact> = vec![
let original: Vec<Contact> = vec![
Contact {
phone_number: String::from("+13055550112"),
..Default::default()
@@ -216,9 +218,6 @@ mod tests {
},
];
match async_std::task::block_on(prsr.file_dump()) {
Ok(contacts) => {
assert!((contacts.len() > 0), "No contacts has been parsed");
@@ -234,5 +233,29 @@ mod tests {
}
#[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:?}");
}
}
}
}