#[derive(Clone, Debug, Default)]
pub struct Line {
pub offset: u64,
pub hex_body: Vec<u8>,
pub ascii: Vec<u8>,
pub bytes: u64,
}
impl Line {
pub fn new() -> Line {
Line {
offset: 0x0,
hex_body: Vec::new(),
ascii: Vec::new(),
bytes: 0x0,
}
}
}
#[derive(Clone, Debug, Default)]
pub struct Page {
pub offset: u64,
pub body: Vec<Line>,
pub bytes: u64,
}
impl Page {
pub fn new() -> Page {
Page {
offset: 0x0,
body: Vec::new(),
bytes: 0x0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_line_struct() {
let mut ascii_line: Line = Line::new();
ascii_line.ascii.push(b'.');
assert_eq!(ascii_line.ascii[0], b'.');
assert_eq!(ascii_line.offset, 0x0);
}
#[test]
fn test_line_default() {
let line = Line::new();
assert_eq!(line.offset, 0x0);
assert_eq!(line.hex_body.len(), 0);
assert_eq!(line.ascii.len(), 0);
assert_eq!(line.bytes, 0x0);
}
#[test]
fn test_line_with_data() {
let mut line = Line::new();
line.hex_body.push(0x42);
line.hex_body.push(0x43);
line.ascii.push(b'B');
line.ascii.push(b'C');
line.bytes = 2;
line.offset = 0x100;
assert_eq!(line.hex_body.len(), 2);
assert_eq!(line.hex_body[0], 0x42);
assert_eq!(line.hex_body[1], 0x43);
assert_eq!(line.ascii.len(), 2);
assert_eq!(line.ascii[0], b'B');
assert_eq!(line.ascii[1], b'C');
assert_eq!(line.bytes, 2);
assert_eq!(line.offset, 0x100);
}
#[test]
fn test_page_default() {
let page = Page::new();
assert_eq!(page.offset, 0x0);
assert_eq!(page.body.len(), 0);
assert_eq!(page.bytes, 0x0);
}
#[test]
fn test_page_with_lines() {
let mut page = Page::new();
let mut line1 = Line::new();
line1.hex_body.push(0x01);
line1.bytes = 1;
let mut line2 = Line::new();
line2.hex_body.push(0x02);
line2.bytes = 1;
page.body.push(line1);
page.body.push(line2);
page.bytes = 2;
page.offset = 0x100;
assert_eq!(page.body.len(), 2);
assert_eq!(page.bytes, 2);
assert_eq!(page.offset, 0x100);
}
}