Skip to main content

sim_lib_lang_lua/
matrix_row.rs

1//! Lua conformance matrix row.
2
3use sim_kernel::Symbol;
4use sim_lib_standard_core::{
5    LanguageRow, LanguageRowBuilder, SourceConformanceCase, SourceExpectation,
6};
7
8use crate::{lua_core_profile, lua_lowering_symbol, lua_reader_symbol};
9
10/// Builds the Lua core matrix row.
11pub fn lua_core_matrix_row() -> LanguageRow {
12    LanguageRowBuilder::new(Symbol::new("lua"), lua_core_profile())
13        .with_cases(lua_core_source_cases())
14        .build()
15}
16
17/// Minimal source cases for the Lua core matrix row.
18pub fn lua_core_source_cases() -> Vec<SourceConformanceCase> {
19    vec![
20        SourceConformanceCase {
21            symbol: Symbol::qualified("test/lua-core", "profile-declared"),
22            organ: lua_reader_symbol(),
23            source_name: "profile.sim".to_owned(),
24            source: "profile".to_owned(),
25            expectation: SourceExpectation::LowersTo(lua_core_profile_display()),
26            affects_badge: Some(Symbol::qualified("standard", "partial")),
27        },
28        SourceConformanceCase {
29            symbol: Symbol::qualified("test/lua-core", "runtime-gap"),
30            organ: lua_lowering_symbol(),
31            source_name: "runtime-gap.lua".to_owned(),
32            source: "return load('return 1 + 2')()".to_owned(),
33            expectation: SourceExpectation::ExpectedGap {
34                code: Symbol::qualified("lua", "runtime-gap"),
35                reason: "Lua full VM execution is outside this row".to_owned(),
36            },
37            affects_badge: None,
38        },
39    ]
40}
41
42fn lua_core_profile_display() -> String {
43    let profile = lua_core_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 lua_core_matrix_row_language_symbol_is_lua() {
56        let row = lua_core_matrix_row();
57
58        assert_eq!(row.language, Symbol::new("lua"));
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}