Skip to content

Commit

Permalink
fix bug where inline Hexstrings would not get put on the same line as…
Browse files Browse the repository at this point in the history
… the Title when scrolling up
  • Loading branch information
misson20000 committed Aug 4, 2024
1 parent 8e31ab3 commit 92fa673
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/model/listing/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum LineType {
},
}

#[derive(Debug, PartialEq, Eq)]
enum LinePushResult {
Accepted,
Completed,
Expand Down Expand Up @@ -266,7 +267,7 @@ impl Line {
(LineType::Empty, token::Token::Hexstring(token)) => (LineType::Hexstring {
title: None,
token
}, LinePushResult::Completed),
}, LinePushResult::Accepted),

/* A title token can occur on the same line as a hexstring if the title is inline and there isn't already a title. */
(LineType::Hexstring { title: None, token: hexstring_token }, token::Token::Title(token))
Expand Down Expand Up @@ -540,3 +541,39 @@ impl fmt::Debug for Line {
.finish()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_hexstring_backwards_construction() {
let node = structure::Node::builder()
.name("foo")
.size(0x8)
.content_display(structure::ContentDisplay::Hexstring)
.title_display(structure::TitleDisplay::Inline)
.build();

let mut line = Line::empty();

assert_eq!(line.push_front(token::Token::Hexstring(token::HexstringToken {
common: token::TokenCommon {
node: node.clone(),
node_path: vec![],
node_addr: addr::unit::NULL,
depth: 0,
},
extent: addr::Extent::sized_u64(0, 8),
})), LinePushResult::Accepted);

assert_eq!(line.push_front(token::Token::Title(token::TitleToken {
common: token::TokenCommon {
node: node.clone(),
node_path: vec![],
node_addr: addr::unit::NULL,
depth: 0,
},
})), LinePushResult::Accepted);
}
}

0 comments on commit 92fa673

Please sign in to comment.