use crate::spec::{expect_failure, expect_parse_success, expect_success};
mod final_modifier {
use super::*;
#[test]
#[ignore = "Final modifier enforcement not yet implemented"]
fn mls_7_2_6_final_cannot_be_modified() {
expect_failure(
r#"
model Base
final parameter Real k = 1;
equation
end Base;
model Derived
extends Base(k = 2);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
#[ignore = "Final modifier enforcement not yet implemented"]
fn mls_7_2_6_final_nested_modification() {
expect_failure(
r#"
model Inner
parameter Real x = 1;
equation
end Inner;
model Base
final Inner i(x = 2);
equation
end Base;
model Derived
extends Base(i(x = 3));
equation
end Derived;
"#,
"Derived",
);
}
#[test]
#[ignore = "Final redeclare restriction not yet implemented"]
fn mls_7_2_6_final_cannot_redeclare() {
expect_failure(
r#"
model Base
final replaceable model M = Integer;
equation
end Base;
model Derived
extends Base(redeclare model M = Real);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
fn mls_7_2_6_non_final_modification() {
expect_success(
r#"
model Base
parameter Real k = 1;
equation
end Base;
model Derived
extends Base(k = 2);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
fn mls_7_2_6_final_declaration() {
expect_success(
r#"
model Base
final parameter Real k = 1;
equation
end Base;
model Derived
extends Base;
equation
end Derived;
"#,
"Derived",
);
}
}
mod constrainedby_checking {
use super::*;
#[test]
#[ignore = "constrainedby type checking not yet implemented"]
fn mls_7_3_2_constrainedby_violation() {
expect_failure(
r#"
model Base
Real x = 1;
equation
end Base;
model Extended
extends Base;
Real y = 2;
equation
end Extended;
model Container
replaceable Base b constrainedby Base;
equation
end Container;
connector C
Real v;
end C;
model Test
extends Container(redeclare C b);
equation
end Test;
"#,
"Test",
);
}
#[test]
fn mls_7_3_2_constrainedby_satisfied() {
expect_success(
r#"
model Base
Real x = 1;
equation
end Base;
model Extended
extends Base;
Real y = 2;
equation
end Extended;
model Container
replaceable Base b constrainedby Base;
equation
end Container;
model Test
extends Container(redeclare Extended b);
equation
end Test;
"#,
"Test",
);
}
#[test]
fn mls_7_3_2_default_constraining_type() {
expect_success(
r#"
model Base
Real x = 1;
equation
end Base;
model Extended
extends Base;
Real y = 2;
equation
end Extended;
model Container
replaceable Base b;
equation
end Container;
model Test
extends Container(redeclare Extended b);
equation
end Test;
"#,
"Test",
);
}
}
mod break_modifier {
use super::*;
#[test]
fn mls_7_4_break_removes_element() {
expect_success(
r#"
model Base
Real x = 1;
Real y = 2;
equation
end Base;
model Derived
extends Base(break x);
Real x = 10;
equation
end Derived;
"#,
"Derived",
);
}
#[test]
#[ignore = "break equation syntax not yet supported"]
fn mls_7_4_break_equation() {
expect_parse_success(
r#"
model Base
Real x;
equation
x = 1;
end Base;
model Derived
extends Base(break x = 1);
equation
x = 2;
end Derived;
"#,
);
}
#[test]
#[ignore = "break on non-inherited element not yet checked"]
fn mls_7_4_break_non_inherited() {
expect_failure(
r#"
model Base
Real x = 1;
equation
end Base;
model Derived
extends Base(break nonexistent);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
fn mls_7_4_multiple_breaks() {
expect_success(
r#"
model Base
Real x = 1;
Real y = 2;
Real z = 3;
equation
end Base;
model Derived
extends Base(break x, break y);
Real x = 10;
Real y = 20;
equation
end Derived;
"#,
"Derived",
);
}
}
mod extends_restrictions {
use super::*;
#[test]
#[ignore = "Extends class category check not yet implemented"]
fn mls_7_1_model_extends_connector() {
expect_failure(
r#"
connector C
Real v;
flow Real i;
end C;
model Test
extends C;
equation
end Test;
"#,
"Test",
);
}
#[test]
#[ignore = "Extends class category check not yet implemented"]
fn mls_7_1_model_extends_function() {
expect_failure(
r#"
function F
input Real x;
output Real y;
algorithm
y := x;
end F;
model Test
extends F;
equation
end Test;
"#,
"Test",
);
}
#[test]
fn mls_7_1_model_extends_model() {
expect_success(
r#"
model Base
Real x = 1;
equation
end Base;
model Derived
extends Base;
Real y = 2;
equation
end Derived;
"#,
"Derived",
);
}
#[test]
fn mls_7_1_block_extends_block() {
expect_parse_success(
r#"
block Base
input Real u;
output Real y;
equation
y = u;
end Base;
block Derived
extends Base;
end Derived;
"#,
);
}
#[test]
fn mls_7_1_connector_extends_connector() {
expect_parse_success(
r#"
connector Base
Real v;
end Base;
connector Extended
extends Base;
flow Real i;
end Extended;
"#,
);
}
#[test]
fn mls_7_1_record_extends_record() {
expect_parse_success(
r#"
record Base
Real x;
end Base;
record Extended
extends Base;
Real y;
end Extended;
"#,
);
}
}
mod modification_restrictions {
use super::*;
#[test]
#[ignore = "Modification target validation not yet implemented"]
fn mls_7_2_modify_nonexistent() {
expect_failure(
r#"
model Base
Real x = 1;
equation
end Base;
model Derived
extends Base(nonexistent = 2);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
#[ignore = "each modifier validation not yet implemented"]
fn mls_7_2_each_on_scalar() {
expect_failure(
r#"
model Inner
Real x = 1;
equation
end Inner;
model Container
Inner i;
equation
end Container;
model Test
extends Container(each i(x = 2));
equation
end Test;
"#,
"Test",
);
}
#[test]
fn mls_7_2_each_on_array() {
expect_success(
r#"
model Container
Real x[3](each start = 0);
equation
for i in 1:3 loop
x[i] = i;
end for;
end Container;
"#,
"Container",
);
}
#[test]
fn mls_7_2_nested_modification() {
expect_success(
r#"
model Inner
parameter Real k = 1;
equation
end Inner;
model Outer
Inner i;
equation
end Outer;
model Test
extends Outer(i(k = 2));
equation
end Test;
"#,
"Test",
);
}
}
mod replaceable_redeclare {
use super::*;
#[test]
#[ignore = "Non-replaceable redeclare check not yet implemented"]
fn mls_7_3_redeclare_non_replaceable() {
expect_failure(
r#"
model Base
parameter Real k = 1;
equation
end Base;
model Derived
extends Base(redeclare parameter Integer k = 2);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
fn mls_7_3_redeclare_replaceable() {
expect_success(
r#"
model Base
replaceable parameter Real k = 1;
equation
end Base;
model Derived
extends Base(redeclare parameter Real k = 2);
equation
end Derived;
"#,
"Derived",
);
}
#[test]
fn mls_7_3_replaceable_model() {
expect_success(
r#"
model DefaultModel
Real x = 1;
equation
end DefaultModel;
model AltModel
Real x = 2;
equation
end AltModel;
model Container
replaceable DefaultModel m;
equation
end Container;
model Test
extends Container(redeclare AltModel m);
equation
end Test;
"#,
"Test",
);
}
}