Skip to main content

sim_lib_lang_ruby/
matrix_row.rs

1//! Ruby conformance matrix row.
2
3use sim_kernel::Symbol;
4use sim_lib_standard_core::{
5    LanguageRow, LanguageRowBuilder, SourceConformanceCase, SourceConformanceCaseKind,
6    SourceExpectation,
7};
8
9use crate::{ruby_dsl_profile, ruby_lowering_symbol, ruby_reader_symbol};
10
11/// Builds the Ruby DSL matrix row.
12pub fn ruby_dsl_matrix_row() -> LanguageRow {
13    LanguageRowBuilder::new(Symbol::new("ruby"), ruby_dsl_profile())
14        .with_cases(ruby_dsl_source_cases())
15        .build()
16}
17
18/// Minimal source cases for the Ruby DSL matrix row.
19pub fn ruby_dsl_source_cases() -> Vec<SourceConformanceCase> {
20    vec![
21        SourceConformanceCase {
22            symbol: Symbol::qualified("test/ruby-dsl", "profile-declared"),
23            organ: ruby_reader_symbol(),
24            source_name: "profile.sim".to_owned(),
25            source: "profile".to_owned(),
26            kind: SourceConformanceCaseKind::DescriptorOnly,
27            expectation: SourceExpectation::LowersTo(ruby_dsl_profile_display()),
28            affects_badge: Some(Symbol::qualified("standard", "partial")),
29        },
30        SourceConformanceCase {
31            symbol: Symbol::qualified("test/ruby-dsl", "runtime-gap"),
32            organ: ruby_lowering_symbol(),
33            source_name: "runtime-gap.rb".to_owned(),
34            source: "eval('1 + 2')".to_owned(),
35            kind: SourceConformanceCaseKind::DescriptorOnly,
36            expectation: SourceExpectation::ExpectedGap {
37                code: Symbol::qualified("ruby", "runtime-gap"),
38                reason: "Ruby full object-model execution is outside this row".to_owned(),
39            },
40            affects_badge: None,
41        },
42    ]
43}
44
45fn ruby_dsl_profile_display() -> String {
46    let profile = ruby_dsl_profile();
47    format!(
48        "profile:{} reader:{} lowering:{}",
49        profile.symbol, profile.reader, profile.lowering
50    )
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn ruby_dsl_matrix_row_language_symbol_is_ruby() {
59        let row = ruby_dsl_matrix_row();
60
61        assert_eq!(row.language, Symbol::new("ruby"));
62        assert!(!row.is_empty());
63        assert_eq!(row.cases.len(), 2);
64        assert!(matches!(
65            row.cases[0].expectation,
66            SourceExpectation::LowersTo(_)
67        ));
68        assert!(matches!(
69            row.cases[1].expectation,
70            SourceExpectation::ExpectedGap { .. }
71        ));
72    }
73}