From 910a46ef9df724973c9055384320142740cf4a26 Mon Sep 17 00:00:00 2001 From: Christopher Cole Date: Sun, 13 Nov 2022 13:53:13 -0800 Subject: [PATCH] Add ParsingTable.is_empty() --- src/parse.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/parse.rs b/src/parse.rs index e2284da..34ebdf9 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -268,6 +268,10 @@ impl<'data, E: EndianParse, P: ParseAt> ParsingTable<'data, E, P> { self.data.len() / P::size_for(self.class) } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn get(&self, index: usize) -> Result { if self.data.is_empty() { return Err(ParseError::BadOffset(index as u64)); @@ -417,6 +421,19 @@ mod parsing_table_tests { assert_eq!(table.len(), 2); } + #[test] + fn test_u32_table_is_empty() { + let data = vec![0u8, 1, 2, 3, 4, 5, 6, 7]; + let table = U32Table::new(LittleEndian, Class::ELF32, data.as_ref()); + assert!(!table.is_empty()); + + let table = U32Table::new(LittleEndian, Class::ELF32, &[]); + assert!(table.is_empty()); + + let table = U32Table::new(LittleEndian, Class::ELF32, data.get(0..1).unwrap()); + assert!(table.is_empty()); + } + #[test] fn test_u32_table_get_parse_failure() { let data = vec![0u8, 1];