Enforce declared visual subclass field contracts before native effects
Verify Tessera GUI / verify (push) Failing after 7m46s
Verify Tessera GUI / verify (push) Failing after 7m46s
This commit is contained in:
@@ -993,6 +993,106 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn checked_fields_reject_native_constructor_side_effects_and_preserve_live_values() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../examples/field-contracts.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
210,
|
||||
)
|
||||
.unwrap();
|
||||
for invalid in [
|
||||
r#"counter.value = "wrong""#,
|
||||
r#"CounterText("bad", "wrong")"#,
|
||||
"Model(42)",
|
||||
] {
|
||||
let error = session.execute(invalid, "app.main").err().unwrap();
|
||||
assert!(error.to_string().contains("field"), "{error:#}");
|
||||
assert!(
|
||||
session.documents[&crate::window::MAIN_WINDOW]
|
||||
.frame
|
||||
.fault
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
session.execute("counter.value", "app.main").unwrap().value,
|
||||
"9"
|
||||
);
|
||||
session
|
||||
.execute("class CheckedPage: Page { count: Number }", "app.main")
|
||||
.unwrap();
|
||||
let pages = session
|
||||
.execute("ui.window().pages().count", "app.main")
|
||||
.unwrap()
|
||||
.value;
|
||||
assert!(
|
||||
session
|
||||
.execute(r#"CheckedPage("wrong")"#, "app.main")
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("ui.window().pages().count", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
pages
|
||||
);
|
||||
let updated = session
|
||||
.execute("button.click()", "app.main")
|
||||
.unwrap()
|
||||
.document
|
||||
.unwrap();
|
||||
assert!(
|
||||
updated.frame.commands.iter().any(
|
||||
|command| matches!(command, RenderCommand::Text { value, .. } if value == "10")
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
session.execute("counter.value", "app.main").unwrap().value,
|
||||
"10"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checked_fields_follow_shared_block_forwarding_and_binding_writes() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
r#"
|
||||
class Numeric: TextBlock { value: Number }
|
||||
class Textual: TextBlock { value: String }
|
||||
block = Numeric("old", 9)
|
||||
alias = block
|
||||
page = Page()
|
||||
page.render(block)
|
||||
"#,
|
||||
"app.main",
|
||||
1,
|
||||
211,
|
||||
)
|
||||
.unwrap();
|
||||
session
|
||||
.execute(r#"block = Textual("new", "kept")"#, "app.main")
|
||||
.unwrap();
|
||||
assert!(session.execute("alias.value = 42", "app.main").is_err());
|
||||
assert_eq!(
|
||||
session.execute("alias.value", "app.main").unwrap().value,
|
||||
r#""kept""#
|
||||
);
|
||||
session
|
||||
.execute(r#"alias.value = "updated""#, "app.main")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session.execute("block.value", "app.main").unwrap().value,
|
||||
r#""updated""#
|
||||
);
|
||||
assert!(
|
||||
session
|
||||
.execute("alias.bind(\"value\", ui.viewport)", "app.main")
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positional_insert_preserves_existing_slots_and_mounts_and_rejects_invalid_graphs() {
|
||||
let source = r#"head=TextBlock("head")
|
||||
|
||||
Reference in New Issue
Block a user