From 46a077d24cb3ee6894db696eac6fddf4d1de968a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 17 Jul 2024 19:17:03 -0500 Subject: [PATCH] test(binary): Cover more cases Pulled from rust-bakery/nom#1769 I skipped the float ones because I didn't feel like adapting them to the `binary` mod. --- src/binary/tests.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/binary/tests.rs b/src/binary/tests.rs index bc2a0058..9747b366 100644 --- a/src/binary/tests.rs +++ b/src/binary/tests.rs @@ -796,6 +796,22 @@ mod partial { ); } + #[test] + fn le_u16_tests() { + assert_parse!( + le_u16.parse_peek(Partial::new(&[0x00, 0x03][..])), + Ok((Partial::new(&b""[..]), 0x0300)) + ); + assert_parse!( + le_u16.parse_peek(Partial::new(&[b'a', b'b'][..])), + Ok((Partial::new(&b""[..]), 0x6261)) + ); + assert_parse!( + le_u16.parse_peek(Partial::new(&[0x01][..])), + Err(ErrMode::Incomplete(Needed::new(1))) + ); + } + #[test] fn le_i8_tests() { assert_parse!( @@ -868,6 +884,22 @@ mod partial { ); } + #[test] + fn le_u32_test() { + assert_parse!( + le_u32.parse_peek(Partial::new(&[0x00, 0x03, 0x05, 0x07][..])), + Ok((Partial::new(&b""[..]), 0x07050300)) + ); + assert_parse!( + le_u32.parse_peek(Partial::new(&[b'a', b'b', b'c', b'd'][..])), + Ok((Partial::new(&b""[..]), 0x64636261)) + ); + assert_parse!( + le_u32.parse_peek(Partial::new(&[0x01][..])), + Err(ErrMode::Incomplete(Needed::new(3))) + ); + } + #[test] fn le_i32_tests() { assert_parse!(