diff options
| author | Valentin Popov <valentin@popov.link> | 2026-06-30 01:47:24 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-06-30 01:47:24 +0300 |
| commit | c7a9c43b5bfdda7c3869ac461f03d043e5b1e3b7 (patch) | |
| tree | eec654882f50491a3b7d15672dd6f47e0a3fa33c /crates/fparkan-inspection | |
| parent | c0116d32bea18859f1310ed01d8ac074ac676dda (diff) | |
| download | fparkan-c7a9c43b5bfdda7c3869ac461f03d043e5b1e3b7.tar.xz fparkan-c7a9c43b5bfdda7c3869ac461f03d043e5b1e3b7.zip | |
test(inspection): cover archive diagnostic span context
Diffstat (limited to 'crates/fparkan-inspection')
| -rw-r--r-- | crates/fparkan-inspection/src/lib.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/fparkan-inspection/src/lib.rs b/crates/fparkan-inspection/src/lib.rs index 7fce95e..519490c 100644 --- a/crates/fparkan-inspection/src/lib.rs +++ b/crates/fparkan-inspection/src/lib.rs @@ -21,7 +21,7 @@ //! Shared inspection helpers for format-backed tooling. use fparkan_diagnostics::{ - diagnostic, render_human, Diagnostic, DiagnosticCode, DiagnosticContext, Phase, + diagnostic, render_human, Diagnostic, DiagnosticCode, DiagnosticContext, Phase, SourceSpan, }; use fparkan_msh::{decode_msh, validate_msh, ModelAsset}; use fparkan_nres::{decode as decode_nres, NresDocument, ReadProfile}; @@ -215,7 +215,7 @@ fn inspect_archive_bytes( Arc::from(bytes.to_vec().into_boxed_slice()), ReadProfile::Compatible, ) - .map_err(|err| archive_parse_diagnostic("S1.NRES.DECODE", source, err.to_string()))?; + .map_err(|err| archive_parse_diagnostic("S1.NRES.DECODE", source, bytes, err.to_string()))?; let mut sample = Vec::new(); for entry in document.entries().iter().take(sample_limit) { sample.push(NresEntrySummary { @@ -234,7 +234,7 @@ fn inspect_archive_bytes( Arc::from(bytes.to_vec().into_boxed_slice()), fparkan_rsli::ReadProfile::Compatible, ) - .map_err(|err| archive_parse_diagnostic("S1.RSLI.DECODE", source, err.to_string()))?; + .map_err(|err| archive_parse_diagnostic("S1.RSLI.DECODE", source, bytes, err.to_string()))?; Ok(ArchiveInspection::Rsli { entries: document.entries().len(), }) @@ -242,6 +242,7 @@ fn inspect_archive_bytes( Err(archive_parse_diagnostic( "S1.RESOURCE.UNSUPPORTED_ARCHIVE", source, + bytes, "unsupported archive magic".to_string(), )) } @@ -386,11 +387,16 @@ fn load_model_document_from_root( fn archive_parse_diagnostic( code: &'static str, source: Option<&Path>, + bytes: &[u8], message: String, ) -> Diagnostic { diagnostic(DiagnosticCode(code), message).with_context(DiagnosticContext { phase: Some(Phase::Parse), path: source.map(|path| path.display().to_string()), + span: Some(SourceSpan { + offset: 0, + length: u64::try_from(bytes.len().min(4)).unwrap_or(4), + }), ..DiagnosticContext::default() }) } @@ -414,7 +420,7 @@ mod tests { } #[test] - fn archive_diagnostic_preserves_source_path() { + fn archive_diagnostic_preserves_source_path_phase_and_span() { let dir = temp_dir("inspect-diagnostic"); let path = dir.join("broken.nres"); fs::write(&path, b"NRes").expect("broken nres"); @@ -428,6 +434,14 @@ mod tests { diagnostic.context.path.as_deref(), Some(expected_path.as_str()) ); + assert_eq!(diagnostic.context.phase, Some(Phase::Parse)); + assert_eq!( + diagnostic.context.span, + Some(SourceSpan { + offset: 0, + length: 4 + }) + ); } #[test] |
