diff --git a/Cargo.lock b/Cargo.lock index ae5cda1..f780999 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,7 +372,7 @@ dependencies = [ [[package]] name = "trevors_utilities" -version = "0.1.0" +version = "0.1.0-20250606" dependencies = [ "clap", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 665fb4b..53eb73b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trevors_utilities" -version = "0.1.0" +version = "0.1.0-20250606" edition = "2024" [dependencies] diff --git a/resources/data_to_text/q.bin b/resources/data_to_text/q.bin new file mode 100644 index 0000000..ea0c8a8 --- /dev/null +++ b/resources/data_to_text/q.bin @@ -0,0 +1 @@ +q \ No newline at end of file diff --git a/resources/data_to_text/q.display b/resources/data_to_text/q.display new file mode 100644 index 0000000..d09ea3c --- /dev/null +++ b/resources/data_to_text/q.display @@ -0,0 +1 @@ +0x71 q diff --git a/resources/data_to_text/quickbrownfoxtest.bin b/resources/data_to_text/quickbrownfox.bin similarity index 100% rename from resources/data_to_text/quickbrownfoxtest.bin rename to resources/data_to_text/quickbrownfox.bin diff --git a/resources/data_to_text/quickbrownfox.display b/resources/data_to_text/quickbrownfox.display index bb7c368..eee2a2d 100644 --- a/resources/data_to_text/quickbrownfox.display +++ b/resources/data_to_text/quickbrownfox.display @@ -1,3 +1,3 @@ -0x74 0x68 0x65 0x20 0x71 0x75 0x69 0x63 0x6b 0x20 0x62 0x72 0x6f 0x77 0x6e 0x20 the quick brown -0x66 0x6f 0x78 0x20 0x6a 0x75 0x6d 0x70 0x73 0x20 0x6f 0x76 0x65 0x72 0x20 0x74 fox jumps over t -0x68 0x65 0x20 0x6c 0x61 0x7a 0x79 0x20 0x64 0x6f 0x67 he lazy dog +0x74 0x68 0x65 0x20 0x71 0x75 0x69 0x63 0x6b 0x20 0x62 0x72 0x6f 0x77 0x6e 0x20 the quick brown +0x66 0x6f 0x78 0x20 0x6a 0x75 0x6d 0x70 0x65 0x64 0x20 0x6f 0x76 0x65 0x72 0x20 fox jumped over +0x74 0x68 0x65 0x20 0x6c 0x61 0x7a 0x79 0x20 0x64 0x6f 0x67 the lazy dog diff --git a/src/bin/gen_test.rs b/src/bin/gen_test.rs index cff71fe..b7e47ce 100644 --- a/src/bin/gen_test.rs +++ b/src/bin/gen_test.rs @@ -1,7 +1,7 @@ use trevors_utilities::data_to_text::DataToText; fn main() { - let text = "the quick brown fox jumps over the lazy dog"; + let text = "q"; let displayed_hex = DataToText::data_to_text(text.as_bytes()); diff --git a/tests/data_to_text.rs b/tests/data_to_text.rs index 649827f..5c75afa 100644 --- a/tests/data_to_text.rs +++ b/tests/data_to_text.rs @@ -1,12 +1,24 @@ use trevors_utilities::data_to_text::DataToText; +fn read_bin(source: &str) -> Vec { + let full_path = format!("/home/tmerritt/Projects/trevors_utilities/resources/data_to_text/{}.bin", source); + println!("FULL PATH BIN: [{}]", full_path); + std::fs::read(full_path).unwrap() +} + +fn read_display(source: &str) -> String { + let full_path = format!("/home/tmerritt/Projects/trevors_utilities/resources/data_to_text/{}.display", source); + println!("FULL PATH DIS: [{}]", full_path); + std::fs::read_to_string(full_path).unwrap() +} + #[test] fn data_to_text() { let data_to_display: &[u8] = &[ 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 "; + 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); @@ -15,13 +27,22 @@ fn data_to_text() { #[test] fn quickbrownfoxtest() { let test_params = vec![ - "quickbrownfox" + "quickbrownfox", + "q" ]; - // load the content from quickbrownfox.bin - // format it for display + for stub in test_params { + // load the content from quickbrownfox.bin + let bin_data = read_bin(stub); - // load the content from quickbrownfox.display + // format it for display + let formatted = DataToText::data_to_text(&bin_data); - // compare the formatted data to the loaded content. -} \ No newline at end of file + // load the content from quickbrownfox.display + let expected = read_display(stub); + + assert_eq!( + formatted, expected + ); + } +}