Skip to content

Commit 4f39db3

Browse files
tausbnCopilot
andcommitted
Unified: Update import location test JSON
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5f97662 commit 4f39db3

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

unified/extractor/tests/swift_syntax_pipeline.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,46 @@ mod languages;
1616
/// A real `swift-syntax-rs` JSON dump of the Swift source `let x = 1`.
1717
const LET_X_JSON: &str = include_str!("fixtures/let_x.swiftsyntax.json");
1818

19+
const IMPORT_FOUNDATION_JSON: &str = r#"{
20+
"$lineStarts": [0],
21+
"$pos": 0,
22+
"$end": 17,
23+
"kind": "sourceFile",
24+
"statements": [
25+
{
26+
"$pos": 0,
27+
"$end": 17,
28+
"kind": "codeBlockItem",
29+
"item": {
30+
"$pos": 0,
31+
"$end": 17,
32+
"kind": "importDecl",
33+
"importKeyword": {
34+
"$pos": 0,
35+
"$end": 6,
36+
"kind": "token",
37+
"tokenKind": "keyword(SwiftSyntax.Keyword.import)",
38+
"text": "import"
39+
},
40+
"path": [
41+
{
42+
"$pos": 7,
43+
"$end": 17,
44+
"kind": "importPathComponent",
45+
"name": {
46+
"$pos": 7,
47+
"$end": 17,
48+
"kind": "token",
49+
"tokenKind": "identifier(\"Foundation\")",
50+
"text": "Foundation"
51+
}
52+
}
53+
]
54+
}
55+
}
56+
]
57+
}"#;
58+
1959
#[test]
2060
fn swift_syntax_json_runs_through_the_desugarer() {
2161
let lang = languages::all_language_specs()
@@ -47,3 +87,37 @@ fn swift_syntax_json_runs_through_the_desugarer() {
4787
assert!(dump.contains("top_level"), "unexpected dump: {dump}");
4888
assert!(dump.contains("block"), "unexpected dump: {dump}");
4989
}
90+
91+
#[test]
92+
fn import_name_expr_location_excludes_import_keyword() {
93+
let lang = languages::all_language_specs()
94+
.into_iter()
95+
.find(|l| l.file_globs.iter().any(|g| g.contains("swift")))
96+
.expect("swift language spec");
97+
let desugarer = lang.desugarer.as_ref();
98+
let adapted = languages::swift_adapter::json_to_ast(IMPORT_FOUNDATION_JSON)
99+
.expect("adapter should succeed");
100+
101+
let desugared = desugarer
102+
.run_from_ast(adapted.ast)
103+
.expect("desugaring an import should not error");
104+
105+
let name_expr_ids: Vec<yeast::Id> = desugared
106+
.reachable_node_ids()
107+
.into_iter()
108+
.filter(|&id| {
109+
desugared
110+
.get_node(id)
111+
.is_some_and(|node| node.kind_name() == "name_expr")
112+
})
113+
.collect();
114+
assert_eq!(
115+
name_expr_ids.len(),
116+
1,
117+
"expected exactly one reachable name_expr"
118+
);
119+
120+
let name_expr = desugared.get_node(name_expr_ids[0]).unwrap();
121+
assert_eq!(name_expr.start_byte(), 7);
122+
assert_eq!(name_expr.end_byte(), 17);
123+
}

0 commit comments

Comments
 (0)