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:
glm-5.2 committed 2026-08-02 08:04:44 +00:00
1 parent 9fb85417b5
commit 57d8ed25ba
7 files changed
+672 -2

No files matched your search

+108
View File
@@ -809,4 +809,112 @@ mod tests {
})
);
}
#[test]
fn as_str_round_trips_for_all_kinds() {
for kind in [
AlkTypeKind::Int8,
AlkTypeKind::Int16,
AlkTypeKind::Int32,
AlkTypeKind::Int64,
AlkTypeKind::Uint8,
AlkTypeKind::Uint16,
AlkTypeKind::Uint32,
AlkTypeKind::Uint64,
AlkTypeKind::Float32,
AlkTypeKind::Float64,
AlkTypeKind::Boolean,
AlkTypeKind::Enum,
AlkTypeKind::String,
AlkTypeKind::Bytes,
AlkTypeKind::Struct,
AlkTypeKind::Union,
AlkTypeKind::Array,
AlkTypeKind::Record,
AlkTypeKind::Timestamp,
] {
let s = kind.as_str();
assert_eq!(s.parse::<AlkTypeKind>().unwrap(), kind, "{kind}");
}
}
#[test]
fn display_uses_as_str() {
assert_eq!(format!("{}", AlkTypeKind::Uint32), "AlkType:Uint32");
assert_eq!(format!("{}", AlkTypeKind::String), "AlkType:String");
}
#[test]
fn needs_endian_classifies_correctly() {
for kind in [
AlkTypeKind::Int16,
AlkTypeKind::Int32,
AlkTypeKind::Int64,
AlkTypeKind::Uint16,
AlkTypeKind::Uint32,
AlkTypeKind::Uint64,
AlkTypeKind::Float32,
AlkTypeKind::Float64,
AlkTypeKind::Enum,
AlkTypeKind::String,
AlkTypeKind::Bytes,
AlkTypeKind::Timestamp,
] {
assert!(kind.needs_endian(), "expected needs_endian: {kind}");
}
for kind in [
AlkTypeKind::Int8,
AlkTypeKind::Uint8,
AlkTypeKind::Boolean,
AlkTypeKind::Struct,
AlkTypeKind::Union,
AlkTypeKind::Array,
AlkTypeKind::Record,
] {
assert!(!kind.needs_endian(), "expected not needs_endian: {kind}");
}
}
#[test]
fn is_composite_classifies_correctly() {
for kind in [
AlkTypeKind::Struct,
AlkTypeKind::Union,
AlkTypeKind::Array,
AlkTypeKind::Record,
] {
assert!(kind.is_composite(), "expected composite: {kind}");
}
for kind in [
AlkTypeKind::Int8,
AlkTypeKind::Int16,
AlkTypeKind::Int32,
AlkTypeKind::Int64,
AlkTypeKind::Uint8,
AlkTypeKind::Uint16,
AlkTypeKind::Uint32,
AlkTypeKind::Uint64,
AlkTypeKind::Float32,
AlkTypeKind::Float64,
AlkTypeKind::Boolean,
AlkTypeKind::Enum,
AlkTypeKind::String,
AlkTypeKind::Bytes,
AlkTypeKind::Timestamp,
] {
assert!(!kind.is_composite(), "expected not composite: {kind}");
}
}
#[test]
fn get_alktype_kind_enum_returns_none_for_object_form() {
let schema = json!({"AlkType:String": {"encoding": "length-prefixed"}});
assert_eq!(get_alktype_kind_enum(&schema), None);
}
#[test]
fn get_alktype_kind_enum_returns_kind_for_bool_form() {
let schema = json!({"AlkType:Uint32": true});
assert_eq!(get_alktype_kind_enum(&schema), Some(AlkTypeKind::Uint32));
}
}