Skip to main content

mig_assembly/
test_support.rs

1//! Shared test helpers for constructing MIG schema test fixtures.
2//!
3//! Available to both unit tests (`#[cfg(test)]` modules) and integration tests.
4
5use mig_types::schema::mig::{MigSegment, MigSegmentGroup};
6
7/// Create a minimal `MigSegment` for testing, with only the `id` set meaningfully.
8pub fn make_mig_segment(id: &str) -> MigSegment {
9    MigSegment {
10        id: id.to_string(),
11        name: id.to_string(),
12        description: None,
13        counter: None,
14        level: 0,
15        number: None,
16        max_rep_std: 1,
17        max_rep_spec: 1,
18        status_std: Some("M".to_string()),
19        status_spec: Some("M".to_string()),
20        example: None,
21        data_elements: vec![],
22        composites: vec![],
23    }
24}
25
26/// Create a `MigSegment` with a MIG `Number` attribute for testing mig_number assignment.
27pub fn make_mig_segment_numbered(id: &str, number: &str) -> MigSegment {
28    let mut seg = make_mig_segment(id);
29    seg.number = Some(number.to_string());
30    seg
31}
32
33/// Create a minimal `MigSegmentGroup` for testing.
34pub fn make_mig_group(
35    id: &str,
36    segments: Vec<&str>,
37    nested: Vec<MigSegmentGroup>,
38) -> MigSegmentGroup {
39    MigSegmentGroup {
40        id: id.to_string(),
41        name: id.to_string(),
42        description: None,
43        counter: None,
44        level: 1,
45        max_rep_std: 99,
46        max_rep_spec: 99,
47        status_std: Some("M".to_string()),
48        status_spec: Some("M".to_string()),
49        segments: segments.into_iter().map(make_mig_segment).collect(),
50        nested_groups: nested,
51        variant_code: None,
52        variant_qualifier_position: None,
53        variant_codes: vec![],
54        merged_variant_count: None,
55        variant_entry_qualifiers: Vec::new(),
56    }
57}
58
59/// Create a `MigSegmentGroup` with a variant code for testing variant-aware assembly.
60pub fn make_mig_group_with_variant(
61    id: &str,
62    segments: Vec<&str>,
63    nested: Vec<MigSegmentGroup>,
64    variant_code: &str,
65) -> MigSegmentGroup {
66    let mut group = make_mig_group(id, segments, nested);
67    group.variant_code = Some(variant_code.to_string());
68    group.variant_codes = vec![variant_code.to_string()];
69    group
70}