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
This commit is contained in:
parent
9852ef687d
commit
e3b8939082
@ -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/*"
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ impl DataToText {
|
||||
let ascii_char = if byte.is_ascii_graphic() {
|
||||
*byte as char
|
||||
} else {
|
||||
'.'
|
||||
' '
|
||||
};
|
||||
ascii_line.push(ascii_char);
|
||||
|
||||
|
||||
@ -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, "");
|
||||
}
|
||||
|
||||
@ -2,3 +2,4 @@ mod data_to_text;
|
||||
mod number_system_conversion;
|
||||
mod test_compression;
|
||||
mod format_with_commas;
|
||||
mod primitive_formatting;
|
||||
|
||||
7
tests/poc/primitive_formatting.rs
Normal file
7
tests/poc/primitive_formatting.rs
Normal 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));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user