Skip to main content

sim_lib_lang_islisp/
conformance.rs

1//! ISLISP matrix-row conformance runner.
2
3use sim_kernel::{Cx, Result, Symbol};
4use sim_lib_standard_core::{
5    LanguageProfile, MatrixRunReport, MatrixRunner, SourceConformanceCase, SourceExpectation,
6    SourceObservation,
7};
8
9use crate::{islisp_matrix_row, islisp_profile};
10
11/// Runs one ISLISP source conformance case.
12pub fn run_islisp_conformance_case(
13    _cx: &mut Cx,
14    case: &SourceConformanceCase,
15) -> Result<SourceObservation> {
16    Ok(observe_profile_backed_case(
17        case,
18        &islisp_profile(),
19        Symbol::qualified("islisp", "unsupported-source-case"),
20        "case is outside ISLISP profile descriptor coverage",
21    ))
22}
23
24/// Runs the ISLISP matrix row and publishes claim-backed cells.
25pub fn run_islisp_matrix_row(cx: &mut Cx) -> Result<MatrixRunReport> {
26    let row = islisp_matrix_row();
27    let report = MatrixRunner::run_row(cx, &row, run_islisp_conformance_case);
28    report.publish_claims(cx)?;
29    Ok(report)
30}
31
32fn observe_profile_backed_case(
33    case: &SourceConformanceCase,
34    profile: &LanguageProfile,
35    unsupported_code: Symbol,
36    unsupported_reason: &str,
37) -> SourceObservation {
38    match &case.expectation {
39        SourceExpectation::ExpectedGap { code, reason } => SourceObservation::Gap {
40            code: code.clone(),
41            reason: reason.clone(),
42        },
43        SourceExpectation::LowersTo(_) if case.source == "profile" => {
44            SourceObservation::LowersTo(profile_display(profile))
45        }
46        SourceExpectation::LowersTo(_) => SourceObservation::Gap {
47            code: unsupported_code,
48            reason: unsupported_reason.to_owned(),
49        },
50    }
51}
52
53fn profile_display(profile: &LanguageProfile) -> String {
54    format!(
55        "profile:{} reader:{} lowering:{}",
56        profile.symbol, profile.reader, profile.lowering
57    )
58}
59
60#[cfg(test)]
61mod tests {
62    use sim_kernel::testing::bare_cx as cx;
63    use sim_lib_standard_core::standard_test_capability;
64
65    use super::*;
66
67    #[test]
68    fn islisp_matrix_row_runner_reports_profile_pass_and_runtime_gap() {
69        let mut cx = cx();
70        cx.grant(standard_test_capability());
71
72        let report = run_islisp_matrix_row(&mut cx).unwrap();
73
74        assert_eq!(report.cells.len(), 2);
75        assert_eq!(report.pass_count(), 1);
76        assert_eq!(report.gap_count(), 1);
77        assert_eq!(report.fail_count(), 0);
78    }
79}