From 45409c4ff390014bfd9d684a90c776c3dcff019c Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 6 Sep 2024 12:46:54 +0200 Subject: [PATCH] test: add tests for raw mode --- tests/format.rs | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/tests/format.rs b/tests/format.rs index 78aa896..609a935 100644 --- a/tests/format.rs +++ b/tests/format.rs @@ -41,6 +41,9 @@ fn format() { Format::Base64.format_str(0x4141414141414141, &options), "QUFBQUFBQUE=" ); + + assert_eq!(Format::Raw.format(0x1337, &options), vec![0x13, 0x37]); + assert_eq!(Format::Raw.format(0x0, &options), vec![0x0]); } #[test] @@ -91,6 +94,9 @@ fn format_padding() { Format::Base64.format_str(0x4141414141414141, &options), "QUFBQUFBQUE=" ); + + assert_eq!(Format::Raw.format(0x1337, &options), vec![0x13, 0x37]); + assert_eq!(Format::Raw.format(0x0, &options), vec![0x0]); } #[test] @@ -142,6 +148,9 @@ fn format_prefix() { Format::Base64.format_str(0x4141414141414141, &options), "0sQUFBQUFBQUE=" ); + + assert_eq!(Format::Raw.format(0x1337, &options), vec![0x0, 0x13, 0x37]); + assert_eq!(Format::Raw.format(0x0, &options), vec![0x0, 0x0]); } #[test] @@ -199,6 +208,9 @@ fn format_padded_prefix() { Format::Base64.format_str(0x4141414141414141, &options), "0sQUFBQUFBQUE=" ); + + assert_eq!(Format::Raw.format(0x1337, &options), vec![0x0, 0x13, 0x37]); + assert_eq!(Format::Raw.format(0x0, &options), vec![0x0, 0x0]); } #[test] @@ -215,41 +227,46 @@ fn set_format_checker() { #[test] fn parser_dec() { - assert_eq!(numf_parser::("1337").unwrap(), 1337); - assert_eq!(numf_parser::("0d1337").unwrap(), 1337); + assert_eq!(numf_parser_str::("1337").unwrap(), 1337); + assert_eq!(numf_parser_str::("0d1337").unwrap(), 1337); } #[test] fn parser_bin() { - assert_eq!(numf_parser::("0b11001").unwrap(), 0b11001); - assert_eq!(numf_parser::("0b11001").unwrap(), 0b11001); + assert_eq!(numf_parser_str::("0b11001").unwrap(), 0b11001); + assert_eq!(numf_parser_str::("0b11001").unwrap(), 0b11001); } #[test] fn parser_hex() { - assert_eq!(numf_parser::("0xdeadbeef").unwrap(), 0xdeadbeef); + assert_eq!(numf_parser_str::("0xdeadbeef").unwrap(), 0xdeadbeef); } #[test] fn parser_oct() { - assert_eq!(numf_parser::("0o771171").unwrap(), 0o771171); + assert_eq!(numf_parser_str::("0o771171").unwrap(), 0o771171); } #[test] fn parser_b64() { - assert_eq!(numf_parser::("0sQUFCQg==").unwrap(), 0x41414242); + assert_eq!(numf_parser_str::("0sQUFCQg==").unwrap(), 0x41414242); } #[test] fn parser_b32() { - assert_eq!(numf_parser::("032sIFAUEQQ=").unwrap(), 0x41414242); + assert_eq!(numf_parser_str::("032sIFAUEQQ=").unwrap(), 0x41414242); +} + +#[test] +fn parser_raw() { + assert_eq!(numf_parser_str::("\x00\x50\x60").unwrap(), 0x5060); } #[test] fn parser_generics() { - assert_eq!(numf_parser::("55").unwrap(), 55); - assert_eq!(numf_parser::("55").unwrap(), 55); - assert_eq!(numf_parser::("55").unwrap(), 55); - assert_eq!(numf_parser::("55").unwrap(), 55); - assert_eq!(numf_parser::("55").unwrap(), 55); + assert_eq!(numf_parser_str::("55").unwrap(), 55); + assert_eq!(numf_parser_str::("55").unwrap(), 55); + assert_eq!(numf_parser_str::("55").unwrap(), 55); + assert_eq!(numf_parser_str::("55").unwrap(), 55); + assert_eq!(numf_parser_str::("55").unwrap(), 55); }