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