feat: add managed types, source classes and scoped native calls

This commit is contained in:
2026-10-21 01:47:08 +08:00
parent 7c842789c0
commit a970fd7707
48 changed files with 2069 additions and 134 deletions
+38 -1
View File
@@ -4,6 +4,35 @@ use frontend::ast::{
};
use frontend::{EndorReader, ParseMode, Span, parse_ast, parse_source_ast};
#[test]
fn function_bodies_accept_method_statements_and_optional_trailing_return() {
let root = parse_ast(
"function click(): Unit { title.setText(\"changed\") card.setColor(\"#FFEEDD\") }",
ParseMode::Module,
)
.unwrap();
let AstRoot::Module(program) = root else {
panic!("expected module")
};
let function = program.functions().next().unwrap();
assert_eq!(function.body.statements.len(), 2);
assert!(
function
.body
.statements
.iter()
.all(|s| matches!(s.kind, StmtKind::Expression(_)))
);
assert!(parse_ast("function empty(): Unit {}", ParseMode::Module).is_ok());
assert!(
parse_ast(
"function invalid(): Unit { return value other() }",
ParseMode::Module
)
.is_err()
);
}
#[test]
fn parse_modes_produce_distinct_roots_and_preserve_source_diagnostics() {
let source = "function echo(value: String): String { let copy = value return copy }";
@@ -198,5 +227,13 @@ fn bare_assignment_has_its_own_ast_and_unicode_source_ranges() {
let json = document.to_json().unwrap();
assert_eq!(AstDocument::from_json(&json).unwrap(), document);
assert!(parse_ast("value = 1 = 2", ParseMode::Interactive).is_err());
assert!(parse_ast("object.field = 1", ParseMode::Interactive).is_err());
let member = parse_ast("object.field = 1", ParseMode::Interactive).unwrap();
let AstRoot::Interactive(member) = member else {
panic!("interactive")
};
assert!(matches!(
&member.statements[0].kind,
StmtKind::MemberAssignment(_)
));
assert!(parse_ast("object() = 1", ParseMode::Interactive).is_err());
}