Add tests for coverage gaps S1, S2, S3, S5, S6, S7 (285→346 tests, 88.9%→91.9% lines)
- S1 (error.rs): 5 tests for Display impl on all 4 AlkTypeError variants + Error::source(). error.rs 0%→100%. - S2 (validation.rs, macros.rs): 28 tests for validate() (Result-returning) method on every validator + factory rejection arms for all 12 keywords. validation.rs 85%→97.5% lines / 100% fns; macros.rs 75.7%→93.1% / 100% fns. - S3 (engine.rs): 3 tests for read_field on nested struct leaf fields, Bytes, and Timestamp. engine.rs fns 95%→95.3%. - S5 (layout_builder.rs): 2 tests for union 'variant must be Struct' error (byte + field discriminator). - S6 (schema.rs): 6 tests for as_str() round-trip (all 19 kinds), Display, needs_endian(), is_composite(), get_alktype_kind_enum(). schema.rs 91.2%→97.5% lines / 94.3% fns. - S7 (offset_map.rs): 1 test for nested-struct-without-properties schema error. Updated docs/reviews/001-coverage-analysis.md with resolution section and partial-resolved status. Remaining: S4 (sequential_reader error paths, medium effort) and S8 (overflow guards, recommended to skip for v1).
This commit is contained in:
1 parent
9fb85417b5
commit
57d8ed25ba
7 files changed
+672
-2
No files matched your search
@@ -751,4 +751,79 @@ mod tests {
|
||||
Some(AlkTypeKind::String)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_field_aligned_reads_nested_struct_leaf_fields() {
|
||||
let mut schema = json!({
|
||||
"AlkType:Struct": true,
|
||||
"endian": "little",
|
||||
"properties": {
|
||||
"header": {
|
||||
"AlkType:Struct": true,
|
||||
"properties": {
|
||||
"magic": { "AlkType:Uint32": true },
|
||||
"version": { "AlkType:Uint8": true }
|
||||
}
|
||||
},
|
||||
"body": { "AlkType:Uint32": true }
|
||||
}
|
||||
});
|
||||
let engine = AlkTypeEngine::compile(&mut schema, LayoutMode::Aligned).expect("compile");
|
||||
let mut buf = vec![0u8; 12];
|
||||
buf[0..4].copy_from_slice(&0xDEADBEEFu32.to_le_bytes());
|
||||
buf[4] = 0x01;
|
||||
buf[8..12].copy_from_slice(&0xCAFEBABEu32.to_le_bytes());
|
||||
assert_eq!(
|
||||
engine.read_field(&buf, "header.magic").unwrap(),
|
||||
FieldValue::U32(0xDEADBEEF)
|
||||
);
|
||||
assert_eq!(
|
||||
engine.read_field(&buf, "header.version").unwrap(),
|
||||
FieldValue::U8(0x01)
|
||||
);
|
||||
assert_eq!(
|
||||
engine.read_field(&buf, "body").unwrap(),
|
||||
FieldValue::U32(0xCAFEBABE)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_field_aligned_reads_bytes_field() {
|
||||
let mut schema = json!({
|
||||
"AlkType:Struct": true,
|
||||
"properties": {
|
||||
"blob": { "AlkType:Bytes": true }
|
||||
}
|
||||
});
|
||||
let engine = AlkTypeEngine::compile(&mut schema, LayoutMode::Aligned).expect("compile");
|
||||
let mut buf = vec![0u8; 16];
|
||||
let payload = [0xAA, 0xBB, 0xCC];
|
||||
let len_bytes = 3u32.to_le_bytes();
|
||||
buf[0..4].copy_from_slice(&len_bytes);
|
||||
buf[4..7].copy_from_slice(&payload);
|
||||
match engine.read_field(&buf, "blob").unwrap() {
|
||||
FieldValue::Bytes(b) => assert_eq!(b, &payload[..]),
|
||||
other => panic!("expected Bytes, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_field_aligned_reads_timestamp_as_string() {
|
||||
let mut schema = json!({
|
||||
"AlkType:Struct": true,
|
||||
"properties": {
|
||||
"ts": { "AlkType:Timestamp": true }
|
||||
}
|
||||
});
|
||||
let engine = AlkTypeEngine::compile(&mut schema, LayoutMode::Aligned).expect("compile");
|
||||
let mut buf = vec![0u8; 32];
|
||||
let stamp = "2026-07-20T15:30:00Z";
|
||||
let len_bytes = (stamp.len() as u32).to_le_bytes();
|
||||
buf[0..4].copy_from_slice(&len_bytes);
|
||||
buf[4..4 + stamp.len()].copy_from_slice(stamp.as_bytes());
|
||||
match engine.read_field(&buf, "ts").unwrap() {
|
||||
FieldValue::String(s) => assert_eq!(s, stamp),
|
||||
other => panic!("expected String, got {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user