feat: support bare name assignments in interactive and function scopes
This commit is contained in:
@@ -179,3 +179,24 @@ fn json_interfaces_reject_unknown_fields_schema_changes_and_invalid_ranges() {
|
||||
Err(AstError::InvalidSpan(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bare_assignment_has_its_own_ast_and_unicode_source_ranges() {
|
||||
let source = "标题 = ui.text(\"你好\")";
|
||||
let root = parse_ast(source, ParseMode::Interactive).unwrap();
|
||||
let AstRoot::Interactive(input) = &root else {
|
||||
panic!("interactive input")
|
||||
};
|
||||
let StmtKind::Assignment(assignment) = &input.statements[0].kind else {
|
||||
panic!("assignment")
|
||||
};
|
||||
assert_eq!(assignment.name.text, "标题");
|
||||
assert_eq!(assignment.name.source_text(source), Some("标题"));
|
||||
assert_eq!(assignment.source_text(source), Some(source));
|
||||
let document = AstDocument::new(root).unwrap();
|
||||
document.validate_source(source).unwrap();
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user