Register typed GUI capabilities and reject incompatible presenters early
This commit is contained in:
@@ -3837,6 +3837,60 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presentable_type_contracts_reject_before_registration_or_body_effects() {
|
||||
let mut session = ReplSession::new(232).unwrap();
|
||||
session.execute("marker = ui.state(0)", "app.main").unwrap();
|
||||
for (name, method) in [
|
||||
(
|
||||
"WrongParameter",
|
||||
"function present(self: WrongParameter, window: Point): Block { marker.increment() return TextBlock(\"bad\") }",
|
||||
),
|
||||
(
|
||||
"WrongResult",
|
||||
"function present(self: WrongResult, window: Window): Number { marker.increment() return 7 }",
|
||||
),
|
||||
] {
|
||||
let input = format!("class {name} {{ {method} }} ui.implement({name}, Presentable)");
|
||||
let error = session
|
||||
.execute(&input, "app.main")
|
||||
.err()
|
||||
.expect("incompatible typed capability");
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("trait Presentable method present"),
|
||||
"{error:#}"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute(&format!("ui.implements({name}, Presentable)"), "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"false"
|
||||
);
|
||||
assert_eq!(
|
||||
session.execute("marker.value", "app.main").unwrap().value,
|
||||
"0"
|
||||
);
|
||||
}
|
||||
session.execute(r#"
|
||||
class Good {
|
||||
function present(self: Good, window: Object): TextBlock { return TextBlock("typed") }
|
||||
}
|
||||
ui.implement(Good, Presentable)
|
||||
view = ui.present(Good())
|
||||
"#, "app.main").unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("ui.isInstance(view, TextBlock)", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"true"
|
||||
);
|
||||
assert!(!session.is_faulted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presentable_dispatch_preserves_source_identity_and_reactive_display() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
|
||||
Reference in New Issue
Block a user