Compare commits

..

2 Commits

Author SHA1 Message Date
bdeefdb3b6 more formatting 2026-05-03 08:50:55 -04:00
e3b8939082 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
2026-04-14 07:43:20 -04:00
7 changed files with 32 additions and 11 deletions

View File

@ -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/*"

View File

@ -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<u8>) {
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<u8>> = 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);
}
}

View File

@ -30,7 +30,7 @@ impl DataToText {
let ascii_char = if byte.is_ascii_graphic() {
*byte as char
} else {
'.'
' '
};
ascii_line.push(ascii_char);

View File

@ -6,3 +6,6 @@ pub fn bool_to_string(b: bool) -> String {
}
}
pub fn bool_array_to_string(b: &[bool]) -> String {
b.iter().map(|b| bool_to_string(*b)).collect::<Vec<String>>().join("")
}

View File

@ -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, "");
}

View File

@ -2,3 +2,4 @@ mod data_to_text;
mod number_system_conversion;
mod test_compression;
mod format_with_commas;
mod primitive_formatting;

View File

@ -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));
}