From e3b893908205d30702ac080403d488c27277b601 Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Tue, 14 Apr 2026 07:43:20 -0400 Subject: [PATCH] config.toml: remove excluded files for coverage report data_to_text.rs: change from . as unrecognized character to ' ' demo.rs: improves POC display of headers tests/primitive_formatting.rs: initial tests of bool formatting --- .cargo/config.toml | 2 +- src/bin/demo.rs | 19 +++++++++++-------- src/data_to_text.rs | 2 +- tests/poc/data_to_text.rs | 9 ++++++++- tests/poc/mod.rs | 1 + tests/poc/primitive_formatting.rs | 7 +++++++ 6 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 tests/poc/primitive_formatting.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 320b8e2..ca4c2bf 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -coverage = "tarpaulin --out Html --skip-clean --output-dir coverage" +coverage = "tarpaulin --out Html --skip-clean --output-dir coverage --exclude-files src/bin/* --exclude-files tests/*" diff --git a/src/bin/demo.rs b/src/bin/demo.rs index 7f5dd0e..f4259f8 100644 --- a/src/bin/demo.rs +++ b/src/bin/demo.rs @@ -1,13 +1,18 @@ -#![feature(trusted_random_access)] - -use std::iter::TrustedRandomAccessNoCoerce; use std::time::Duration; use trevors_utilities::data_to_text::DataToText; use trevors_utilities::duration_to_string::duration_to_string::{duration_to_string, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE}; use trevors_utilities::format_with_commas::format_with_commas; +fn demo_header(title: &str, width: Option) { + let width = width.unwrap_or(80) as usize; + let num_leading = (width - title.len() - 4) / 2; + println!("{}{}", "-".repeat(width), ""); + println!("|{}{} {}|", " ".repeat(num_leading), title, " ".repeat(num_leading)); + println!("{}{}", "-".repeat(width), ""); +} + fn duration_to_string_demo() { - println!("**This is the duration_to_string demo**"); + demo_header("Duration to String", None); println!(); let options = vec![ @@ -28,16 +33,14 @@ fn duration_to_string_demo() { } fn data_to_text_demo() { - println!("**Data To Text**"); + demo_header("Data To Text", None); let options: Vec> = vec![ (0..=255).collect(), (0..128).collect(), (0x20..=0x7f).collect() ]; - for option in options { - let sizeof = option.iter().size(); - let data = DataToText::data_to_text(option.as_slice()); + for option in options { let data = DataToText::data_to_text(option.as_slice()); println!("{}", data); } } diff --git a/src/data_to_text.rs b/src/data_to_text.rs index 9819754..c0d7493 100644 --- a/src/data_to_text.rs +++ b/src/data_to_text.rs @@ -30,7 +30,7 @@ impl DataToText { let ascii_char = if byte.is_ascii_graphic() { *byte as char } else { - '.' + ' ' }; ascii_line.push(ascii_char); diff --git a/tests/poc/data_to_text.rs b/tests/poc/data_to_text.rs index 8dd2f82..3dffb2d 100644 --- a/tests/poc/data_to_text.rs +++ b/tests/poc/data_to_text.rs @@ -33,7 +33,7 @@ fn data_to_text() { 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x20, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x20, ]; - let expected_data: &str = "0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 0x74 0x20 fghijklmnopqrst \n0x76 0x77 0x78 0x79 0x7a 0x7b 0x7c 0x7d 0x7e 0x7f 0x20 vwxyz{|}~..\n"; + let expected_data: &str = "0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 0x74 0x20 fghijklmnopqrst \n0x76 0x77 0x78 0x79 0x7a 0x7b 0x7c 0x7d 0x7e 0x7f 0x20 vwxyz{|}~ \n"; let actual_data = DataToText::data_to_text(data_to_display); assert_eq!(actual_data, expected_data); @@ -64,3 +64,10 @@ fn data_to_text_window_all() { let expected = read_display("quickbrownfox"); assert_eq!(formatted, expected); } + +#[test] +fn test_window_past_end_of_data() { + let bin_data = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06]; + let formatted = DataToText::data_to_text_window(&bin_data, 10, 10); + assert_eq!(formatted, ""); +} diff --git a/tests/poc/mod.rs b/tests/poc/mod.rs index 9ab5520..89737a9 100644 --- a/tests/poc/mod.rs +++ b/tests/poc/mod.rs @@ -2,3 +2,4 @@ mod data_to_text; mod number_system_conversion; mod test_compression; mod format_with_commas; +mod primitive_formatting; diff --git a/tests/poc/primitive_formatting.rs b/tests/poc/primitive_formatting.rs new file mode 100644 index 0000000..9e7222e --- /dev/null +++ b/tests/poc/primitive_formatting.rs @@ -0,0 +1,7 @@ +use trevors_utilities::primitive_formatting; + +#[test] +fn test_primitive_bool() { + assert_eq!("1".to_string(), primitive_formatting::bool_to_string(true)); + assert_eq!("0".to_string(), primitive_formatting::bool_to_string(false)); +}