use super::*;
#[test]
fn header_size() {
assert_eq!(std::mem::size_of::<Header>(), 64);
}
#[test]
fn header_default() {
let h = Header::default();
assert!(h.validate_magic());
assert!(h.validate_version());
assert_eq!(h.total_size, 0);
}
#[test]
fn header_roundtrip() {
let h = Header {
magic: MAGIC,
version: VERSION,
checksum: 0x12345678,
total_size: 1024,
str_blob_size: 100,
regex_blob_size: 256,
str_table_count: 10,
regex_table_count: 3,
node_types_count: 20,
node_fields_count: 5,
trivia_count: 2,
type_defs_count: 8,
type_members_count: 12,
type_names_count: 4,
entrypoints_count: 1,
transitions_count: 15,
_reserved: [0; 20],
};
let bytes = h.to_bytes();
assert_eq!(bytes.len(), 64);
let decoded = Header::from_bytes(&bytes);
assert_eq!(decoded, h);
}
#[test]
fn compute_offsets_empty() {
let h = Header::default();
let offsets = h.compute_offsets();
assert_eq!(offsets.str_blob, 64); assert_eq!(offsets.regex_blob, 64); assert_eq!(offsets.str_table, 64); assert_eq!(offsets.regex_table, 128); assert_eq!(offsets.node_types, 192); assert_eq!(offsets.node_fields, 192); assert_eq!(offsets.trivia, 192);
assert_eq!(offsets.type_defs, 192);
assert_eq!(offsets.type_members, 192);
assert_eq!(offsets.type_names, 192);
assert_eq!(offsets.entrypoints, 192);
assert_eq!(offsets.transitions, 192);
}
#[test]
fn compute_offsets_with_data() {
let h = Header {
str_table_count: 5, regex_table_count: 2, node_types_count: 10, node_fields_count: 5, trivia_count: 3, type_defs_count: 8, type_members_count: 12, type_names_count: 4, entrypoints_count: 2, transitions_count: 20, str_blob_size: 100,
regex_blob_size: 128,
..Default::default()
};
let offsets = h.compute_offsets();
assert_eq!(offsets.str_blob, 64); assert_eq!(offsets.regex_blob, 192); assert_eq!(offsets.str_table, 320); assert_eq!(offsets.regex_table, 384); assert_eq!(offsets.node_types, 448); assert_eq!(offsets.node_fields, 512); assert_eq!(offsets.trivia, 576); assert_eq!(offsets.type_defs, 640); assert_eq!(offsets.type_members, 704); assert_eq!(offsets.type_names, 768); assert_eq!(offsets.entrypoints, 832); assert_eq!(offsets.transitions, 896); }