From 3e1ca82cbf7ad4d5a220a1a4764cff4270ce6f43 Mon Sep 17 00:00:00 2001 From: Asger F Date: Mon, 29 Jun 2026 13:49:02 +0200 Subject: [PATCH 1/3] unified: Split corpus tests into source code and generated output The corpus tests interleaved hand-written content (test cases) with generated content (printed ASTs). This made merge conflicts hard to resolve because you can't just regnerate the printed ASTs without potentially throwing away new test cases that came from either branch (or depending on whether the merge conflict markers appeared, the corpus test could be ruined completely). The old design did have one nice advantage: Reviewers could see the printed ASTs alongside the source code from which it was generated. To preserve this feature, the source code for the test case is itself included in the generated output file. --- unified/AGENTS.md | 6 +- unified/extractor/tests/corpus_tests.rs | 293 +++++++++++------------- 2 files changed, 137 insertions(+), 162 deletions(-) diff --git a/unified/AGENTS.md b/unified/AGENTS.md index 6c7d697896f0..1a929c09a715 100644 --- a/unified/AGENTS.md +++ b/unified/AGENTS.md @@ -19,7 +19,11 @@ This is a CodeQL extractor based on tree-sitter. - To run tests for the parser and mapping, run `cargo test` in the `extractor` directory. -- Do not edit the printed ASTs in `extractor/test/corpus` directly. To regenerate the ASTs, run `scripts/update-corpus.sh`. +- Extractor test cases are located at `extractor/test/corpus/swift/*/*.swift`. + +- Each test case has a corresponding `.output` file containing its generated output along with a copy of the test case itself. + +- Check the output files for correctness but do not edit them manually. Regenerate them with `scripts/update-corpus.sh`. ## CodeQL Testing - If you changed the extractor code, always rebuild it before running CodeQL tests. diff --git a/unified/extractor/tests/corpus_tests.rs b/unified/extractor/tests/corpus_tests.rs index 6c859c2f6cf0..ac93f06622cf 100644 --- a/unified/extractor/tests/corpus_tests.rs +++ b/unified/extractor/tests/corpus_tests.rs @@ -9,7 +9,6 @@ mod languages; #[derive(Debug)] struct CorpusCase { - name: String, input: String, raw: String, expected: String, @@ -21,129 +20,43 @@ fn update_mode_enabled() -> bool { .unwrap_or(false) } -fn is_header_rule(line: &str) -> bool { - let trimmed = line.trim(); - trimmed.len() >= 3 && trimmed.chars().all(|c| c == '=') -} - -fn is_next_case_header(lines: &[&str], i: usize) -> bool { - is_header_rule(lines[i]) - && i + 2 < lines.len() - && !lines[i + 1].trim().is_empty() - && is_header_rule(lines[i + 2]) -} - -fn parse_corpus(content: &str) -> Vec { - let lines: Vec<&str> = content.lines().collect(); - let mut i = 0; - let mut cases = Vec::new(); - - while i < lines.len() { - while i < lines.len() && lines[i].trim().is_empty() { - i += 1; - } - if i >= lines.len() { - break; - } - - assert!( - is_header_rule(lines[i]), - "Expected header delimiter at line {}", - i + 1 - ); - i += 1; - - assert!(i < lines.len(), "Missing test name at line {}", i + 1); - let name = lines[i].trim().to_string(); - i += 1; - - assert!( - i < lines.len() && is_header_rule(lines[i]), - "Missing closing header delimiter for case {name}" - ); - i += 1; - - let input_start = i; - while i < lines.len() && lines[i].trim() != "---" { - if is_next_case_header(&lines, i) { - break; - } - i += 1; - } - let input = lines[input_start..i].join("\n").trim_end().to_string(); - let raw; - let expected; - if i >= lines.len() || lines[i].trim() != "---" { - // No `---` separator before next case (or EOF). Treat the - // remaining sections as empty. - raw = String::new(); - expected = String::new(); - } else { - i += 1; - - // Raw tree-sitter parse section. New-format files have a second - // `---` separator between the raw tree and the mapped AST. Legacy - // files (with only one separator) have no raw section — in that - // case `raw` stays empty and update mode will populate it. - let raw_start = i; - let mut next_sep = i; - while next_sep < lines.len() && lines[next_sep].trim() != "---" { - if is_next_case_header(&lines, next_sep) { - break; - } - next_sep += 1; - } - raw = if next_sep < lines.len() && lines[next_sep].trim() == "---" { - let raw_text = lines[raw_start..next_sep].join("\n").trim().to_string(); - i = next_sep + 1; - raw_text - } else { - String::new() - }; - - let expected_start = i; - while i < lines.len() { - if is_next_case_header(&lines, i) { - break; - } - i += 1; - } - expected = lines[expected_start..i].join("\n").trim().to_string(); - } +/// Parse a corpus `.output` file. The file holds a single test case made of +/// three sections separated by `---` delimiter lines: +/// +/// ```text +/// +/// +/// --- +/// +/// +/// +/// --- +/// +/// +/// ``` +/// +/// The test name is the file name, so there is no header section. Missing +/// trailing sections (e.g. a freshly added file) are treated as empty. +fn parse_corpus(content: &str) -> CorpusCase { + let lines: Vec<&str> = content.split('\n').collect(); + let mut sections = lines + .split(|line| line.trim() == "---") + .map(|chunk| chunk.join("\n").trim().to_string()); - cases.push(CorpusCase { - name, - input, - raw, - expected, - }); + CorpusCase { + input: sections.next().unwrap_or_default(), + raw: sections.next().unwrap_or_default(), + expected: sections.next().unwrap_or_default(), } - - cases } -fn render_corpus(cases: &[CorpusCase]) -> String { - let mut out = String::new(); - - for (idx, case) in cases.iter().enumerate() { - if idx > 0 { - // Blank line between cases. - out.push('\n'); - } - out.push_str("===\n"); - out.push_str(case.name.trim()); - out.push_str("\n===\n\n"); - out.push_str(case.input.trim()); - out.push_str("\n\n---\n\n"); - out.push_str(case.raw.trim()); - out.push_str("\n\n---\n\n"); - out.push_str(case.expected.trim()); - // Single trailing newline per case; the inter-case blank line is - // added by the prefix above, and the file ends with exactly one `\n`. - out.push('\n'); - } - - out +fn render_corpus(case: &CorpusCase) -> String { + format!( + "{}\n\n---\n\n{}\n\n---\n\n{}\n", + case.input.trim(), + case.raw.trim(), + case.expected.trim() + ) } fn run_desugaring(lang: &simple::LanguageSpec, input: &str) -> Result { @@ -182,6 +95,26 @@ fn dump_raw_parse(lang: &simple::LanguageSpec, input: &str) -> Result) { + let entries = fs::read_dir(dir) + .unwrap_or_else(|e| panic!("Failed to read corpus directory {}: {e}", dir.display())); + for entry in entries { + let path = entry.expect("Failed to read corpus entry").path(); + if path.is_dir() { + collect_corpus_stems(&path, out); + } else if path + .extension() + .is_some_and(|ext| ext == "swift" || ext == "output") + { + out.push(path.with_extension("")); + } + } +} + #[test] fn test_corpus() { let update_mode = update_mode_enabled(); @@ -200,47 +133,85 @@ fn test_corpus() { continue; } - let mut corpus_files: Vec<_> = fs::read_dir(&lang_corpus_dir) - .unwrap_or_else(|e| { - panic!( - "Failed to read corpus directory {}: {e}", - lang_corpus_dir.display() - ) - }) - .map(|entry| entry.expect("Failed to read corpus entry").path()) - .filter(|path| path.extension().is_some_and(|ext| ext == "txt")) - .collect(); - corpus_files.sort(); + let mut stems = Vec::new(); + collect_corpus_stems(&lang_corpus_dir, &mut stems); + stems.sort(); + stems.dedup(); - for corpus_path in corpus_files { - let content = fs::read_to_string(&corpus_path) - .unwrap_or_else(|e| panic!("Failed to read {}: {e}", corpus_path.display())); - let mut cases = parse_corpus(&content); + for stem in stems { + let swift_path = stem.with_extension("swift"); + let output_path = stem.with_extension("output"); let mut failures = Vec::new(); - assert!( - !cases.is_empty(), - "No corpus cases found in {}", - corpus_path.display() - ); - for case in &mut cases { - match dump_raw_parse(&lang, &case.input) { + // The canonical test case lives in the `.swift` file and is the + // source of truth. An `.output` file without a `.swift` sibling is + // an orphan: there is nothing to drive it from. + if !swift_path.exists() { + panic!( + "Found {} with no corresponding test case; add {} or remove the output file", + output_path.display(), + swift_path.display() + ); + } + + let swift_input = fs::read_to_string(&swift_path) + .unwrap_or_else(|e| panic!("Failed to read {}: {e}", swift_path.display())) + .trim() + .to_string(); + + // Build the case from the existing `.output` file when present. + // When it is missing (a freshly added `.swift`), start from an + // empty case: update mode will generate it, and a normal test run + // reports the missing output. + let mut case = if output_path.exists() { + let content = fs::read_to_string(&output_path) + .unwrap_or_else(|e| panic!("Failed to read {}: {e}", output_path.display())); + parse_corpus(&content) + } else { + if !update_mode { + failures.push(format!( + "Missing output file {}; run scripts/update-corpus.sh to generate it", + output_path.display() + )); + } + CorpusCase { + input: String::new(), + raw: String::new(), + expected: String::new(), + } + }; + + { + // The input section in the `.output` file is a generated copy + // of the `.swift` source, kept only so reviewers can see the + // source alongside its printed ASTs. + if update_mode { + case.input = swift_input.clone(); + } else if output_path.exists() && case.input.trim() != swift_input { + failures.push(format!( + "Test case copy out of date in {}; rerun update-corpus to regenerate from {}", + output_path.display(), + swift_path.display() + )); + } + // Ensure the AST passes below operate on the source of truth. + let case_input = swift_input.clone(); + + match dump_raw_parse(&lang, &case_input) { Err(e) => { failures.push(format!( - "Raw parse failed for {} in {}: {}", - case.name, - corpus_path.display(), + "Raw parse failed in {}: {}", + output_path.display(), e )); } Ok(actual_raw) => { if update_mode { case.raw = actual_raw.trim().to_string(); - } else if case.raw.trim() != actual_raw.trim() { + } else if output_path.exists() && case.raw.trim() != actual_raw.trim() { failures.push(format!( - "Raw parse mismatch in {}: \"{}\"\nEXPECTED:\n\n{}\n\nACTUAL:\n\n{}", - corpus_path.display(), - case.name, + "Raw parse mismatch in {}:\nEXPECTED:\n\n{}\n\nACTUAL:\n\n{}", + output_path.display(), case.raw.trim(), actual_raw.trim() )); @@ -248,12 +219,11 @@ fn test_corpus() { } } - match run_desugaring(&lang, &case.input) { + match run_desugaring(&lang, &case_input) { Err(e) => { failures.push(format!( - "Desugaring failed for {} in {}: {}", - case.name, - corpus_path.display(), + "Desugaring failed in {}: {}", + output_path.display(), e )); } @@ -261,16 +231,17 @@ fn test_corpus() { let actual_dump = dump_ast_with_type_errors( &actual, actual.get_root(), - &case.input, + &case_input, &output_schema, ); if update_mode { case.expected = actual_dump.trim().to_string(); - } else if case.expected.trim() != actual_dump.trim() { + } else if output_path.exists() + && case.expected.trim() != actual_dump.trim() + { failures.push(format!( - "Test failed in {}: \"{}\"\nEXPECTED:\n\n{}\n\nACTUAL:\n\n{}", - corpus_path.display(), - case.name, + "Test failed in {}:\nEXPECTED:\n\n{}\n\nACTUAL:\n\n{}", + output_path.display(), case.expected.trim(), actual_dump.trim() )); @@ -282,12 +253,12 @@ fn test_corpus() { assert!(failures.is_empty(), "{}", failures.join("\n\n") + "\n\n"); if update_mode { - let updated = render_corpus(&cases); - let write_result = fs::write(&corpus_path, updated); + let updated = render_corpus(&case); + let write_result = fs::write(&output_path, updated); assert!( write_result.is_ok(), "Failed to update corpus file {}: {}", - corpus_path.display(), + output_path.display(), write_result .err() .map_or_else(String::new, |e| e.to_string()) From 12bd3e2860a87d9778376e734b804796bed55fcb Mon Sep 17 00:00:00 2001 From: Asger F Date: Mon, 29 Jun 2026 13:49:02 +0200 Subject: [PATCH 2/3] unified: Bulk migrate all corpus tests to the new system --- .../extractor/tests/corpus/swift/closures.txt | 377 ------ .../closures/closure-with-capture-list.output | 69 ++ .../closures/closure-with-capture-list.swift | 1 + .../closure-with-explicit-parameters.output | 77 ++ .../closure-with-explicit-parameters.swift | 1 + .../closure-with-shorthand-parameters.output | 47 + .../closure-with-shorthand-parameters.swift | 1 + .../closures/multi-statement-closure.output | 111 ++ .../closures/multi-statement-closure.swift | 4 + .../swift/closures/trailing-closure.output | 49 + .../swift/closures/trailing-closure.swift | 1 + .../tests/corpus/swift/collections.txt | 410 ------- .../swift/collections/array-literal.output | 39 + .../swift/collections/array-literal.swift | 1 + .../collections/dictionary-literal.output | 41 + .../collections/dictionary-literal.swift | 1 + .../collections/dictionary-subscript.output | 51 + .../collections/dictionary-subscript.swift | 3 + .../empty-array-literal-with-type.output | 51 + .../empty-array-literal-with-type.swift | 1 + .../swift/collections/set-literal.output | 60 + .../swift/collections/set-literal.swift | 1 + .../swift/collections/subscript-access.output | 51 + .../swift/collections/subscript-access.swift | 4 + .../swift/collections/tuple-literal.output | 39 + .../swift/collections/tuple-literal.swift | 1 + .../collections/tuple-member-access.output | 39 + .../collections/tuple-member-access.swift | 1 + .../tests/corpus/swift/control-flow.txt | 966 --------------- .../swift/control-flow/guard-let.output | 52 + .../corpus/swift/control-flow/guard-let.swift | 1 + ...t-with-shadowing-in-condition-value.output | 72 ++ ...et-with-shadowing-in-condition-value.swift | 3 + .../control-flow/if-else-if-chain.output | 119 ++ .../swift/control-flow/if-else-if-chain.swift | 7 + .../corpus/swift/control-flow/if-else.output | 87 ++ .../corpus/swift/control-flow/if-else.swift | 5 + .../if-let-optional-binding.output | 70 ++ .../if-let-optional-binding.swift | 3 + .../swift/control-flow/if-statement.output | 55 + .../swift/control-flow/if-statement.swift | 3 + .../control-flow/switch-statement.output | 125 ++ .../swift/control-flow/switch-statement.swift | 8 + .../switch-with-binding-pattern.output | 140 +++ .../switch-with-binding-pattern.swift | 6 + ...with-labeled-case-pattern-arguments.output | 144 +++ ...-with-labeled-case-pattern-arguments.swift | 6 + .../control-flow/ternary-expression.output | 53 + .../control-flow/ternary-expression.swift | 1 + .../extractor/tests/corpus/swift/desugar.txt | 186 --- .../additive-expression-is-desugared.output | 21 + .../additive-expression-is-desugared.swift | 1 + ...er-additive-expression-is-desugared.output | 25 + ...her-additive-expression-is-desugared.swift | 1 + ...with-deeply-nested-path-three-parts.output | 31 + ...-with-deeply-nested-path-three-parts.swift | 1 + .../import-with-dotted-path-two-parts.output | 27 + .../import-with-dotted-path-two-parts.swift | 1 + .../scoped-import-uses-name-pattern.output | 31 + .../scoped-import-uses-name-pattern.swift | 1 + .../simple-import-with-single-name.output | 22 + .../simple-import-with-single-name.swift | 1 + .../tests/corpus/swift/functions.txt | 657 ---------- ...nction-call-with-labelled-arguments.output | 35 + ...unction-call-with-labelled-arguments.swift | 1 + .../swift/functions/function-call.output | 33 + .../swift/functions/function-call.swift | 1 + ...nction-with-default-parameter-value.output | 64 + ...unction-with-default-parameter-value.swift | 3 + .../function-with-named-parameters.output | 62 + .../function-with-named-parameters.swift | 3 + .../function-with-no-parameters.output | 43 + .../function-with-no-parameters.swift | 3 + ...ion-with-parameters-and-return-type.output | 88 ++ ...tion-with-parameters-and-return-type.swift | 3 + .../swift/functions/generic-function.output | 66 + .../swift/functions/generic-function.swift | 3 + .../leading-dot-expression-call.output | 49 + .../leading-dot-expression-call.swift | 1 + .../leading-dot-expression-value.output | 35 + .../leading-dot-expression-value.swift | 1 + .../corpus/swift/functions/method-call.output | 37 + .../corpus/swift/functions/method-call.swift | 1 + .../swift/functions/variadic-function.output | 91 ++ .../swift/functions/variadic-function.swift | 3 + .../extractor/tests/corpus/swift/literals.txt | 143 --- .../swift/literals/boolean-literals.output | 18 + .../swift/literals/boolean-literals.swift | 2 + .../literals/floating-point-literal.output | 13 + .../literals/floating-point-literal.swift | 1 + .../swift/literals/integer-literal.output | 13 + .../swift/literals/integer-literal.swift | 1 + .../literals/negative-integer-literal.output | 19 + .../literals/negative-integer-literal.swift | 1 + .../corpus/swift/literals/nil-literal.output | 13 + .../corpus/swift/literals/nil-literal.swift | 1 + .../swift/literals/string-literal.output | 15 + .../swift/literals/string-literal.swift | 1 + .../literals/string-with-interpolation.output | 18 + .../literals/string-with-interpolation.swift | 1 + .../extractor/tests/corpus/swift/loops.txt | 410 ------- .../swift/loops/break-and-continue.output | 101 ++ .../swift/loops/break-and-continue.swift | 5 + .../loops/for-in-over-array-literal.output | 59 + .../loops/for-in-over-array-literal.swift | 3 + .../swift/loops/for-in-over-range.output | 57 + .../swift/loops/for-in-over-range.swift | 3 + .../loops/for-in-with-where-clause.output | 66 + .../loops/for-in-with-where-clause.swift | 3 + .../swift/loops/repeat-while-loop.output | 49 + .../swift/loops/repeat-while-loop.swift | 3 + .../corpus/swift/loops/while-loop.output | 49 + .../tests/corpus/swift/loops/while-loop.swift | 3 + .../tests/corpus/swift/operators.txt | 367 ------ .../corpus/swift/operators/addition.output | 25 + .../corpus/swift/operators/addition.swift | 1 + .../corpus/swift/operators/comparison.output | 25 + .../corpus/swift/operators/comparison.swift | 1 + .../corpus/swift/operators/division.output | 25 + .../corpus/swift/operators/division.swift | 1 + .../corpus/swift/operators/equality.output | 25 + .../corpus/swift/operators/equality.swift | 1 + .../corpus/swift/operators/logical-and.output | 25 + .../corpus/swift/operators/logical-and.swift | 1 + .../corpus/swift/operators/logical-not.output | 21 + .../corpus/swift/operators/logical-not.swift | 1 + .../corpus/swift/operators/logical-or.output | 25 + .../corpus/swift/operators/logical-or.swift | 1 + .../swift/operators/multiplication.output | 25 + .../swift/operators/multiplication.swift | 1 + ...cedence-addition-and-multiplication.output | 35 + ...ecedence-addition-and-multiplication.swift | 1 + .../operators/parenthesised-expression.output | 31 + .../operators/parenthesised-expression.swift | 1 + .../swift/operators/range-operator.output | 21 + .../swift/operators/range-operator.swift | 1 + .../corpus/swift/operators/subtraction.output | 25 + .../corpus/swift/operators/subtraction.swift | 1 + .../corpus/swift/optionals-and-errors.txt | 418 ------- .../optionals-and-errors/do-catch.output | 71 ++ .../swift/optionals-and-errors/do-catch.swift | 5 + .../optionals-and-errors/force-unwrap.output | 37 + .../optionals-and-errors/force-unwrap.swift | 1 + .../nil-coalescing.output | 38 + .../optionals-and-errors/nil-coalescing.swift | 1 + .../optional-chaining.output | 51 + .../optional-chaining.swift | 1 + .../optional-type-annotation.output | 48 + .../optional-type-annotation.swift | 1 + .../throwing-function.output | 42 + .../throwing-function.swift | 3 + .../try-expression-2.output | 46 + .../try-expression-2.swift | 1 + .../try-expression.output | 46 + .../optionals-and-errors/try-expression.swift | 1 + .../extractor/tests/corpus/swift/types.txt | 1082 ----------------- .../swift/types/class-inheritance.output | 28 + .../swift/types/class-inheritance.swift | 1 + .../swift/types/class-with-initializer.output | 96 ++ .../swift/types/class-with-initializer.swift | 6 + .../swift/types/class-with-method.output | 66 + .../swift/types/class-with-method.swift | 6 + .../types/class-with-stored-properties.output | 78 ++ .../types/class-with-stored-properties.swift | 4 + .../swift/types/computed-property.output | 129 ++ .../swift/types/computed-property.swift | 7 + .../corpus/swift/types/empty-class.output | 21 + .../corpus/swift/types/empty-class.swift | 1 + .../types/enum-with-associated-values.output | 86 ++ .../types/enum-with-associated-values.swift | 4 + .../corpus/swift/types/enum-with-cases.output | 64 + .../corpus/swift/types/enum-with-cases.swift | 6 + ...separated-cases-chained-declaration.output | 61 + ...-separated-cases-chained-declaration.swift | 3 + .../tests/corpus/swift/types/extension.output | 68 ++ .../tests/corpus/swift/types/extension.swift | 3 + .../property-with-getter-and-setter.output | 124 ++ .../property-with-getter-and-setter.swift | 7 + .../swift/types/protocol-declaration.output | 29 + .../swift/types/protocol-declaration.swift | 3 + ...nd-read-write-property-requirements.output | 85 ++ ...and-read-write-property-requirements.swift | 4 + .../tests/corpus/swift/types/struct.output | 78 ++ .../tests/corpus/swift/types/struct.swift | 4 + .../tests/corpus/swift/variables.txt | 448 ------- .../corpus/swift/variables/assignment.output | 24 + .../corpus/swift/variables/assignment.swift | 1 + .../variables/compound-assignment.output | 25 + .../swift/variables/compound-assignment.swift | 1 + .../corpus/swift/variables/let-binding.output | 29 + .../corpus/swift/variables/let-binding.swift | 1 + .../variables/let-with-type-annotation.output | 41 + .../variables/let-with-type-annotation.swift | 1 + .../multiple-bindings-on-one-line.output | 42 + .../multiple-bindings-on-one-line.swift | 1 + ...y-with-willset-and-didset-observers.output | 122 ++ ...ty-with-willset-and-didset-observers.swift | 6 + .../tuple-destructuring-binding.output | 53 + .../tuple-destructuring-binding.swift | 1 + .../corpus/swift/variables/var-binding.output | 29 + .../corpus/swift/variables/var-binding.swift | 1 + .../variables/var-without-initialiser.output | 39 + .../variables/var-without-initialiser.swift | 1 + 203 files changed, 5215 insertions(+), 5464 deletions(-) delete mode 100644 unified/extractor/tests/corpus/swift/closures.txt create mode 100644 unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output create mode 100644 unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.swift create mode 100644 unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output create mode 100644 unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.swift create mode 100644 unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output create mode 100644 unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.swift create mode 100644 unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output create mode 100644 unified/extractor/tests/corpus/swift/closures/multi-statement-closure.swift create mode 100644 unified/extractor/tests/corpus/swift/closures/trailing-closure.output create mode 100644 unified/extractor/tests/corpus/swift/closures/trailing-closure.swift delete mode 100644 unified/extractor/tests/corpus/swift/collections.txt create mode 100644 unified/extractor/tests/corpus/swift/collections/array-literal.output create mode 100644 unified/extractor/tests/corpus/swift/collections/array-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/dictionary-literal.output create mode 100644 unified/extractor/tests/corpus/swift/collections/dictionary-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output create mode 100644 unified/extractor/tests/corpus/swift/collections/dictionary-subscript.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output create mode 100644 unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/set-literal.output create mode 100644 unified/extractor/tests/corpus/swift/collections/set-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/subscript-access.output create mode 100644 unified/extractor/tests/corpus/swift/collections/subscript-access.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/tuple-literal.output create mode 100644 unified/extractor/tests/corpus/swift/collections/tuple-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/collections/tuple-member-access.output create mode 100644 unified/extractor/tests/corpus/swift/collections/tuple-member-access.swift delete mode 100644 unified/extractor/tests/corpus/swift/control-flow.txt create mode 100644 unified/extractor/tests/corpus/swift/control-flow/guard-let.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/guard-let.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-else.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-else.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-statement.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/if-statement.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/switch-statement.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/switch-statement.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.swift create mode 100644 unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output create mode 100644 unified/extractor/tests/corpus/swift/control-flow/ternary-expression.swift delete mode 100644 unified/extractor/tests/corpus/swift/desugar.txt create mode 100644 unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.output create mode 100644 unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.swift create mode 100644 unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output create mode 100644 unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.swift create mode 100644 unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output create mode 100644 unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.swift create mode 100644 unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output create mode 100644 unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.swift create mode 100644 unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output create mode 100644 unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.swift create mode 100644 unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output create mode 100644 unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.swift delete mode 100644 unified/extractor/tests/corpus/swift/functions.txt create mode 100644 unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output create mode 100644 unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/function-call.output create mode 100644 unified/extractor/tests/corpus/swift/functions/function-call.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output create mode 100644 unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/generic-function.output create mode 100644 unified/extractor/tests/corpus/swift/functions/generic-function.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output create mode 100644 unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output create mode 100644 unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/method-call.output create mode 100644 unified/extractor/tests/corpus/swift/functions/method-call.swift create mode 100644 unified/extractor/tests/corpus/swift/functions/variadic-function.output create mode 100644 unified/extractor/tests/corpus/swift/functions/variadic-function.swift delete mode 100644 unified/extractor/tests/corpus/swift/literals.txt create mode 100644 unified/extractor/tests/corpus/swift/literals/boolean-literals.output create mode 100644 unified/extractor/tests/corpus/swift/literals/boolean-literals.swift create mode 100644 unified/extractor/tests/corpus/swift/literals/floating-point-literal.output create mode 100644 unified/extractor/tests/corpus/swift/literals/floating-point-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/literals/integer-literal.output create mode 100644 unified/extractor/tests/corpus/swift/literals/integer-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/literals/negative-integer-literal.output create mode 100644 unified/extractor/tests/corpus/swift/literals/negative-integer-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/literals/nil-literal.output create mode 100644 unified/extractor/tests/corpus/swift/literals/nil-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/literals/string-literal.output create mode 100644 unified/extractor/tests/corpus/swift/literals/string-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/literals/string-with-interpolation.output create mode 100644 unified/extractor/tests/corpus/swift/literals/string-with-interpolation.swift delete mode 100644 unified/extractor/tests/corpus/swift/loops.txt create mode 100644 unified/extractor/tests/corpus/swift/loops/break-and-continue.output create mode 100644 unified/extractor/tests/corpus/swift/loops/break-and-continue.swift create mode 100644 unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output create mode 100644 unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.swift create mode 100644 unified/extractor/tests/corpus/swift/loops/for-in-over-range.output create mode 100644 unified/extractor/tests/corpus/swift/loops/for-in-over-range.swift create mode 100644 unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output create mode 100644 unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.swift create mode 100644 unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output create mode 100644 unified/extractor/tests/corpus/swift/loops/repeat-while-loop.swift create mode 100644 unified/extractor/tests/corpus/swift/loops/while-loop.output create mode 100644 unified/extractor/tests/corpus/swift/loops/while-loop.swift delete mode 100644 unified/extractor/tests/corpus/swift/operators.txt create mode 100644 unified/extractor/tests/corpus/swift/operators/addition.output create mode 100644 unified/extractor/tests/corpus/swift/operators/addition.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/comparison.output create mode 100644 unified/extractor/tests/corpus/swift/operators/comparison.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/division.output create mode 100644 unified/extractor/tests/corpus/swift/operators/division.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/equality.output create mode 100644 unified/extractor/tests/corpus/swift/operators/equality.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/logical-and.output create mode 100644 unified/extractor/tests/corpus/swift/operators/logical-and.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/logical-not.output create mode 100644 unified/extractor/tests/corpus/swift/operators/logical-not.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/logical-or.output create mode 100644 unified/extractor/tests/corpus/swift/operators/logical-or.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/multiplication.output create mode 100644 unified/extractor/tests/corpus/swift/operators/multiplication.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output create mode 100644 unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output create mode 100644 unified/extractor/tests/corpus/swift/operators/parenthesised-expression.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/range-operator.output create mode 100644 unified/extractor/tests/corpus/swift/operators/range-operator.swift create mode 100644 unified/extractor/tests/corpus/swift/operators/subtraction.output create mode 100644 unified/extractor/tests/corpus/swift/operators/subtraction.swift delete mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors.txt create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.swift create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output create mode 100644 unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.swift delete mode 100644 unified/extractor/tests/corpus/swift/types.txt create mode 100644 unified/extractor/tests/corpus/swift/types/class-inheritance.output create mode 100644 unified/extractor/tests/corpus/swift/types/class-inheritance.swift create mode 100644 unified/extractor/tests/corpus/swift/types/class-with-initializer.output create mode 100644 unified/extractor/tests/corpus/swift/types/class-with-initializer.swift create mode 100644 unified/extractor/tests/corpus/swift/types/class-with-method.output create mode 100644 unified/extractor/tests/corpus/swift/types/class-with-method.swift create mode 100644 unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output create mode 100644 unified/extractor/tests/corpus/swift/types/class-with-stored-properties.swift create mode 100644 unified/extractor/tests/corpus/swift/types/computed-property.output create mode 100644 unified/extractor/tests/corpus/swift/types/computed-property.swift create mode 100644 unified/extractor/tests/corpus/swift/types/empty-class.output create mode 100644 unified/extractor/tests/corpus/swift/types/empty-class.swift create mode 100644 unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output create mode 100644 unified/extractor/tests/corpus/swift/types/enum-with-associated-values.swift create mode 100644 unified/extractor/tests/corpus/swift/types/enum-with-cases.output create mode 100644 unified/extractor/tests/corpus/swift/types/enum-with-cases.swift create mode 100644 unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output create mode 100644 unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.swift create mode 100644 unified/extractor/tests/corpus/swift/types/extension.output create mode 100644 unified/extractor/tests/corpus/swift/types/extension.swift create mode 100644 unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output create mode 100644 unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.swift create mode 100644 unified/extractor/tests/corpus/swift/types/protocol-declaration.output create mode 100644 unified/extractor/tests/corpus/swift/types/protocol-declaration.swift create mode 100644 unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output create mode 100644 unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift create mode 100644 unified/extractor/tests/corpus/swift/types/struct.output create mode 100644 unified/extractor/tests/corpus/swift/types/struct.swift delete mode 100644 unified/extractor/tests/corpus/swift/variables.txt create mode 100644 unified/extractor/tests/corpus/swift/variables/assignment.output create mode 100644 unified/extractor/tests/corpus/swift/variables/assignment.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/compound-assignment.output create mode 100644 unified/extractor/tests/corpus/swift/variables/compound-assignment.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/let-binding.output create mode 100644 unified/extractor/tests/corpus/swift/variables/let-binding.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output create mode 100644 unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output create mode 100644 unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output create mode 100644 unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output create mode 100644 unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/var-binding.output create mode 100644 unified/extractor/tests/corpus/swift/variables/var-binding.swift create mode 100644 unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output create mode 100644 unified/extractor/tests/corpus/swift/variables/var-without-initialiser.swift diff --git a/unified/extractor/tests/corpus/swift/closures.txt b/unified/extractor/tests/corpus/swift/closures.txt deleted file mode 100644 index 1d058dfb1e3c..000000000000 --- a/unified/extractor/tests/corpus/swift/closures.txt +++ /dev/null @@ -1,377 +0,0 @@ -=== -Closure with explicit parameters -=== - -let f = { (x: Int) -> Int in x * 2 } - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "f" - value: - lambda_literal - statement: - multiplicative_expression - lhs: simple_identifier "x" - op: * - rhs: integer_literal "2" - type: - lambda_function_type - params: - lambda_function_type_parameters - parameter: - lambda_parameter - name: simple_identifier "x" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "f" - value: - function_expr - body: - block - stmt: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "x" - right: int_literal "2" - parameter: - parameter - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - return_type: - named_type_expr - name: identifier "Int" - -=== -Closure with shorthand parameters -=== - -let f = { $0 + $1 } - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "f" - value: - lambda_literal - statement: - additive_expression - lhs: simple_identifier "$0" - op: + - rhs: simple_identifier "$1" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "f" - value: - function_expr - body: - block - stmt: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "$0" - right: - name_expr - identifier: identifier "$1" - -=== -Trailing closure -=== - -xs.map { $0 * 2 } - ---- - -source_file - statement: - call_expression - function: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "map" - target: simple_identifier "xs" - suffix: - call_suffix - lambda: - lambda_literal - statement: - multiplicative_expression - lhs: simple_identifier "$0" - op: * - rhs: integer_literal "2" - ---- - -top_level - body: - block - stmt: - call_expr - argument: - argument - value: - function_expr - body: - block - stmt: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "$0" - right: int_literal "2" - callee: - member_access_expr - base: - name_expr - identifier: identifier "xs" - member: identifier "map" - -=== -Closure with capture list -=== - -let f = { [weak self] in self?.doThing() } - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "f" - value: - lambda_literal - captures: - capture_list - item: - capture_list_item - name: simple_identifier "self" - ownership: - ownership_modifier - statement: - call_expression - function: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "doThing" - target: - optional_chain_marker - expr: - self_expression - suffix: - call_suffix - arguments: - value_arguments - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "f" - value: - function_expr - body: - block - stmt: - call_expr - callee: - member_access_expr - base: - name_expr - identifier: identifier "self" - member: identifier "doThing" - capture_declaration: - variable_declaration - modifier: modifier "weak" - pattern: - name_pattern - identifier: identifier "self" - -=== -Multi-statement closure -=== - -let f = { (x: Int) -> Int in - let y = x + 1 - return y * 2 -} - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "f" - value: - lambda_literal - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "y" - value: - additive_expression - lhs: simple_identifier "x" - op: + - rhs: integer_literal "1" - control_transfer_statement - kind: return - result: - multiplicative_expression - lhs: simple_identifier "y" - op: * - rhs: integer_literal "2" - type: - lambda_function_type - params: - lambda_function_type_parameters - parameter: - lambda_parameter - name: simple_identifier "x" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "f" - value: - function_expr - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "y" - value: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "x" - right: int_literal "1" - return_expr - value: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "y" - right: int_literal "2" - parameter: - parameter - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - return_type: - named_type_expr - name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output new file mode 100644 index 000000000000..8f28322b4930 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output @@ -0,0 +1,69 @@ +let f = { [weak self] in self?.doThing() } + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "f" + value: + lambda_literal + captures: + capture_list + item: + capture_list_item + name: simple_identifier "self" + ownership: + ownership_modifier + statement: + call_expression + function: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "doThing" + target: + optional_chain_marker + expr: + self_expression + suffix: + call_suffix + arguments: + value_arguments + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "f" + value: + function_expr + body: + block + stmt: + call_expr + callee: + member_access_expr + base: + name_expr + identifier: identifier "self" + member: identifier "doThing" + capture_declaration: + variable_declaration + modifier: modifier "weak" + pattern: + name_pattern + identifier: identifier "self" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.swift b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.swift new file mode 100644 index 000000000000..e6b06ca3d0db --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.swift @@ -0,0 +1 @@ +let f = { [weak self] in self?.doThing() } diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output new file mode 100644 index 000000000000..95d638118d84 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output @@ -0,0 +1,77 @@ +let f = { (x: Int) -> Int in x * 2 } + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "f" + value: + lambda_literal + statement: + multiplicative_expression + lhs: simple_identifier "x" + op: * + rhs: integer_literal "2" + type: + lambda_function_type + params: + lambda_function_type_parameters + parameter: + lambda_parameter + name: simple_identifier "x" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "f" + value: + function_expr + body: + block + stmt: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "x" + right: int_literal "2" + parameter: + parameter + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + return_type: + named_type_expr + name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.swift b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.swift new file mode 100644 index 000000000000..f0c276371a26 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.swift @@ -0,0 +1 @@ +let f = { (x: Int) -> Int in x * 2 } diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output new file mode 100644 index 000000000000..bd286c385799 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output @@ -0,0 +1,47 @@ +let f = { $0 + $1 } + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "f" + value: + lambda_literal + statement: + additive_expression + lhs: simple_identifier "$0" + op: + + rhs: simple_identifier "$1" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "f" + value: + function_expr + body: + block + stmt: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "$0" + right: + name_expr + identifier: identifier "$1" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.swift b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.swift new file mode 100644 index 000000000000..09eabcd29fd8 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.swift @@ -0,0 +1 @@ +let f = { $0 + $1 } diff --git a/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output new file mode 100644 index 000000000000..6c9a403f19c1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output @@ -0,0 +1,111 @@ +let f = { (x: Int) -> Int in + let y = x + 1 + return y * 2 +} + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "f" + value: + lambda_literal + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "y" + value: + additive_expression + lhs: simple_identifier "x" + op: + + rhs: integer_literal "1" + control_transfer_statement + kind: return + result: + multiplicative_expression + lhs: simple_identifier "y" + op: * + rhs: integer_literal "2" + type: + lambda_function_type + params: + lambda_function_type_parameters + parameter: + lambda_parameter + name: simple_identifier "x" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "f" + value: + function_expr + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "y" + value: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "x" + right: int_literal "1" + return_expr + value: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "y" + right: int_literal "2" + parameter: + parameter + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + return_type: + named_type_expr + name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.swift b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.swift new file mode 100644 index 000000000000..66d6e508592b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.swift @@ -0,0 +1,4 @@ +let f = { (x: Int) -> Int in + let y = x + 1 + return y * 2 +} diff --git a/unified/extractor/tests/corpus/swift/closures/trailing-closure.output b/unified/extractor/tests/corpus/swift/closures/trailing-closure.output new file mode 100644 index 000000000000..56b8bf9a7c20 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/trailing-closure.output @@ -0,0 +1,49 @@ +xs.map { $0 * 2 } + +--- + +source_file + statement: + call_expression + function: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "map" + target: simple_identifier "xs" + suffix: + call_suffix + lambda: + lambda_literal + statement: + multiplicative_expression + lhs: simple_identifier "$0" + op: * + rhs: integer_literal "2" + +--- + +top_level + body: + block + stmt: + call_expr + argument: + argument + value: + function_expr + body: + block + stmt: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "$0" + right: int_literal "2" + callee: + member_access_expr + base: + name_expr + identifier: identifier "xs" + member: identifier "map" diff --git a/unified/extractor/tests/corpus/swift/closures/trailing-closure.swift b/unified/extractor/tests/corpus/swift/closures/trailing-closure.swift new file mode 100644 index 000000000000..285bcc5e9b0d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/closures/trailing-closure.swift @@ -0,0 +1 @@ +xs.map { $0 * 2 } diff --git a/unified/extractor/tests/corpus/swift/collections.txt b/unified/extractor/tests/corpus/swift/collections.txt deleted file mode 100644 index 2ecdf5a0179b..000000000000 --- a/unified/extractor/tests/corpus/swift/collections.txt +++ /dev/null @@ -1,410 +0,0 @@ -=== -Array literal -=== - -let xs = [1, 2, 3] - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "xs" - value: - array_literal - element: - integer_literal "1" - integer_literal "2" - integer_literal "3" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "xs" - value: - array_literal - element: - int_literal "1" - int_literal "2" - int_literal "3" - -=== -Empty array literal with type -=== - -let xs: [Int] = [] - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "xs" - type: - type_annotation - type: - type - name: - array_type - element: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - value: - array_literal - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "xs" - type: - generic_type_expr - base: - named_type_expr - name: identifier "Array" - type_argument: - named_type_expr - name: identifier "Int" - value: array_literal "[]" - -=== -Dictionary literal -=== - -let d = ["a": 1, "b": 2] - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "d" - value: - dictionary_literal - element: - dictionary_literal_item - key: - line_string_literal - text: line_str_text "a" - value: integer_literal "1" - dictionary_literal_item - key: - line_string_literal - text: line_str_text "b" - value: integer_literal "2" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "d" - value: map_literal "[\"a\": 1, \"b\": 2]" - -=== -Set literal -=== - -let s: Set = [1, 2, 3] - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "s" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - arguments: - type_arguments - argument: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - name: type_identifier "Set" - value: - array_literal - element: - integer_literal "1" - integer_literal "2" - integer_literal "3" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "s" - type: - named_type_expr - name: identifier "Set" - value: - array_literal - element: - int_literal "1" - int_literal "2" - int_literal "3" - -=== -Tuple literal -=== - -let t = (1, "two", 3.0) - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "t" - value: - tuple_expression - element: - tuple_expression_item - value: integer_literal "1" - tuple_expression_item - value: - line_string_literal - text: line_str_text "two" - tuple_expression_item - value: real_literal "3.0" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "t" - value: tuple_expr "(1, \"two\", 3.0)" - -=== -Subscript access -=== - -// TODO: tree-sitter-swift parses `xs[0]` as a call_expression (same shape -// as `xs(0)`), so the mapping currently produces a call_expr. Update the -// parser / add a separate subscript_expr node and remap when fixed. -let first = xs[0] - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "first" - value: - call_expression - function: simple_identifier "xs" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "0" - comment "// TODO: tree-sitter-swift parses `xs[0]` as a call_expression (same shape" - comment "// as `xs(0)`), so the mapping currently produces a call_expr. Update the" - comment "// parser / add a separate subscript_expr node and remap when fixed." - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "first" - value: - call_expr - argument: - argument - value: int_literal "0" - callee: - name_expr - identifier: identifier "xs" - -=== -Dictionary subscript -=== - -// TODO: same parser issue as the array subscript case above — -// `d["key"]` is parsed as `call_expression(d, ("key"))`. -let v = d["key"] - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "v" - value: - call_expression - function: simple_identifier "d" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - line_string_literal - text: line_str_text "key" - comment "// TODO: same parser issue as the array subscript case above —" - comment "// `d[\"key\"]` is parsed as `call_expression(d, (\"key\"))`." - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "v" - value: - call_expr - argument: - argument - value: string_literal "\"key\"" - callee: - name_expr - identifier: identifier "d" - -=== -Tuple member access -=== - -let n = t.0 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "n" - value: - navigation_expression - suffix: - navigation_suffix - suffix: integer_literal "0" - target: simple_identifier "t" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "n" - value: - member_access_expr - base: - name_expr - identifier: identifier "t" - member: identifier "0" diff --git a/unified/extractor/tests/corpus/swift/collections/array-literal.output b/unified/extractor/tests/corpus/swift/collections/array-literal.output new file mode 100644 index 000000000000..f6ee44c1f809 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/array-literal.output @@ -0,0 +1,39 @@ +let xs = [1, 2, 3] + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "xs" + value: + array_literal + element: + integer_literal "1" + integer_literal "2" + integer_literal "3" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "xs" + value: + array_literal + element: + int_literal "1" + int_literal "2" + int_literal "3" diff --git a/unified/extractor/tests/corpus/swift/collections/array-literal.swift b/unified/extractor/tests/corpus/swift/collections/array-literal.swift new file mode 100644 index 000000000000..eda1f726b64c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/array-literal.swift @@ -0,0 +1 @@ +let xs = [1, 2, 3] diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output new file mode 100644 index 000000000000..a19028d3f3bb --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output @@ -0,0 +1,41 @@ +let d = ["a": 1, "b": 2] + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "d" + value: + dictionary_literal + element: + dictionary_literal_item + key: + line_string_literal + text: line_str_text "a" + value: integer_literal "1" + dictionary_literal_item + key: + line_string_literal + text: line_str_text "b" + value: integer_literal "2" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "d" + value: map_literal "[\"a\": 1, \"b\": 2]" diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-literal.swift b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.swift new file mode 100644 index 000000000000..1b9eb5ebe2c4 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.swift @@ -0,0 +1 @@ +let d = ["a": 1, "b": 2] diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output new file mode 100644 index 000000000000..59afc51867a2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output @@ -0,0 +1,51 @@ +// TODO: same parser issue as the array subscript case above — +// `d["key"]` is parsed as `call_expression(d, ("key"))`. +let v = d["key"] + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "v" + value: + call_expression + function: simple_identifier "d" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + line_string_literal + text: line_str_text "key" + comment "// TODO: same parser issue as the array subscript case above —" + comment "// `d[\"key\"]` is parsed as `call_expression(d, (\"key\"))`." + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "v" + value: + call_expr + argument: + argument + value: string_literal "\"key\"" + callee: + name_expr + identifier: identifier "d" diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.swift b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.swift new file mode 100644 index 000000000000..a8ee09a980a9 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.swift @@ -0,0 +1,3 @@ +// TODO: same parser issue as the array subscript case above — +// `d["key"]` is parsed as `call_expression(d, ("key"))`. +let v = d["key"] diff --git a/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output new file mode 100644 index 000000000000..90d1a9dde368 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output @@ -0,0 +1,51 @@ +let xs: [Int] = [] + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "xs" + type: + type_annotation + type: + type + name: + array_type + element: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + value: + array_literal + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "xs" + type: + generic_type_expr + base: + named_type_expr + name: identifier "Array" + type_argument: + named_type_expr + name: identifier "Int" + value: array_literal "[]" diff --git a/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.swift b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.swift new file mode 100644 index 000000000000..4aa0a276f9cf --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.swift @@ -0,0 +1 @@ +let xs: [Int] = [] diff --git a/unified/extractor/tests/corpus/swift/collections/set-literal.output b/unified/extractor/tests/corpus/swift/collections/set-literal.output new file mode 100644 index 000000000000..a1a1dde75f9a --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/set-literal.output @@ -0,0 +1,60 @@ +let s: Set = [1, 2, 3] + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "s" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + arguments: + type_arguments + argument: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + name: type_identifier "Set" + value: + array_literal + element: + integer_literal "1" + integer_literal "2" + integer_literal "3" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "s" + type: + named_type_expr + name: identifier "Set" + value: + array_literal + element: + int_literal "1" + int_literal "2" + int_literal "3" diff --git a/unified/extractor/tests/corpus/swift/collections/set-literal.swift b/unified/extractor/tests/corpus/swift/collections/set-literal.swift new file mode 100644 index 000000000000..867d9dfb1c41 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/set-literal.swift @@ -0,0 +1 @@ +let s: Set = [1, 2, 3] diff --git a/unified/extractor/tests/corpus/swift/collections/subscript-access.output b/unified/extractor/tests/corpus/swift/collections/subscript-access.output new file mode 100644 index 000000000000..481a3e95f774 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/subscript-access.output @@ -0,0 +1,51 @@ +// TODO: tree-sitter-swift parses `xs[0]` as a call_expression (same shape +// as `xs(0)`), so the mapping currently produces a call_expr. Update the +// parser / add a separate subscript_expr node and remap when fixed. +let first = xs[0] + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "first" + value: + call_expression + function: simple_identifier "xs" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "0" + comment "// TODO: tree-sitter-swift parses `xs[0]` as a call_expression (same shape" + comment "// as `xs(0)`), so the mapping currently produces a call_expr. Update the" + comment "// parser / add a separate subscript_expr node and remap when fixed." + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "first" + value: + call_expr + argument: + argument + value: int_literal "0" + callee: + name_expr + identifier: identifier "xs" diff --git a/unified/extractor/tests/corpus/swift/collections/subscript-access.swift b/unified/extractor/tests/corpus/swift/collections/subscript-access.swift new file mode 100644 index 000000000000..00a85bda4336 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/subscript-access.swift @@ -0,0 +1,4 @@ +// TODO: tree-sitter-swift parses `xs[0]` as a call_expression (same shape +// as `xs(0)`), so the mapping currently produces a call_expr. Update the +// parser / add a separate subscript_expr node and remap when fixed. +let first = xs[0] diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-literal.output b/unified/extractor/tests/corpus/swift/collections/tuple-literal.output new file mode 100644 index 000000000000..a0ac8861674b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/tuple-literal.output @@ -0,0 +1,39 @@ +let t = (1, "two", 3.0) + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "t" + value: + tuple_expression + element: + tuple_expression_item + value: integer_literal "1" + tuple_expression_item + value: + line_string_literal + text: line_str_text "two" + tuple_expression_item + value: real_literal "3.0" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "t" + value: tuple_expr "(1, \"two\", 3.0)" diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-literal.swift b/unified/extractor/tests/corpus/swift/collections/tuple-literal.swift new file mode 100644 index 000000000000..d1aad0049c4d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/tuple-literal.swift @@ -0,0 +1 @@ +let t = (1, "two", 3.0) diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output new file mode 100644 index 000000000000..29b234f30e26 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output @@ -0,0 +1,39 @@ +let n = t.0 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "n" + value: + navigation_expression + suffix: + navigation_suffix + suffix: integer_literal "0" + target: simple_identifier "t" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "n" + value: + member_access_expr + base: + name_expr + identifier: identifier "t" + member: identifier "0" diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.swift b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.swift new file mode 100644 index 000000000000..cd2651fa80b8 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.swift @@ -0,0 +1 @@ +let n = t.0 diff --git a/unified/extractor/tests/corpus/swift/control-flow.txt b/unified/extractor/tests/corpus/swift/control-flow.txt deleted file mode 100644 index f7d59e8cfe40..000000000000 --- a/unified/extractor/tests/corpus/swift/control-flow.txt +++ /dev/null @@ -1,966 +0,0 @@ -=== -If statement -=== - -if x > 0 { - print(x) -} - ---- - -source_file - statement: - if_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "x" - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - ---- - -top_level - body: - block - stmt: - if_expr - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - then: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "x" - callee: - name_expr - identifier: identifier "print" - -=== -If-else -=== - -if x > 0 { - print(x) -} else { - print(-x) -} - ---- - -source_file - statement: - if_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "x" - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - else_branch: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - prefix_expression - operation: - - target: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - if_expr - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - else: - block - stmt: - call_expr - argument: - argument - value: - unary_expr - operand: - name_expr - identifier: identifier "x" - operator: prefix_operator "-" - callee: - name_expr - identifier: identifier "print" - then: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "x" - callee: - name_expr - identifier: identifier "print" - -=== -If-else-if chain -=== - -if x > 0 { - print(1) -} else if x < 0 { - print(2) -} else { - print(3) -} - ---- - -source_file - statement: - if_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "1" - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - else_branch: - if_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "2" - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: < - rhs: integer_literal "0" - else_branch: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "3" - ---- - -top_level - body: - block - stmt: - if_expr - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - else: - if_expr - condition: - binary_expr - operator: infix_operator "<" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - else: - block - stmt: - call_expr - argument: - argument - value: int_literal "3" - callee: - name_expr - identifier: identifier "print" - then: - block - stmt: - call_expr - argument: - argument - value: int_literal "2" - callee: - name_expr - identifier: identifier "print" - then: - block - stmt: - call_expr - argument: - argument - value: int_literal "1" - callee: - name_expr - identifier: identifier "print" - -=== -If-let optional binding -=== - -if let value = optional { - print(value) -} - ---- - -source_file - statement: - if_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "value" - condition: - if_condition - kind: - if_let_binding - pattern: - pattern - binding: - value_binding_pattern - mutability: let - bound_identifier: simple_identifier "value" - value: simple_identifier "optional" - ---- - -top_level - body: - block - stmt: - if_expr - condition: - pattern_guard_expr - pattern: - constructor_pattern - element: - pattern_element - pattern: - name_pattern - identifier: identifier "value" - constructor: - member_access_expr - base: - named_type_expr - name: identifier "Optional" - member: identifier "some" - value: - name_expr - identifier: identifier "optional" - then: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "value" - callee: - name_expr - identifier: identifier "print" - -=== -Guard let -=== - -guard let value = optional else { return } - ---- - -source_file - statement: - guard_statement - body: - block - statement: - control_transfer_statement - kind: return - condition: - if_condition - kind: - if_let_binding - pattern: - pattern - binding: - value_binding_pattern - mutability: let - bound_identifier: simple_identifier "value" - value: simple_identifier "optional" - ---- - -top_level - body: - block - stmt: - guard_if_stmt - condition: - pattern_guard_expr - pattern: - constructor_pattern - element: - pattern_element - pattern: - name_pattern - identifier: identifier "value" - constructor: - member_access_expr - base: - named_type_expr - name: identifier "Optional" - member: identifier "some" - value: - name_expr - identifier: identifier "optional" - else: - block - stmt: return_expr "return" - -=== -Ternary expression -=== - -let y = x > 0 ? 1 : -1 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "y" - value: - ternary_expression - condition: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - if_false: - prefix_expression - operation: - - target: integer_literal "1" - if_true: integer_literal "1" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "y" - value: - if_expr - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - else: - unary_expr - operand: int_literal "1" - operator: prefix_operator "-" - then: int_literal "1" - -=== -Switch statement -=== - -switch x { -case 1: - print("one") -case 2, 3: - print("two or three") -default: - print("other") -} - ---- - -source_file - statement: - switch_statement - entry: - switch_entry - pattern: - switch_pattern - pattern: - pattern - kind: integer_literal "1" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - line_string_literal - text: line_str_text "one" - switch_entry - pattern: - switch_pattern - pattern: - pattern - kind: integer_literal "2" - switch_pattern - pattern: - pattern - kind: integer_literal "3" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - line_string_literal - text: line_str_text "two or three" - switch_entry - default: default_keyword "default" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - line_string_literal - text: line_str_text "other" - expr: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - switch_expr - case: - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: string_literal "\"one\"" - callee: - name_expr - identifier: identifier "print" - pattern: - expr_equality_pattern - expr: int_literal "1" - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: string_literal "\"two or three\"" - callee: - name_expr - identifier: identifier "print" - pattern: - or_pattern - pattern: - expr_equality_pattern - expr: int_literal "2" - expr_equality_pattern - expr: int_literal "3" - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: string_literal "\"other\"" - callee: - name_expr - identifier: identifier "print" - value: - name_expr - identifier: identifier "x" - -=== -If-case-let with shadowing in condition value -=== - -if case let x = x + 10 { - print(x) -} - ---- - -source_file - statement: - if_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "x" - condition: - if_condition - kind: - if_let_binding - pattern: - pattern - kind: - binding_pattern - binding: - value_binding_pattern - mutability: let - pattern: - pattern - bound_identifier: simple_identifier "x" - value: - additive_expression - lhs: simple_identifier "x" - op: + - rhs: integer_literal "10" - ---- - -top_level - body: - block - stmt: - if_expr - condition: - pattern_guard_expr - pattern: - name_pattern - identifier: identifier "x" - value: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "x" - right: int_literal "10" - then: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "x" - callee: - name_expr - identifier: identifier "print" - -=== -Switch with binding pattern -=== - -switch shape { -case .circle(let r): - print(r) -case .square(let s): - print(s) -} - ---- - -source_file - statement: - switch_statement - entry: - switch_entry - pattern: - switch_pattern - pattern: - pattern - kind: - case_pattern - arguments: - tuple_pattern - item: - tuple_pattern_item - pattern: - pattern - kind: - binding_pattern - binding: - value_binding_pattern - mutability: let - pattern: - pattern - bound_identifier: simple_identifier "r" - dot: . - name: simple_identifier "circle" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "r" - switch_entry - pattern: - switch_pattern - pattern: - pattern - kind: - case_pattern - arguments: - tuple_pattern - item: - tuple_pattern_item - pattern: - pattern - kind: - binding_pattern - binding: - value_binding_pattern - mutability: let - pattern: - pattern - bound_identifier: simple_identifier "s" - dot: . - name: simple_identifier "square" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "s" - expr: simple_identifier "shape" - ---- - -top_level - body: - block - stmt: - switch_expr - case: - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "r" - callee: - name_expr - identifier: identifier "print" - pattern: - constructor_pattern - element: - pattern_element - pattern: - name_pattern - identifier: identifier "r" - constructor: - member_access_expr - base: inferred_type_expr "." - member: identifier "circle" - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "s" - callee: - name_expr - identifier: identifier "print" - pattern: - constructor_pattern - element: - pattern_element - pattern: - name_pattern - identifier: identifier "s" - constructor: - member_access_expr - base: inferred_type_expr "." - member: identifier "square" - value: - name_expr - identifier: identifier "shape" - -=== -Switch with labeled case pattern arguments -=== - -switch x { -case .implicit(isAcknowledged: false): - print("yes") -case .thread(threadRowId: _, let rowId): - print(rowId) -} - ---- - -source_file - statement: - switch_statement - entry: - switch_entry - pattern: - switch_pattern - pattern: - pattern - kind: - case_pattern - arguments: - tuple_pattern - item: - tuple_pattern_item - name: simple_identifier "isAcknowledged" - pattern: - pattern - kind: - boolean_literal - dot: . - name: simple_identifier "implicit" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - line_string_literal - text: line_str_text "yes" - switch_entry - pattern: - switch_pattern - pattern: - pattern - kind: - case_pattern - arguments: - tuple_pattern - item: - tuple_pattern_item - name: simple_identifier "threadRowId" - pattern: - pattern - kind: wildcard_pattern "_" - tuple_pattern_item - pattern: - pattern - kind: - binding_pattern - binding: - value_binding_pattern - mutability: let - pattern: - pattern - bound_identifier: simple_identifier "rowId" - dot: . - name: simple_identifier "thread" - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "rowId" - expr: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - switch_expr - case: - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: string_literal "\"yes\"" - callee: - name_expr - identifier: identifier "print" - pattern: - constructor_pattern - element: - pattern_element - key: identifier "isAcknowledged" - pattern: - expr_equality_pattern - expr: boolean_literal "false" - constructor: - member_access_expr - base: inferred_type_expr "." - member: identifier "implicit" - switch_case - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "rowId" - callee: - name_expr - identifier: identifier "print" - pattern: - constructor_pattern - element: - pattern_element - key: identifier "threadRowId" - pattern: ignore_pattern "_" - pattern_element - pattern: - name_pattern - identifier: identifier "rowId" - constructor: - member_access_expr - base: inferred_type_expr "." - member: identifier "thread" - value: - name_expr - identifier: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output new file mode 100644 index 000000000000..a21962341217 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output @@ -0,0 +1,52 @@ +guard let value = optional else { return } + +--- + +source_file + statement: + guard_statement + body: + block + statement: + control_transfer_statement + kind: return + condition: + if_condition + kind: + if_let_binding + pattern: + pattern + binding: + value_binding_pattern + mutability: let + bound_identifier: simple_identifier "value" + value: simple_identifier "optional" + +--- + +top_level + body: + block + stmt: + guard_if_stmt + condition: + pattern_guard_expr + pattern: + constructor_pattern + element: + pattern_element + pattern: + name_pattern + identifier: identifier "value" + constructor: + member_access_expr + base: + named_type_expr + name: identifier "Optional" + member: identifier "some" + value: + name_expr + identifier: identifier "optional" + else: + block + stmt: return_expr "return" diff --git a/unified/extractor/tests/corpus/swift/control-flow/guard-let.swift b/unified/extractor/tests/corpus/swift/control-flow/guard-let.swift new file mode 100644 index 000000000000..d5aad119b286 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/guard-let.swift @@ -0,0 +1 @@ +guard let value = optional else { return } diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output new file mode 100644 index 000000000000..6a53c87d21a2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output @@ -0,0 +1,72 @@ +if case let x = x + 10 { + print(x) +} + +--- + +source_file + statement: + if_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "x" + condition: + if_condition + kind: + if_let_binding + pattern: + pattern + kind: + binding_pattern + binding: + value_binding_pattern + mutability: let + pattern: + pattern + bound_identifier: simple_identifier "x" + value: + additive_expression + lhs: simple_identifier "x" + op: + + rhs: integer_literal "10" + +--- + +top_level + body: + block + stmt: + if_expr + condition: + pattern_guard_expr + pattern: + name_pattern + identifier: identifier "x" + value: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "x" + right: int_literal "10" + then: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "x" + callee: + name_expr + identifier: identifier "print" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift new file mode 100644 index 000000000000..c57c8ae5b67c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift @@ -0,0 +1,3 @@ +if case let x = x + 10 { + print(x) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output b/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output new file mode 100644 index 000000000000..e8f413726466 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output @@ -0,0 +1,119 @@ +if x > 0 { + print(1) +} else if x < 0 { + print(2) +} else { + print(3) +} + +--- + +source_file + statement: + if_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "1" + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + else_branch: + if_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "2" + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: < + rhs: integer_literal "0" + else_branch: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "3" + +--- + +top_level + body: + block + stmt: + if_expr + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + else: + if_expr + condition: + binary_expr + operator: infix_operator "<" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + else: + block + stmt: + call_expr + argument: + argument + value: int_literal "3" + callee: + name_expr + identifier: identifier "print" + then: + block + stmt: + call_expr + argument: + argument + value: int_literal "2" + callee: + name_expr + identifier: identifier "print" + then: + block + stmt: + call_expr + argument: + argument + value: int_literal "1" + callee: + name_expr + identifier: identifier "print" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.swift b/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.swift new file mode 100644 index 000000000000..f0a7feeeabc2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.swift @@ -0,0 +1,7 @@ +if x > 0 { + print(1) +} else if x < 0 { + print(2) +} else { + print(3) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-else.output b/unified/extractor/tests/corpus/swift/control-flow/if-else.output new file mode 100644 index 000000000000..469861214676 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-else.output @@ -0,0 +1,87 @@ +if x > 0 { + print(x) +} else { + print(-x) +} + +--- + +source_file + statement: + if_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "x" + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + else_branch: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + prefix_expression + operation: - + target: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + if_expr + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + else: + block + stmt: + call_expr + argument: + argument + value: + unary_expr + operand: + name_expr + identifier: identifier "x" + operator: prefix_operator "-" + callee: + name_expr + identifier: identifier "print" + then: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "x" + callee: + name_expr + identifier: identifier "print" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-else.swift b/unified/extractor/tests/corpus/swift/control-flow/if-else.swift new file mode 100644 index 000000000000..2060ecb8cf62 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-else.swift @@ -0,0 +1,5 @@ +if x > 0 { + print(x) +} else { + print(-x) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output new file mode 100644 index 000000000000..f6b605a7461c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output @@ -0,0 +1,70 @@ +if let value = optional { + print(value) +} + +--- + +source_file + statement: + if_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "value" + condition: + if_condition + kind: + if_let_binding + pattern: + pattern + binding: + value_binding_pattern + mutability: let + bound_identifier: simple_identifier "value" + value: simple_identifier "optional" + +--- + +top_level + body: + block + stmt: + if_expr + condition: + pattern_guard_expr + pattern: + constructor_pattern + element: + pattern_element + pattern: + name_pattern + identifier: identifier "value" + constructor: + member_access_expr + base: + named_type_expr + name: identifier "Optional" + member: identifier "some" + value: + name_expr + identifier: identifier "optional" + then: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "value" + callee: + name_expr + identifier: identifier "print" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.swift b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.swift new file mode 100644 index 000000000000..74af660c7f3f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.swift @@ -0,0 +1,3 @@ +if let value = optional { + print(value) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-statement.output b/unified/extractor/tests/corpus/swift/control-flow/if-statement.output new file mode 100644 index 000000000000..2c29ab1dc69b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-statement.output @@ -0,0 +1,55 @@ +if x > 0 { + print(x) +} + +--- + +source_file + statement: + if_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "x" + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + +--- + +top_level + body: + block + stmt: + if_expr + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + then: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "x" + callee: + name_expr + identifier: identifier "print" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-statement.swift b/unified/extractor/tests/corpus/swift/control-flow/if-statement.swift new file mode 100644 index 000000000000..5046074db140 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/if-statement.swift @@ -0,0 +1,3 @@ +if x > 0 { + print(x) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output new file mode 100644 index 000000000000..bb90cb60fc5b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output @@ -0,0 +1,125 @@ +switch x { +case 1: + print("one") +case 2, 3: + print("two or three") +default: + print("other") +} + +--- + +source_file + statement: + switch_statement + entry: + switch_entry + pattern: + switch_pattern + pattern: + pattern + kind: integer_literal "1" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + line_string_literal + text: line_str_text "one" + switch_entry + pattern: + switch_pattern + pattern: + pattern + kind: integer_literal "2" + switch_pattern + pattern: + pattern + kind: integer_literal "3" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + line_string_literal + text: line_str_text "two or three" + switch_entry + default: default_keyword "default" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + line_string_literal + text: line_str_text "other" + expr: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + switch_expr + case: + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: string_literal "\"one\"" + callee: + name_expr + identifier: identifier "print" + pattern: + expr_equality_pattern + expr: int_literal "1" + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: string_literal "\"two or three\"" + callee: + name_expr + identifier: identifier "print" + pattern: + or_pattern + pattern: + expr_equality_pattern + expr: int_literal "2" + expr_equality_pattern + expr: int_literal "3" + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: string_literal "\"other\"" + callee: + name_expr + identifier: identifier "print" + value: + name_expr + identifier: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-statement.swift b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.swift new file mode 100644 index 000000000000..f8d62c5e7885 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.swift @@ -0,0 +1,8 @@ +switch x { +case 1: + print("one") +case 2, 3: + print("two or three") +default: + print("other") +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output new file mode 100644 index 000000000000..4d98620fe8f4 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output @@ -0,0 +1,140 @@ +switch shape { +case .circle(let r): + print(r) +case .square(let s): + print(s) +} + +--- + +source_file + statement: + switch_statement + entry: + switch_entry + pattern: + switch_pattern + pattern: + pattern + kind: + case_pattern + arguments: + tuple_pattern + item: + tuple_pattern_item + pattern: + pattern + kind: + binding_pattern + binding: + value_binding_pattern + mutability: let + pattern: + pattern + bound_identifier: simple_identifier "r" + dot: . + name: simple_identifier "circle" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "r" + switch_entry + pattern: + switch_pattern + pattern: + pattern + kind: + case_pattern + arguments: + tuple_pattern + item: + tuple_pattern_item + pattern: + pattern + kind: + binding_pattern + binding: + value_binding_pattern + mutability: let + pattern: + pattern + bound_identifier: simple_identifier "s" + dot: . + name: simple_identifier "square" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "s" + expr: simple_identifier "shape" + +--- + +top_level + body: + block + stmt: + switch_expr + case: + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "r" + callee: + name_expr + identifier: identifier "print" + pattern: + constructor_pattern + element: + pattern_element + pattern: + name_pattern + identifier: identifier "r" + constructor: + member_access_expr + base: inferred_type_expr "." + member: identifier "circle" + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "s" + callee: + name_expr + identifier: identifier "print" + pattern: + constructor_pattern + element: + pattern_element + pattern: + name_pattern + identifier: identifier "s" + constructor: + member_access_expr + base: inferred_type_expr "." + member: identifier "square" + value: + name_expr + identifier: identifier "shape" diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.swift b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.swift new file mode 100644 index 000000000000..e57a4e4ad061 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.swift @@ -0,0 +1,6 @@ +switch shape { +case .circle(let r): + print(r) +case .square(let s): + print(s) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output new file mode 100644 index 000000000000..aef36c168558 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output @@ -0,0 +1,144 @@ +switch x { +case .implicit(isAcknowledged: false): + print("yes") +case .thread(threadRowId: _, let rowId): + print(rowId) +} + +--- + +source_file + statement: + switch_statement + entry: + switch_entry + pattern: + switch_pattern + pattern: + pattern + kind: + case_pattern + arguments: + tuple_pattern + item: + tuple_pattern_item + name: simple_identifier "isAcknowledged" + pattern: + pattern + kind: + boolean_literal + dot: . + name: simple_identifier "implicit" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + line_string_literal + text: line_str_text "yes" + switch_entry + pattern: + switch_pattern + pattern: + pattern + kind: + case_pattern + arguments: + tuple_pattern + item: + tuple_pattern_item + name: simple_identifier "threadRowId" + pattern: + pattern + kind: wildcard_pattern "_" + tuple_pattern_item + pattern: + pattern + kind: + binding_pattern + binding: + value_binding_pattern + mutability: let + pattern: + pattern + bound_identifier: simple_identifier "rowId" + dot: . + name: simple_identifier "thread" + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "rowId" + expr: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + switch_expr + case: + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: string_literal "\"yes\"" + callee: + name_expr + identifier: identifier "print" + pattern: + constructor_pattern + element: + pattern_element + key: identifier "isAcknowledged" + pattern: + expr_equality_pattern + expr: boolean_literal "false" + constructor: + member_access_expr + base: inferred_type_expr "." + member: identifier "implicit" + switch_case + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "rowId" + callee: + name_expr + identifier: identifier "print" + pattern: + constructor_pattern + element: + pattern_element + key: identifier "threadRowId" + pattern: ignore_pattern "_" + pattern_element + pattern: + name_pattern + identifier: identifier "rowId" + constructor: + member_access_expr + base: inferred_type_expr "." + member: identifier "thread" + value: + name_expr + identifier: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.swift b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.swift new file mode 100644 index 000000000000..4a7bd6bd9ca5 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.swift @@ -0,0 +1,6 @@ +switch x { +case .implicit(isAcknowledged: false): + print("yes") +case .thread(threadRowId: _, let rowId): + print(rowId) +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output new file mode 100644 index 000000000000..7f9da80d34ac --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output @@ -0,0 +1,53 @@ +let y = x > 0 ? 1 : -1 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "y" + value: + ternary_expression + condition: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + if_false: + prefix_expression + operation: - + target: integer_literal "1" + if_true: integer_literal "1" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "y" + value: + if_expr + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + else: + unary_expr + operand: int_literal "1" + operator: prefix_operator "-" + then: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.swift b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.swift new file mode 100644 index 000000000000..9284457311df --- /dev/null +++ b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.swift @@ -0,0 +1 @@ +let y = x > 0 ? 1 : -1 diff --git a/unified/extractor/tests/corpus/swift/desugar.txt b/unified/extractor/tests/corpus/swift/desugar.txt deleted file mode 100644 index 1611943bf1ae..000000000000 --- a/unified/extractor/tests/corpus/swift/desugar.txt +++ /dev/null @@ -1,186 +0,0 @@ -=== -Additive expression is desugared -=== - -1 + 2 - ---- - -source_file - statement: - additive_expression - lhs: integer_literal "1" - op: + - rhs: integer_literal "2" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "+" - left: int_literal "1" - right: int_literal "2" - -=== -Another additive expression is desugared -=== - -foo + bar - ---- - -source_file - statement: - additive_expression - lhs: simple_identifier "foo" - op: + - rhs: simple_identifier "bar" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "foo" - right: - name_expr - identifier: identifier "bar" - -=== -Simple import with single name -=== - -import Foundation - ---- - -source_file - statement: - import_declaration - name: - identifier - part: simple_identifier "Foundation" - ---- - -top_level - body: - block - stmt: - import_declaration - pattern: bulk_importing_pattern "import Foundation" - imported_expr: - name_expr - identifier: identifier "Foundation" - -=== -Import with dotted path (two parts) -=== - -import Foundation.Networking - ---- - -source_file - statement: - import_declaration - name: - identifier - part: - simple_identifier "Foundation" - simple_identifier "Networking" - ---- - -top_level - body: - block - stmt: - import_declaration - pattern: bulk_importing_pattern "import Foundation.Networking" - imported_expr: - member_access_expr - base: - name_expr - identifier: identifier "Foundation" - member: identifier "Networking" - -=== -Import with deeply nested path (three parts) -=== - -import Foundation.Networking.URLSession - ---- - -source_file - statement: - import_declaration - name: - identifier - part: - simple_identifier "Foundation" - simple_identifier "Networking" - simple_identifier "URLSession" - ---- - -top_level - body: - block - stmt: - import_declaration - pattern: bulk_importing_pattern "import Foundation.Networking.URLSession" - imported_expr: - member_access_expr - base: - member_access_expr - base: - name_expr - identifier: identifier "Foundation" - member: identifier "Networking" - member: identifier "URLSession" - -=== -Scoped import uses name_pattern -=== - -import struct Foundation.Date - ---- - -source_file - statement: - import_declaration - name: - identifier - part: - simple_identifier "Foundation" - simple_identifier "Date" - scoped_import_kind: struct - ---- - -top_level - body: - block - stmt: - import_declaration - modifier: modifier "struct" - pattern: - name_pattern - identifier: identifier "Date" - imported_expr: - member_access_expr - base: - name_expr - identifier: identifier "Foundation" - member: identifier "Date" diff --git a/unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.output b/unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.output new file mode 100644 index 000000000000..07aa40618bd1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.output @@ -0,0 +1,21 @@ +1 + 2 + +--- + +source_file + statement: + additive_expression + lhs: integer_literal "1" + op: + + rhs: integer_literal "2" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "+" + left: int_literal "1" + right: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.swift b/unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.swift new file mode 100644 index 000000000000..e0ef5840209c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/additive-expression-is-desugared.swift @@ -0,0 +1 @@ +1 + 2 diff --git a/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output b/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output new file mode 100644 index 000000000000..ff830fd4b894 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output @@ -0,0 +1,25 @@ +foo + bar + +--- + +source_file + statement: + additive_expression + lhs: simple_identifier "foo" + op: + + rhs: simple_identifier "bar" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "foo" + right: + name_expr + identifier: identifier "bar" diff --git a/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.swift b/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.swift new file mode 100644 index 000000000000..40750801b0d0 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.swift @@ -0,0 +1 @@ +foo + bar diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output new file mode 100644 index 000000000000..4f312dabb151 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output @@ -0,0 +1,31 @@ +import Foundation.Networking.URLSession + +--- + +source_file + statement: + import_declaration + name: + identifier + part: + simple_identifier "Foundation" + simple_identifier "Networking" + simple_identifier "URLSession" + +--- + +top_level + body: + block + stmt: + import_declaration + pattern: bulk_importing_pattern "import Foundation.Networking.URLSession" + imported_expr: + member_access_expr + base: + member_access_expr + base: + name_expr + identifier: identifier "Foundation" + member: identifier "Networking" + member: identifier "URLSession" diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.swift b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.swift new file mode 100644 index 000000000000..031ca336c03b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.swift @@ -0,0 +1 @@ +import Foundation.Networking.URLSession diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output new file mode 100644 index 000000000000..efd2a6461243 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output @@ -0,0 +1,27 @@ +import Foundation.Networking + +--- + +source_file + statement: + import_declaration + name: + identifier + part: + simple_identifier "Foundation" + simple_identifier "Networking" + +--- + +top_level + body: + block + stmt: + import_declaration + pattern: bulk_importing_pattern "import Foundation.Networking" + imported_expr: + member_access_expr + base: + name_expr + identifier: identifier "Foundation" + member: identifier "Networking" diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.swift b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.swift new file mode 100644 index 000000000000..0b2c36fa11ae --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.swift @@ -0,0 +1 @@ +import Foundation.Networking diff --git a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output new file mode 100644 index 000000000000..fbf8e8100af7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output @@ -0,0 +1,31 @@ +import struct Foundation.Date + +--- + +source_file + statement: + import_declaration + name: + identifier + part: + simple_identifier "Foundation" + simple_identifier "Date" + scoped_import_kind: struct + +--- + +top_level + body: + block + stmt: + import_declaration + modifier: modifier "struct" + pattern: + name_pattern + identifier: identifier "Date" + imported_expr: + member_access_expr + base: + name_expr + identifier: identifier "Foundation" + member: identifier "Date" diff --git a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.swift b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.swift new file mode 100644 index 000000000000..450a79254188 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.swift @@ -0,0 +1 @@ +import struct Foundation.Date diff --git a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output new file mode 100644 index 000000000000..7a6be1c35e4c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output @@ -0,0 +1,22 @@ +import Foundation + +--- + +source_file + statement: + import_declaration + name: + identifier + part: simple_identifier "Foundation" + +--- + +top_level + body: + block + stmt: + import_declaration + pattern: bulk_importing_pattern "import Foundation" + imported_expr: + name_expr + identifier: identifier "Foundation" diff --git a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.swift b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.swift new file mode 100644 index 000000000000..fecc4ab44999 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.swift @@ -0,0 +1 @@ +import Foundation diff --git a/unified/extractor/tests/corpus/swift/functions.txt b/unified/extractor/tests/corpus/swift/functions.txt deleted file mode 100644 index ed86618910c8..000000000000 --- a/unified/extractor/tests/corpus/swift/functions.txt +++ /dev/null @@ -1,657 +0,0 @@ -=== -Function with no parameters -=== - -func greet() { - print("hello") -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: - line_string_literal - text: line_str_text "hello" - name: simple_identifier "greet" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - call_expr - argument: - argument - value: string_literal "\"hello\"" - callee: - name_expr - identifier: identifier "print" - name: identifier "greet" - -=== -Function with parameters and return type -=== - -func add(_ a: Int, _ b: Int) -> Int { - return a + b -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - control_transfer_statement - kind: return - result: - additive_expression - lhs: simple_identifier "a" - op: + - rhs: simple_identifier "b" - name: simple_identifier "add" - parameter: - function_parameter - parameter: - parameter - external_name: simple_identifier "_" - name: simple_identifier "a" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - function_parameter - parameter: - parameter - external_name: simple_identifier "_" - name: simple_identifier "b" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - return_expr - value: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - name: identifier "add" - parameter: - parameter - external_name: identifier "_" - pattern: - name_pattern - identifier: identifier "a" - parameter - external_name: identifier "_" - pattern: - name_pattern - identifier: identifier "b" - return_type: - named_type_expr - name: identifier "Int" - -=== -Function with named parameters -=== - -func greet(person name: String) { - print(name) -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "name" - name: simple_identifier "greet" - parameter: - function_parameter - parameter: - parameter - external_name: simple_identifier "person" - name: simple_identifier "name" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "String" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "name" - callee: - name_expr - identifier: identifier "print" - name: identifier "greet" - parameter: - parameter - external_name: identifier "person" - pattern: - name_pattern - identifier: identifier "name" - -=== -Function with default parameter value -=== - -func greet(name: String = "world") { - print(name) -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "name" - name: simple_identifier "greet" - parameter: - function_parameter - default_value: - line_string_literal - text: line_str_text "world" - parameter: - parameter - name: simple_identifier "name" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "String" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "name" - callee: - name_expr - identifier: identifier "print" - name: identifier "greet" - parameter: - parameter - default: string_literal "\"world\"" - pattern: - name_pattern - identifier: identifier "name" - -=== -Variadic function -=== - -func sum(_ values: Int...) -> Int { - return values.reduce(0, +) -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - control_transfer_statement - kind: return - result: - call_expression - function: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "reduce" - target: simple_identifier "values" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "0" - value_argument - value: - referenceable_operator - operator: + - name: simple_identifier "sum" - parameter: - function_parameter - parameter: - parameter - external_name: simple_identifier "_" - name: simple_identifier "values" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - return_expr - value: - call_expr - argument: - argument - value: int_literal "0" - argument - value: - name_expr - identifier: identifier "+" - callee: - member_access_expr - base: - name_expr - identifier: identifier "values" - member: identifier "reduce" - name: identifier "sum" - parameter: - parameter - external_name: identifier "_" - pattern: - name_pattern - identifier: identifier "values" - return_type: - named_type_expr - name: identifier "Int" - -=== -Function call -=== - -foo(1, 2) - ---- - -source_file - statement: - call_expression - function: simple_identifier "foo" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "1" - value_argument - value: integer_literal "2" - ---- - -top_level - body: - block - stmt: - call_expr - argument: - argument - value: int_literal "1" - argument - value: int_literal "2" - callee: - name_expr - identifier: identifier "foo" - -=== -Function call with labelled arguments -=== - -greet(person: "Bob") - ---- - -source_file - statement: - call_expression - function: simple_identifier "greet" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - name: - value_argument_label - name: simple_identifier "person" - value: - line_string_literal - text: line_str_text "Bob" - ---- - -top_level - body: - block - stmt: - call_expr - argument: - argument - name: identifier "person" - value: string_literal "\"Bob\"" - callee: - name_expr - identifier: identifier "greet" - -=== -Method call -=== - -list.append(1) - ---- - -source_file - statement: - call_expression - function: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "append" - target: simple_identifier "list" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "1" - ---- - -top_level - body: - block - stmt: - call_expr - argument: - argument - value: int_literal "1" - callee: - member_access_expr - base: - name_expr - identifier: identifier "list" - member: identifier "append" - -=== -Generic function -=== - -func identity(_ x: T) -> T { - return x -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - control_transfer_statement - kind: return - result: simple_identifier "x" - name: simple_identifier "identity" - parameter: - function_parameter - parameter: - parameter - external_name: simple_identifier "_" - name: simple_identifier "x" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "T" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "T" - type_parameters: - type_parameters - parameter: - type_parameter - name: type_identifier "T" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - return_expr - value: - name_expr - identifier: identifier "x" - name: identifier "identity" - parameter: - parameter - external_name: identifier "_" - pattern: - name_pattern - identifier: identifier "x" - return_type: - named_type_expr - name: identifier "T" - -=== -Leading-dot expression value -=== - -let x = .foo - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - value: - prefix_expression - operation: . - target: simple_identifier "foo" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "x" - value: - member_access_expr - base: inferred_type_expr ".foo" - member: identifier "foo" - -=== -Leading-dot expression call -=== - -let y = .some(1) - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "y" - value: - call_expression - function: - prefix_expression - operation: . - target: simple_identifier "some" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: integer_literal "1" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "y" - value: - call_expr - argument: - argument - value: int_literal "1" - callee: - member_access_expr - base: inferred_type_expr ".some" - member: identifier "some" diff --git a/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output new file mode 100644 index 000000000000..ba0c002a4527 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output @@ -0,0 +1,35 @@ +greet(person: "Bob") + +--- + +source_file + statement: + call_expression + function: simple_identifier "greet" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + name: + value_argument_label + name: simple_identifier "person" + value: + line_string_literal + text: line_str_text "Bob" + +--- + +top_level + body: + block + stmt: + call_expr + argument: + argument + name: identifier "person" + value: string_literal "\"Bob\"" + callee: + name_expr + identifier: identifier "greet" diff --git a/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.swift b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.swift new file mode 100644 index 000000000000..10ae64e57c1b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.swift @@ -0,0 +1 @@ +greet(person: "Bob") diff --git a/unified/extractor/tests/corpus/swift/functions/function-call.output b/unified/extractor/tests/corpus/swift/functions/function-call.output new file mode 100644 index 000000000000..ed604730d33c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-call.output @@ -0,0 +1,33 @@ +foo(1, 2) + +--- + +source_file + statement: + call_expression + function: simple_identifier "foo" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "1" + value_argument + value: integer_literal "2" + +--- + +top_level + body: + block + stmt: + call_expr + argument: + argument + value: int_literal "1" + argument + value: int_literal "2" + callee: + name_expr + identifier: identifier "foo" diff --git a/unified/extractor/tests/corpus/swift/functions/function-call.swift b/unified/extractor/tests/corpus/swift/functions/function-call.swift new file mode 100644 index 000000000000..22594bf8c7da --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-call.swift @@ -0,0 +1 @@ +foo(1, 2) diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output new file mode 100644 index 000000000000..fdd737e1258d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output @@ -0,0 +1,64 @@ +func greet(name: String = "world") { + print(name) +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "name" + name: simple_identifier "greet" + parameter: + function_parameter + default_value: + line_string_literal + text: line_str_text "world" + parameter: + parameter + name: simple_identifier "name" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "String" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "name" + callee: + name_expr + identifier: identifier "print" + name: identifier "greet" + parameter: + parameter + default: string_literal "\"world\"" + pattern: + name_pattern + identifier: identifier "name" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.swift b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.swift new file mode 100644 index 000000000000..892d1b7bbfeb --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.swift @@ -0,0 +1,3 @@ +func greet(name: String = "world") { + print(name) +} diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output new file mode 100644 index 000000000000..bfa68c645ea1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output @@ -0,0 +1,62 @@ +func greet(person name: String) { + print(name) +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "name" + name: simple_identifier "greet" + parameter: + function_parameter + parameter: + parameter + external_name: simple_identifier "person" + name: simple_identifier "name" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "String" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "name" + callee: + name_expr + identifier: identifier "print" + name: identifier "greet" + parameter: + parameter + external_name: identifier "person" + pattern: + name_pattern + identifier: identifier "name" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.swift b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.swift new file mode 100644 index 000000000000..0b18f19768c1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.swift @@ -0,0 +1,3 @@ +func greet(person name: String) { + print(name) +} diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output new file mode 100644 index 000000000000..b5cdfd73d48f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output @@ -0,0 +1,43 @@ +func greet() { + print("hello") +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: + line_string_literal + text: line_str_text "hello" + name: simple_identifier "greet" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + call_expr + argument: + argument + value: string_literal "\"hello\"" + callee: + name_expr + identifier: identifier "print" + name: identifier "greet" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.swift b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.swift new file mode 100644 index 000000000000..3f690449977f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.swift @@ -0,0 +1,3 @@ +func greet() { + print("hello") +} diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output new file mode 100644 index 000000000000..6544f4313cd7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output @@ -0,0 +1,88 @@ +func add(_ a: Int, _ b: Int) -> Int { + return a + b +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + control_transfer_statement + kind: return + result: + additive_expression + lhs: simple_identifier "a" + op: + + rhs: simple_identifier "b" + name: simple_identifier "add" + parameter: + function_parameter + parameter: + parameter + external_name: simple_identifier "_" + name: simple_identifier "a" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + function_parameter + parameter: + parameter + external_name: simple_identifier "_" + name: simple_identifier "b" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + return_expr + value: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" + name: identifier "add" + parameter: + parameter + external_name: identifier "_" + pattern: + name_pattern + identifier: identifier "a" + parameter + external_name: identifier "_" + pattern: + name_pattern + identifier: identifier "b" + return_type: + named_type_expr + name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.swift b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.swift new file mode 100644 index 000000000000..d87ad5c9b0d8 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.swift @@ -0,0 +1,3 @@ +func add(_ a: Int, _ b: Int) -> Int { + return a + b +} diff --git a/unified/extractor/tests/corpus/swift/functions/generic-function.output b/unified/extractor/tests/corpus/swift/functions/generic-function.output new file mode 100644 index 000000000000..f42367a8fca2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/generic-function.output @@ -0,0 +1,66 @@ +func identity(_ x: T) -> T { + return x +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + control_transfer_statement + kind: return + result: simple_identifier "x" + name: simple_identifier "identity" + parameter: + function_parameter + parameter: + parameter + external_name: simple_identifier "_" + name: simple_identifier "x" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "T" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "T" + type_parameters: + type_parameters + parameter: + type_parameter + name: type_identifier "T" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + return_expr + value: + name_expr + identifier: identifier "x" + name: identifier "identity" + parameter: + parameter + external_name: identifier "_" + pattern: + name_pattern + identifier: identifier "x" + return_type: + named_type_expr + name: identifier "T" diff --git a/unified/extractor/tests/corpus/swift/functions/generic-function.swift b/unified/extractor/tests/corpus/swift/functions/generic-function.swift new file mode 100644 index 000000000000..7a3180392a7a --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/generic-function.swift @@ -0,0 +1,3 @@ +func identity(_ x: T) -> T { + return x +} diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output new file mode 100644 index 000000000000..8db16da8ab8b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output @@ -0,0 +1,49 @@ +let y = .some(1) + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "y" + value: + call_expression + function: + prefix_expression + operation: . + target: simple_identifier "some" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "1" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "y" + value: + call_expr + argument: + argument + value: int_literal "1" + callee: + member_access_expr + base: inferred_type_expr ".some" + member: identifier "some" diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.swift b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.swift new file mode 100644 index 000000000000..13a878c7cbbd --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.swift @@ -0,0 +1 @@ +let y = .some(1) diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output new file mode 100644 index 000000000000..85aeeffde6eb --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output @@ -0,0 +1,35 @@ +let x = .foo + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + value: + prefix_expression + operation: . + target: simple_identifier "foo" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "x" + value: + member_access_expr + base: inferred_type_expr ".foo" + member: identifier "foo" diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.swift b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.swift new file mode 100644 index 000000000000..3c7f897a0d84 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.swift @@ -0,0 +1 @@ +let x = .foo diff --git a/unified/extractor/tests/corpus/swift/functions/method-call.output b/unified/extractor/tests/corpus/swift/functions/method-call.output new file mode 100644 index 000000000000..5a8a23f5658a --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/method-call.output @@ -0,0 +1,37 @@ +list.append(1) + +--- + +source_file + statement: + call_expression + function: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "append" + target: simple_identifier "list" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "1" + +--- + +top_level + body: + block + stmt: + call_expr + argument: + argument + value: int_literal "1" + callee: + member_access_expr + base: + name_expr + identifier: identifier "list" + member: identifier "append" diff --git a/unified/extractor/tests/corpus/swift/functions/method-call.swift b/unified/extractor/tests/corpus/swift/functions/method-call.swift new file mode 100644 index 000000000000..4c6b77a1ea76 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/method-call.swift @@ -0,0 +1 @@ +list.append(1) diff --git a/unified/extractor/tests/corpus/swift/functions/variadic-function.output b/unified/extractor/tests/corpus/swift/functions/variadic-function.output new file mode 100644 index 000000000000..7ca1dfbad4eb --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/variadic-function.output @@ -0,0 +1,91 @@ +func sum(_ values: Int...) -> Int { + return values.reduce(0, +) +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + control_transfer_statement + kind: return + result: + call_expression + function: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "reduce" + target: simple_identifier "values" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: integer_literal "0" + value_argument + value: + referenceable_operator + operator: + + name: simple_identifier "sum" + parameter: + function_parameter + parameter: + parameter + external_name: simple_identifier "_" + name: simple_identifier "values" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + return_expr + value: + call_expr + argument: + argument + value: int_literal "0" + argument + value: + name_expr + identifier: identifier "+" + callee: + member_access_expr + base: + name_expr + identifier: identifier "values" + member: identifier "reduce" + name: identifier "sum" + parameter: + parameter + external_name: identifier "_" + pattern: + name_pattern + identifier: identifier "values" + return_type: + named_type_expr + name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/functions/variadic-function.swift b/unified/extractor/tests/corpus/swift/functions/variadic-function.swift new file mode 100644 index 000000000000..98d4f00e3aa3 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/functions/variadic-function.swift @@ -0,0 +1,3 @@ +func sum(_ values: Int...) -> Int { + return values.reduce(0, +) +} diff --git a/unified/extractor/tests/corpus/swift/literals.txt b/unified/extractor/tests/corpus/swift/literals.txt deleted file mode 100644 index bf0e4aae5609..000000000000 --- a/unified/extractor/tests/corpus/swift/literals.txt +++ /dev/null @@ -1,143 +0,0 @@ -=== -Integer literal -=== - -42 - ---- - -source_file - statement: integer_literal "42" - ---- - -top_level - body: - block - stmt: int_literal "42" - -=== -Negative integer literal -=== - --7 - ---- - -source_file - statement: - prefix_expression - operation: - - target: integer_literal "7" - ---- - -top_level - body: - block - stmt: - unary_expr - operand: int_literal "7" - operator: prefix_operator "-" - -=== -Floating-point literal -=== - -3.14 - ---- - -source_file - statement: real_literal "3.14" - ---- - -top_level - body: - block - stmt: float_literal "3.14" - -=== -Boolean literals -=== - -true -false - ---- - -source_file - statement: - boolean_literal - boolean_literal - ---- - -top_level - body: - block - stmt: - boolean_literal "true" - boolean_literal "false" - -=== -Nil literal -=== - -nil - ---- - -source_file - statement: nil - ---- - -top_level - body: - block - stmt: builtin_expr "nil" - -=== -String literal -=== - -"hello" - ---- - -source_file - statement: - line_string_literal - text: line_str_text "hello" - ---- - -top_level - body: - block - stmt: string_literal "\"hello\"" - -=== -String with interpolation -=== - -"hello \(name)" - ---- - -source_file - statement: - line_string_literal - interpolation: - interpolated_expression - value: simple_identifier "name" - text: line_str_text "hello " - ---- - -top_level - body: - block - stmt: string_literal "\"hello \\(name)\"" diff --git a/unified/extractor/tests/corpus/swift/literals/boolean-literals.output b/unified/extractor/tests/corpus/swift/literals/boolean-literals.output new file mode 100644 index 000000000000..d31893de0522 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/boolean-literals.output @@ -0,0 +1,18 @@ +true +false + +--- + +source_file + statement: + boolean_literal + boolean_literal + +--- + +top_level + body: + block + stmt: + boolean_literal "true" + boolean_literal "false" diff --git a/unified/extractor/tests/corpus/swift/literals/boolean-literals.swift b/unified/extractor/tests/corpus/swift/literals/boolean-literals.swift new file mode 100644 index 000000000000..da29283aaa47 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/boolean-literals.swift @@ -0,0 +1,2 @@ +true +false diff --git a/unified/extractor/tests/corpus/swift/literals/floating-point-literal.output b/unified/extractor/tests/corpus/swift/literals/floating-point-literal.output new file mode 100644 index 000000000000..0c374dc4452c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/floating-point-literal.output @@ -0,0 +1,13 @@ +3.14 + +--- + +source_file + statement: real_literal "3.14" + +--- + +top_level + body: + block + stmt: float_literal "3.14" diff --git a/unified/extractor/tests/corpus/swift/literals/floating-point-literal.swift b/unified/extractor/tests/corpus/swift/literals/floating-point-literal.swift new file mode 100644 index 000000000000..6324d401a069 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/floating-point-literal.swift @@ -0,0 +1 @@ +3.14 diff --git a/unified/extractor/tests/corpus/swift/literals/integer-literal.output b/unified/extractor/tests/corpus/swift/literals/integer-literal.output new file mode 100644 index 000000000000..018c57983948 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/integer-literal.output @@ -0,0 +1,13 @@ +42 + +--- + +source_file + statement: integer_literal "42" + +--- + +top_level + body: + block + stmt: int_literal "42" diff --git a/unified/extractor/tests/corpus/swift/literals/integer-literal.swift b/unified/extractor/tests/corpus/swift/literals/integer-literal.swift new file mode 100644 index 000000000000..d81cc0710eb6 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/integer-literal.swift @@ -0,0 +1 @@ +42 diff --git a/unified/extractor/tests/corpus/swift/literals/negative-integer-literal.output b/unified/extractor/tests/corpus/swift/literals/negative-integer-literal.output new file mode 100644 index 000000000000..e1ca11e070ab --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/negative-integer-literal.output @@ -0,0 +1,19 @@ +-7 + +--- + +source_file + statement: + prefix_expression + operation: - + target: integer_literal "7" + +--- + +top_level + body: + block + stmt: + unary_expr + operand: int_literal "7" + operator: prefix_operator "-" diff --git a/unified/extractor/tests/corpus/swift/literals/negative-integer-literal.swift b/unified/extractor/tests/corpus/swift/literals/negative-integer-literal.swift new file mode 100644 index 000000000000..17bdab103828 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/negative-integer-literal.swift @@ -0,0 +1 @@ +-7 diff --git a/unified/extractor/tests/corpus/swift/literals/nil-literal.output b/unified/extractor/tests/corpus/swift/literals/nil-literal.output new file mode 100644 index 000000000000..6c826cabe7db --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/nil-literal.output @@ -0,0 +1,13 @@ +nil + +--- + +source_file + statement: nil + +--- + +top_level + body: + block + stmt: builtin_expr "nil" diff --git a/unified/extractor/tests/corpus/swift/literals/nil-literal.swift b/unified/extractor/tests/corpus/swift/literals/nil-literal.swift new file mode 100644 index 000000000000..607602cfc6ed --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/nil-literal.swift @@ -0,0 +1 @@ +nil diff --git a/unified/extractor/tests/corpus/swift/literals/string-literal.output b/unified/extractor/tests/corpus/swift/literals/string-literal.output new file mode 100644 index 000000000000..ca2ac6df325d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/string-literal.output @@ -0,0 +1,15 @@ +"hello" + +--- + +source_file + statement: + line_string_literal + text: line_str_text "hello" + +--- + +top_level + body: + block + stmt: string_literal "\"hello\"" diff --git a/unified/extractor/tests/corpus/swift/literals/string-literal.swift b/unified/extractor/tests/corpus/swift/literals/string-literal.swift new file mode 100644 index 000000000000..3580093b9da0 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/string-literal.swift @@ -0,0 +1 @@ +"hello" diff --git a/unified/extractor/tests/corpus/swift/literals/string-with-interpolation.output b/unified/extractor/tests/corpus/swift/literals/string-with-interpolation.output new file mode 100644 index 000000000000..eb56fbbbb03f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/string-with-interpolation.output @@ -0,0 +1,18 @@ +"hello \(name)" + +--- + +source_file + statement: + line_string_literal + interpolation: + interpolated_expression + value: simple_identifier "name" + text: line_str_text "hello " + +--- + +top_level + body: + block + stmt: string_literal "\"hello \\(name)\"" diff --git a/unified/extractor/tests/corpus/swift/literals/string-with-interpolation.swift b/unified/extractor/tests/corpus/swift/literals/string-with-interpolation.swift new file mode 100644 index 000000000000..4c58b37b89e7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/literals/string-with-interpolation.swift @@ -0,0 +1 @@ +"hello \(name)" diff --git a/unified/extractor/tests/corpus/swift/loops.txt b/unified/extractor/tests/corpus/swift/loops.txt deleted file mode 100644 index b0e25debff52..000000000000 --- a/unified/extractor/tests/corpus/swift/loops.txt +++ /dev/null @@ -1,410 +0,0 @@ -=== -For-in over array literal -=== - -for x in [1, 2, 3] { - print(x) -} - ---- - -source_file - statement: - for_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "x" - collection: - array_literal - element: - integer_literal "1" - integer_literal "2" - integer_literal "3" - item: - pattern - bound_identifier: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - for_each_stmt - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "x" - callee: - name_expr - identifier: identifier "print" - pattern: - name_pattern - identifier: identifier "x" - iterable: - array_literal - element: - int_literal "1" - int_literal "2" - int_literal "3" - -=== -For-in over range -=== - -for i in 0..<10 { - print(i) -} - ---- - -source_file - statement: - for_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "i" - collection: - range_expression - end: integer_literal "10" - op: ..< - start: integer_literal "0" - item: - pattern - bound_identifier: simple_identifier "i" - ---- - -top_level - body: - block - stmt: - for_each_stmt - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "i" - callee: - name_expr - identifier: identifier "print" - pattern: - name_pattern - identifier: identifier "i" - iterable: - binary_expr - operator: infix_operator "..<" - left: int_literal "0" - right: int_literal "10" - -=== -For-in with where clause -=== - -for x in xs where x > 0 { - print(x) -} - ---- - -source_file - statement: - for_statement - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "x" - collection: simple_identifier "xs" - item: - pattern - bound_identifier: simple_identifier "x" - where: - where_clause - expr: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - keyword: where_keyword "where" - ---- - -top_level - body: - block - stmt: - for_each_stmt - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "x" - callee: - name_expr - identifier: identifier "print" - pattern: - name_pattern - identifier: identifier "x" - guard: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - iterable: - name_expr - identifier: identifier "xs" - -=== -While loop -=== - -while x > 0 { - x -= 1 -} - ---- - -source_file - statement: - while_statement - body: - block - statement: - assignment - operator: -= - result: integer_literal "1" - target: - directly_assignable_expression - expr: simple_identifier "x" - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - ---- - -top_level - body: - block - stmt: - while_stmt - body: - block - stmt: - compound_assign_expr - operator: infix_operator "-=" - target: - name_expr - identifier: identifier "x" - value: int_literal "1" - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - -=== -Repeat-while loop -=== - -repeat { - x -= 1 -} while x > 0 - ---- - -source_file - statement: - repeat_while_statement - body: - block - statement: - assignment - operator: -= - result: integer_literal "1" - target: - directly_assignable_expression - expr: simple_identifier "x" - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "0" - ---- - -top_level - body: - block - stmt: - do_while_stmt - body: - block - stmt: - compound_assign_expr - operator: infix_operator "-=" - target: - name_expr - identifier: identifier "x" - value: int_literal "1" - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - -=== -Break and continue -=== - -for x in xs { - if x < 0 { continue } - if x > 100 { break } - print(x) -} - ---- - -source_file - statement: - for_statement - body: - block - statement: - if_statement - body: - block - statement: - control_transfer_statement - kind: continue - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: < - rhs: integer_literal "0" - if_statement - body: - block - statement: - control_transfer_statement - kind: break - condition: - if_condition - kind: - comparison_expression - lhs: simple_identifier "x" - op: > - rhs: integer_literal "100" - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "x" - collection: simple_identifier "xs" - item: - pattern - bound_identifier: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - for_each_stmt - body: - block - stmt: - if_expr - condition: - binary_expr - operator: infix_operator "<" - left: - name_expr - identifier: identifier "x" - right: int_literal "0" - then: - block - stmt: continue_expr "continue" - if_expr - condition: - binary_expr - operator: infix_operator ">" - left: - name_expr - identifier: identifier "x" - right: int_literal "100" - then: - block - stmt: break_expr "break" - call_expr - argument: - argument - value: - name_expr - identifier: identifier "x" - callee: - name_expr - identifier: identifier "print" - pattern: - name_pattern - identifier: identifier "x" - iterable: - name_expr - identifier: identifier "xs" diff --git a/unified/extractor/tests/corpus/swift/loops/break-and-continue.output b/unified/extractor/tests/corpus/swift/loops/break-and-continue.output new file mode 100644 index 000000000000..702cd0cbc68b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/break-and-continue.output @@ -0,0 +1,101 @@ +for x in xs { + if x < 0 { continue } + if x > 100 { break } + print(x) +} + +--- + +source_file + statement: + for_statement + body: + block + statement: + if_statement + body: + block + statement: + control_transfer_statement + kind: continue + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: < + rhs: integer_literal "0" + if_statement + body: + block + statement: + control_transfer_statement + kind: break + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "100" + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "x" + collection: simple_identifier "xs" + item: + pattern + bound_identifier: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + for_each_stmt + body: + block + stmt: + if_expr + condition: + binary_expr + operator: infix_operator "<" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + then: + block + stmt: continue_expr "continue" + if_expr + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "100" + then: + block + stmt: break_expr "break" + call_expr + argument: + argument + value: + name_expr + identifier: identifier "x" + callee: + name_expr + identifier: identifier "print" + pattern: + name_pattern + identifier: identifier "x" + iterable: + name_expr + identifier: identifier "xs" diff --git a/unified/extractor/tests/corpus/swift/loops/break-and-continue.swift b/unified/extractor/tests/corpus/swift/loops/break-and-continue.swift new file mode 100644 index 000000000000..c06840ed8520 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/break-and-continue.swift @@ -0,0 +1,5 @@ +for x in xs { + if x < 0 { continue } + if x > 100 { break } + print(x) +} diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output new file mode 100644 index 000000000000..bb1711a23412 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output @@ -0,0 +1,59 @@ +for x in [1, 2, 3] { + print(x) +} + +--- + +source_file + statement: + for_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "x" + collection: + array_literal + element: + integer_literal "1" + integer_literal "2" + integer_literal "3" + item: + pattern + bound_identifier: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + for_each_stmt + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "x" + callee: + name_expr + identifier: identifier "print" + pattern: + name_pattern + identifier: identifier "x" + iterable: + array_literal + element: + int_literal "1" + int_literal "2" + int_literal "3" diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.swift b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.swift new file mode 100644 index 000000000000..e348f9cb04c7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.swift @@ -0,0 +1,3 @@ +for x in [1, 2, 3] { + print(x) +} diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output new file mode 100644 index 000000000000..87a0baf328b0 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output @@ -0,0 +1,57 @@ +for i in 0..<10 { + print(i) +} + +--- + +source_file + statement: + for_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "i" + collection: + range_expression + end: integer_literal "10" + op: ..< + start: integer_literal "0" + item: + pattern + bound_identifier: simple_identifier "i" + +--- + +top_level + body: + block + stmt: + for_each_stmt + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "i" + callee: + name_expr + identifier: identifier "print" + pattern: + name_pattern + identifier: identifier "i" + iterable: + binary_expr + operator: infix_operator "..<" + left: int_literal "0" + right: int_literal "10" diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-range.swift b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.swift new file mode 100644 index 000000000000..a13c39683cc6 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.swift @@ -0,0 +1,3 @@ +for i in 0..<10 { + print(i) +} diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output new file mode 100644 index 000000000000..84e832c2be5d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output @@ -0,0 +1,66 @@ +for x in xs where x > 0 { + print(x) +} + +--- + +source_file + statement: + for_statement + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "x" + collection: simple_identifier "xs" + item: + pattern + bound_identifier: simple_identifier "x" + where: + where_clause + expr: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + keyword: where_keyword "where" + +--- + +top_level + body: + block + stmt: + for_each_stmt + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "x" + callee: + name_expr + identifier: identifier "print" + pattern: + name_pattern + identifier: identifier "x" + guard: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" + iterable: + name_expr + identifier: identifier "xs" diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.swift b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.swift new file mode 100644 index 000000000000..5abedde7c560 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.swift @@ -0,0 +1,3 @@ +for x in xs where x > 0 { + print(x) +} diff --git a/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output b/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output new file mode 100644 index 000000000000..15b673109f2f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output @@ -0,0 +1,49 @@ +repeat { + x -= 1 +} while x > 0 + +--- + +source_file + statement: + repeat_while_statement + body: + block + statement: + assignment + operator: -= + result: integer_literal "1" + target: + directly_assignable_expression + expr: simple_identifier "x" + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + +--- + +top_level + body: + block + stmt: + do_while_stmt + body: + block + stmt: + compound_assign_expr + operator: infix_operator "-=" + target: + name_expr + identifier: identifier "x" + value: int_literal "1" + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.swift b/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.swift new file mode 100644 index 000000000000..ddffe068b705 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.swift @@ -0,0 +1,3 @@ +repeat { + x -= 1 +} while x > 0 diff --git a/unified/extractor/tests/corpus/swift/loops/while-loop.output b/unified/extractor/tests/corpus/swift/loops/while-loop.output new file mode 100644 index 000000000000..516ab43a2ee5 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/while-loop.output @@ -0,0 +1,49 @@ +while x > 0 { + x -= 1 +} + +--- + +source_file + statement: + while_statement + body: + block + statement: + assignment + operator: -= + result: integer_literal "1" + target: + directly_assignable_expression + expr: simple_identifier "x" + condition: + if_condition + kind: + comparison_expression + lhs: simple_identifier "x" + op: > + rhs: integer_literal "0" + +--- + +top_level + body: + block + stmt: + while_stmt + body: + block + stmt: + compound_assign_expr + operator: infix_operator "-=" + target: + name_expr + identifier: identifier "x" + value: int_literal "1" + condition: + binary_expr + operator: infix_operator ">" + left: + name_expr + identifier: identifier "x" + right: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/loops/while-loop.swift b/unified/extractor/tests/corpus/swift/loops/while-loop.swift new file mode 100644 index 000000000000..acd87ad53e1d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/loops/while-loop.swift @@ -0,0 +1,3 @@ +while x > 0 { + x -= 1 +} diff --git a/unified/extractor/tests/corpus/swift/operators.txt b/unified/extractor/tests/corpus/swift/operators.txt deleted file mode 100644 index d912a1085dc5..000000000000 --- a/unified/extractor/tests/corpus/swift/operators.txt +++ /dev/null @@ -1,367 +0,0 @@ -=== -Addition -=== - -a + b - ---- - -source_file - statement: - additive_expression - lhs: simple_identifier "a" - op: + - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Subtraction -=== - -a - b - ---- - -source_file - statement: - additive_expression - lhs: simple_identifier "a" - op: - - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "-" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Multiplication -=== - -a * b - ---- - -source_file - statement: - multiplicative_expression - lhs: simple_identifier "a" - op: * - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Division -=== - -a / b - ---- - -source_file - statement: - multiplicative_expression - lhs: simple_identifier "a" - op: / - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "/" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Operator precedence: addition and multiplication -=== - -a + b * c - ---- - -source_file - statement: - additive_expression - lhs: simple_identifier "a" - op: + - rhs: - multiplicative_expression - lhs: simple_identifier "b" - op: * - rhs: simple_identifier "c" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "+" - left: - name_expr - identifier: identifier "a" - right: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "b" - right: - name_expr - identifier: identifier "c" - -=== -Parenthesised expression -=== - -(a + b) * c - ---- - -source_file - statement: - multiplicative_expression - lhs: - tuple_expression - element: - tuple_expression_item - value: - additive_expression - lhs: simple_identifier "a" - op: + - rhs: simple_identifier "b" - op: * - rhs: simple_identifier "c" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "*" - left: tuple_expr "(a + b)" - right: - name_expr - identifier: identifier "c" - -=== -Comparison -=== - -a < b - ---- - -source_file - statement: - comparison_expression - lhs: simple_identifier "a" - op: < - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "<" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Equality -=== - -a == b - ---- - -source_file - statement: - equality_expression - lhs: simple_identifier "a" - op: == - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "==" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Logical and -=== - -a && b - ---- - -source_file - statement: - conjunction_expression - lhs: simple_identifier "a" - op: && - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "&&" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Logical or -=== - -a || b - ---- - -source_file - statement: - disjunction_expression - lhs: simple_identifier "a" - op: || - rhs: simple_identifier "b" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "||" - left: - name_expr - identifier: identifier "a" - right: - name_expr - identifier: identifier "b" - -=== -Logical not -=== - -!a - ---- - -source_file - statement: - prefix_expression - operation: bang "!" - target: simple_identifier "a" - ---- - -top_level - body: - block - stmt: - unary_expr - operand: - name_expr - identifier: identifier "a" - operator: prefix_operator "!" - -=== -Range operator -=== - -1...10 - ---- - -source_file - statement: - range_expression - end: integer_literal "10" - op: ... - start: integer_literal "1" - ---- - -top_level - body: - block - stmt: - binary_expr - operator: infix_operator "..." - left: int_literal "1" - right: int_literal "10" diff --git a/unified/extractor/tests/corpus/swift/operators/addition.output b/unified/extractor/tests/corpus/swift/operators/addition.output new file mode 100644 index 000000000000..42c0ca9de617 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/addition.output @@ -0,0 +1,25 @@ +a + b + +--- + +source_file + statement: + additive_expression + lhs: simple_identifier "a" + op: + + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/addition.swift b/unified/extractor/tests/corpus/swift/operators/addition.swift new file mode 100644 index 000000000000..745e8d376f74 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/addition.swift @@ -0,0 +1 @@ +a + b diff --git a/unified/extractor/tests/corpus/swift/operators/comparison.output b/unified/extractor/tests/corpus/swift/operators/comparison.output new file mode 100644 index 000000000000..f9428ad17589 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/comparison.output @@ -0,0 +1,25 @@ +a < b + +--- + +source_file + statement: + comparison_expression + lhs: simple_identifier "a" + op: < + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "<" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/comparison.swift b/unified/extractor/tests/corpus/swift/operators/comparison.swift new file mode 100644 index 000000000000..ec87be7535b1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/comparison.swift @@ -0,0 +1 @@ +a < b diff --git a/unified/extractor/tests/corpus/swift/operators/division.output b/unified/extractor/tests/corpus/swift/operators/division.output new file mode 100644 index 000000000000..765549543023 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/division.output @@ -0,0 +1,25 @@ +a / b + +--- + +source_file + statement: + multiplicative_expression + lhs: simple_identifier "a" + op: / + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "/" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/division.swift b/unified/extractor/tests/corpus/swift/operators/division.swift new file mode 100644 index 000000000000..81e31eb2d56a --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/division.swift @@ -0,0 +1 @@ +a / b diff --git a/unified/extractor/tests/corpus/swift/operators/equality.output b/unified/extractor/tests/corpus/swift/operators/equality.output new file mode 100644 index 000000000000..cc891492c75f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/equality.output @@ -0,0 +1,25 @@ +a == b + +--- + +source_file + statement: + equality_expression + lhs: simple_identifier "a" + op: == + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "==" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/equality.swift b/unified/extractor/tests/corpus/swift/operators/equality.swift new file mode 100644 index 000000000000..3868da7afe36 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/equality.swift @@ -0,0 +1 @@ +a == b diff --git a/unified/extractor/tests/corpus/swift/operators/logical-and.output b/unified/extractor/tests/corpus/swift/operators/logical-and.output new file mode 100644 index 000000000000..bf852cd46146 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/logical-and.output @@ -0,0 +1,25 @@ +a && b + +--- + +source_file + statement: + conjunction_expression + lhs: simple_identifier "a" + op: && + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "&&" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/logical-and.swift b/unified/extractor/tests/corpus/swift/operators/logical-and.swift new file mode 100644 index 000000000000..b0af58dca088 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/logical-and.swift @@ -0,0 +1 @@ +a && b diff --git a/unified/extractor/tests/corpus/swift/operators/logical-not.output b/unified/extractor/tests/corpus/swift/operators/logical-not.output new file mode 100644 index 000000000000..d07e357620fd --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/logical-not.output @@ -0,0 +1,21 @@ +!a + +--- + +source_file + statement: + prefix_expression + operation: bang "!" + target: simple_identifier "a" + +--- + +top_level + body: + block + stmt: + unary_expr + operand: + name_expr + identifier: identifier "a" + operator: prefix_operator "!" diff --git a/unified/extractor/tests/corpus/swift/operators/logical-not.swift b/unified/extractor/tests/corpus/swift/operators/logical-not.swift new file mode 100644 index 000000000000..60fc874768f5 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/logical-not.swift @@ -0,0 +1 @@ +!a diff --git a/unified/extractor/tests/corpus/swift/operators/logical-or.output b/unified/extractor/tests/corpus/swift/operators/logical-or.output new file mode 100644 index 000000000000..e246174844c1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/logical-or.output @@ -0,0 +1,25 @@ +a || b + +--- + +source_file + statement: + disjunction_expression + lhs: simple_identifier "a" + op: || + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "||" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/logical-or.swift b/unified/extractor/tests/corpus/swift/operators/logical-or.swift new file mode 100644 index 000000000000..ba0778d23959 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/logical-or.swift @@ -0,0 +1 @@ +a || b diff --git a/unified/extractor/tests/corpus/swift/operators/multiplication.output b/unified/extractor/tests/corpus/swift/operators/multiplication.output new file mode 100644 index 000000000000..b4c33b132863 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/multiplication.output @@ -0,0 +1,25 @@ +a * b + +--- + +source_file + statement: + multiplicative_expression + lhs: simple_identifier "a" + op: * + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/multiplication.swift b/unified/extractor/tests/corpus/swift/operators/multiplication.swift new file mode 100644 index 000000000000..339d501baf16 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/multiplication.swift @@ -0,0 +1 @@ +a * b diff --git a/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output b/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output new file mode 100644 index 000000000000..b1467474e7c6 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output @@ -0,0 +1,35 @@ +a + b * c + +--- + +source_file + statement: + additive_expression + lhs: simple_identifier "a" + op: + + rhs: + multiplicative_expression + lhs: simple_identifier "b" + op: * + rhs: simple_identifier "c" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "+" + left: + name_expr + identifier: identifier "a" + right: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "b" + right: + name_expr + identifier: identifier "c" diff --git a/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.swift b/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.swift new file mode 100644 index 000000000000..a191c7bf0b6e --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.swift @@ -0,0 +1 @@ +a + b * c diff --git a/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output b/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output new file mode 100644 index 000000000000..dfc60e5b7f72 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output @@ -0,0 +1,31 @@ +(a + b) * c + +--- + +source_file + statement: + multiplicative_expression + lhs: + tuple_expression + element: + tuple_expression_item + value: + additive_expression + lhs: simple_identifier "a" + op: + + rhs: simple_identifier "b" + op: * + rhs: simple_identifier "c" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "*" + left: tuple_expr "(a + b)" + right: + name_expr + identifier: identifier "c" diff --git a/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.swift b/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.swift new file mode 100644 index 000000000000..614106d923c2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.swift @@ -0,0 +1 @@ +(a + b) * c diff --git a/unified/extractor/tests/corpus/swift/operators/range-operator.output b/unified/extractor/tests/corpus/swift/operators/range-operator.output new file mode 100644 index 000000000000..03d0290bb7c5 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/range-operator.output @@ -0,0 +1,21 @@ +1...10 + +--- + +source_file + statement: + range_expression + end: integer_literal "10" + op: ... + start: integer_literal "1" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "..." + left: int_literal "1" + right: int_literal "10" diff --git a/unified/extractor/tests/corpus/swift/operators/range-operator.swift b/unified/extractor/tests/corpus/swift/operators/range-operator.swift new file mode 100644 index 000000000000..3161f10bb72c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/range-operator.swift @@ -0,0 +1 @@ +1...10 diff --git a/unified/extractor/tests/corpus/swift/operators/subtraction.output b/unified/extractor/tests/corpus/swift/operators/subtraction.output new file mode 100644 index 000000000000..69f75e720408 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/subtraction.output @@ -0,0 +1,25 @@ +a - b + +--- + +source_file + statement: + additive_expression + lhs: simple_identifier "a" + op: - + rhs: simple_identifier "b" + +--- + +top_level + body: + block + stmt: + binary_expr + operator: infix_operator "-" + left: + name_expr + identifier: identifier "a" + right: + name_expr + identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/subtraction.swift b/unified/extractor/tests/corpus/swift/operators/subtraction.swift new file mode 100644 index 000000000000..3ab3ec9adf13 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/operators/subtraction.swift @@ -0,0 +1 @@ +a - b diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors.txt b/unified/extractor/tests/corpus/swift/optionals-and-errors.txt deleted file mode 100644 index 23e545f54630..000000000000 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors.txt +++ /dev/null @@ -1,418 +0,0 @@ -=== -Optional type annotation -=== - -let x: Int? = nil - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - type: - type_annotation - type: - type - name: - optional_type - wrapped: - user_type - part: - simple_user_type - name: type_identifier "Int" - value: nil - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "x" - type: - generic_type_expr - base: - named_type_expr - name: identifier "Optional" - type_argument: - named_type_expr - name: identifier "Int" - value: builtin_expr "nil" - -=== -Optional chaining -=== - -let n = obj?.foo?.bar - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "n" - value: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "bar" - target: - optional_chain_marker - expr: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "foo" - target: - optional_chain_marker - expr: simple_identifier "obj" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "n" - value: - member_access_expr - base: - member_access_expr - base: - name_expr - identifier: identifier "obj" - member: identifier "foo" - member: identifier "bar" - -=== -Force unwrap -=== - -let n = opt! - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "n" - value: - postfix_expression - operation: bang "!" - target: simple_identifier "opt" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "n" - value: - unary_expr - operand: - name_expr - identifier: identifier "opt" - operator: postfix_operator "!" - -=== -Nil-coalescing -=== - -let n = opt ?? 0 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "n" - value: - nil_coalescing_expression - if_nil: integer_literal "0" - value: simple_identifier "opt" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "n" - value: - binary_expr - operator: infix_operator "??" - left: - name_expr - identifier: identifier "opt" - right: int_literal "0" - -=== -Throwing function -=== - -func read() throws -> String { - return "" -} - ---- - -source_file - statement: - function_declaration - body: - block - statement: - control_transfer_statement - kind: return - result: - line_string_literal - name: simple_identifier "read" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "String" - throws: throws "throws" - ---- - -top_level - body: - block - stmt: - function_declaration - body: - block - stmt: - return_expr - value: string_literal "\"\"" - name: identifier "read" - return_type: - named_type_expr - name: identifier "String" - -=== -Do-catch -=== - -do { - try foo() -} catch { - print(error) -} - ---- - -source_file - statement: - do_statement - body: - block - statement: - try_expression - expr: - call_expression - function: simple_identifier "foo" - suffix: - call_suffix - arguments: - value_arguments - operator: - try_operator - catch: - catch_block - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "error" - keyword: catch_keyword "catch" - ---- - -top_level - body: - block - stmt: - try_expr - body: - block - stmt: - unary_expr - operand: - call_expr - callee: - name_expr - identifier: identifier "foo" - operator: prefix_operator "try" - catch_clause: - catch_clause - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "error" - callee: - name_expr - identifier: identifier "print" - -=== -Try? expression -=== - -let result = try? foo() - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "result" - value: - try_expression - expr: - call_expression - function: simple_identifier "foo" - suffix: - call_suffix - arguments: - value_arguments - operator: - try_operator - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "result" - value: - unary_expr - operand: - call_expr - callee: - name_expr - identifier: identifier "foo" - operator: prefix_operator "try?" - -=== -Try! expression -=== - -let result = try! foo() - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "result" - value: - try_expression - expr: - call_expression - function: simple_identifier "foo" - suffix: - call_suffix - arguments: - value_arguments - operator: - try_operator - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "result" - value: - unary_expr - operand: - call_expr - callee: - name_expr - identifier: identifier "foo" - operator: prefix_operator "try!" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output new file mode 100644 index 000000000000..c807bd9b7b9c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output @@ -0,0 +1,71 @@ +do { + try foo() +} catch { + print(error) +} + +--- + +source_file + statement: + do_statement + body: + block + statement: + try_expression + expr: + call_expression + function: simple_identifier "foo" + suffix: + call_suffix + arguments: + value_arguments + operator: + try_operator + catch: + catch_block + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "error" + keyword: catch_keyword "catch" + +--- + +top_level + body: + block + stmt: + try_expr + body: + block + stmt: + unary_expr + operand: + call_expr + callee: + name_expr + identifier: identifier "foo" + operator: prefix_operator "try" + catch_clause: + catch_clause + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "error" + callee: + name_expr + identifier: identifier "print" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.swift new file mode 100644 index 000000000000..21eadeeda01f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.swift @@ -0,0 +1,5 @@ +do { + try foo() +} catch { + print(error) +} diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output new file mode 100644 index 000000000000..96fb627e18b1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output @@ -0,0 +1,37 @@ +let n = opt! + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "n" + value: + postfix_expression + operation: bang "!" + target: simple_identifier "opt" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "n" + value: + unary_expr + operand: + name_expr + identifier: identifier "opt" + operator: postfix_operator "!" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.swift new file mode 100644 index 000000000000..a8d4c8731434 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.swift @@ -0,0 +1 @@ +let n = opt! diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output new file mode 100644 index 000000000000..81a9a9187c04 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output @@ -0,0 +1,38 @@ +let n = opt ?? 0 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "n" + value: + nil_coalescing_expression + if_nil: integer_literal "0" + value: simple_identifier "opt" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "n" + value: + binary_expr + operator: infix_operator "??" + left: + name_expr + identifier: identifier "opt" + right: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.swift new file mode 100644 index 000000000000..8452be9529e2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.swift @@ -0,0 +1 @@ +let n = opt ?? 0 diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output new file mode 100644 index 000000000000..6c5b27a64fe2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output @@ -0,0 +1,51 @@ +let n = obj?.foo?.bar + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "n" + value: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "bar" + target: + optional_chain_marker + expr: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "foo" + target: + optional_chain_marker + expr: simple_identifier "obj" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "n" + value: + member_access_expr + base: + member_access_expr + base: + name_expr + identifier: identifier "obj" + member: identifier "foo" + member: identifier "bar" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.swift new file mode 100644 index 000000000000..d49b180cdea3 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.swift @@ -0,0 +1 @@ +let n = obj?.foo?.bar diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output new file mode 100644 index 000000000000..06191891496e --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output @@ -0,0 +1,48 @@ +let x: Int? = nil + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + type: + type_annotation + type: + type + name: + optional_type + wrapped: + user_type + part: + simple_user_type + name: type_identifier "Int" + value: nil + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "x" + type: + generic_type_expr + base: + named_type_expr + name: identifier "Optional" + type_argument: + named_type_expr + name: identifier "Int" + value: builtin_expr "nil" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.swift new file mode 100644 index 000000000000..79c1610f361f --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.swift @@ -0,0 +1 @@ +let x: Int? = nil diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output new file mode 100644 index 000000000000..f1240bd0b3ef --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output @@ -0,0 +1,42 @@ +func read() throws -> String { + return "" +} + +--- + +source_file + statement: + function_declaration + body: + block + statement: + control_transfer_statement + kind: return + result: + line_string_literal + name: simple_identifier "read" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "String" + throws: throws "throws" + +--- + +top_level + body: + block + stmt: + function_declaration + body: + block + stmt: + return_expr + value: string_literal "\"\"" + name: identifier "read" + return_type: + named_type_expr + name: identifier "String" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.swift new file mode 100644 index 000000000000..bab5b74fcd08 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.swift @@ -0,0 +1,3 @@ +func read() throws -> String { + return "" +} diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output new file mode 100644 index 000000000000..9d5ff032d75c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output @@ -0,0 +1,46 @@ +let result = try! foo() + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "result" + value: + try_expression + expr: + call_expression + function: simple_identifier "foo" + suffix: + call_suffix + arguments: + value_arguments + operator: + try_operator + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "result" + value: + unary_expr + operand: + call_expr + callee: + name_expr + identifier: identifier "foo" + operator: prefix_operator "try!" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.swift new file mode 100644 index 000000000000..186255d96ca2 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.swift @@ -0,0 +1 @@ +let result = try! foo() diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output new file mode 100644 index 000000000000..e6a7bfef3444 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output @@ -0,0 +1,46 @@ +let result = try? foo() + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "result" + value: + try_expression + expr: + call_expression + function: simple_identifier "foo" + suffix: + call_suffix + arguments: + value_arguments + operator: + try_operator + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "result" + value: + unary_expr + operand: + call_expr + callee: + name_expr + identifier: identifier "foo" + operator: prefix_operator "try?" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.swift b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.swift new file mode 100644 index 000000000000..1185bae5ec1c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.swift @@ -0,0 +1 @@ +let result = try? foo() diff --git a/unified/extractor/tests/corpus/swift/types.txt b/unified/extractor/tests/corpus/swift/types.txt deleted file mode 100644 index 9c22ae74798b..000000000000 --- a/unified/extractor/tests/corpus/swift/types.txt +++ /dev/null @@ -1,1082 +0,0 @@ -=== -Empty class -=== - -class Foo {} - ---- - -source_file - statement: - class_declaration - body: - class_body - declaration_kind: class - name: type_identifier "Foo" - ---- - -top_level - body: - block - stmt: - class_like_declaration - modifier: modifier "class" - name: identifier "Foo" - -=== -Class with stored properties -=== - -class Point { - var x: Int - var y: Int -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "y" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - declaration_kind: class - name: type_identifier "Point" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "y" - type: - named_type_expr - name: identifier "Int" - modifier: modifier "class" - name: identifier "Point" - -=== -Class with initializer -=== - -class Point { - var x: Int - init(x: Int) { - self.x = x - } -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - init_declaration - body: - block - statement: - assignment - operator: = - result: simple_identifier "x" - target: - directly_assignable_expression - expr: - navigation_expression - suffix: - navigation_suffix - suffix: simple_identifier "x" - target: - self_expression - parameter: - function_parameter - parameter: - parameter - name: simple_identifier "x" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - declaration_kind: class - name: type_identifier "Point" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - constructor_declaration - body: - block - stmt: - assign_expr - target: - member_access_expr - base: - name_expr - identifier: identifier "self" - member: identifier "x" - value: - name_expr - identifier: identifier "x" - modifier: modifier "class" - name: identifier "Point" - -=== -Class with method -=== - -class Counter { - var n = 0 - func bump() { - n += 1 - } -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "n" - value: integer_literal "0" - function_declaration - body: - block - statement: - assignment - operator: += - result: integer_literal "1" - target: - directly_assignable_expression - expr: simple_identifier "n" - name: simple_identifier "bump" - declaration_kind: class - name: type_identifier "Counter" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "n" - value: int_literal "0" - function_declaration - body: - block - stmt: - compound_assign_expr - operator: infix_operator "+=" - target: - name_expr - identifier: identifier "n" - value: int_literal "1" - name: identifier "bump" - modifier: modifier "class" - name: identifier "Counter" - -=== -Class inheritance -=== - -class Dog: Animal {} - ---- - -source_file - statement: - class_declaration - body: - class_body - declaration_kind: class - inherits: - inheritance_specifier - inherits_from: - user_type - part: - simple_user_type - name: type_identifier "Animal" - name: type_identifier "Dog" - ---- - -top_level - body: - block - stmt: - class_like_declaration - modifier: modifier "class" - name: identifier "Dog" - -=== -Struct -=== - -struct Point { - let x: Int - let y: Int -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "y" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - declaration_kind: struct - name: type_identifier "Point" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "y" - type: - named_type_expr - name: identifier "Int" - modifier: modifier "struct" - name: identifier "Point" - -=== -Enum with cases -=== - -enum Direction { - case north - case south - case east - case west -} - ---- - -source_file - statement: - class_declaration - body: - enum_class_body - member: - enum_entry - case: - enum_case_entry - name: simple_identifier "north" - enum_entry - case: - enum_case_entry - name: simple_identifier "south" - enum_entry - case: - enum_case_entry - name: simple_identifier "east" - enum_entry - case: - enum_case_entry - name: simple_identifier "west" - declaration_kind: enum - name: type_identifier "Direction" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "enum_case" - pattern: - name_pattern - identifier: identifier "north" - variable_declaration - modifier: modifier "enum_case" - pattern: - name_pattern - identifier: identifier "south" - variable_declaration - modifier: modifier "enum_case" - pattern: - name_pattern - identifier: identifier "east" - variable_declaration - modifier: modifier "enum_case" - pattern: - name_pattern - identifier: identifier "west" - modifier: modifier "enum" - name: identifier "Direction" - -=== -Enum with associated values -=== - -enum Shape { - case circle(radius: Double) - case square(side: Double) -} - ---- - -source_file - statement: - class_declaration - body: - enum_class_body - member: - enum_entry - case: - enum_case_entry - data_contents: - enum_type_parameters - parameter: - enum_type_parameter - name: simple_identifier "radius" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Double" - name: simple_identifier "circle" - enum_entry - case: - enum_case_entry - data_contents: - enum_type_parameters - parameter: - enum_type_parameter - name: simple_identifier "side" - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Double" - name: simple_identifier "square" - declaration_kind: enum - name: type_identifier "Shape" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - class_like_declaration - member: - constructor_declaration - body: block "circle(radius: Double)" - parameter: - parameter - pattern: - name_pattern - identifier: identifier "radius" - type: - named_type_expr - name: identifier "Double" - modifier: modifier "enum_case" - name: identifier "circle" - class_like_declaration - member: - constructor_declaration - body: block "square(side: Double)" - parameter: - parameter - pattern: - name_pattern - identifier: identifier "side" - type: - named_type_expr - name: identifier "Double" - modifier: modifier "enum_case" - name: identifier "square" - modifier: modifier "enum" - name: identifier "Shape" - -=== -Protocol declaration -=== - -protocol Drawable { - func draw() -} - ---- - -source_file - statement: - protocol_declaration - body: - protocol_body - member: - protocol_function_declaration - name: simple_identifier "draw" - name: type_identifier "Drawable" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - function_declaration - body: block "func draw()" - name: identifier "draw" - modifier: modifier "protocol" - name: identifier "Drawable" - -=== -Extension -=== - -extension Int { - func squared() -> Int { return self * self } -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - function_declaration - body: - block - statement: - control_transfer_statement - kind: return - result: - multiplicative_expression - lhs: - self_expression - op: * - rhs: - self_expression - name: simple_identifier "squared" - return_type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - declaration_kind: extension - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - function_declaration - body: - block - stmt: - return_expr - value: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "self" - right: - name_expr - identifier: identifier "self" - name: identifier "squared" - return_type: - named_type_expr - name: identifier "Int" - modifier: modifier "extension" - name: identifier "Int" - -=== -Computed property -=== - -class Rect { - var w: Double - var h: Double - var area: Double { - return w * h - } -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "w" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Double" - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "h" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Double" - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - computed_value: - computed_property - statement: - control_transfer_statement - kind: return - result: - multiplicative_expression - lhs: simple_identifier "w" - op: * - rhs: simple_identifier "h" - name: - pattern - bound_identifier: simple_identifier "area" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Double" - declaration_kind: class - name: type_identifier "Rect" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "w" - type: - named_type_expr - name: identifier "Double" - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "h" - type: - named_type_expr - name: identifier "Double" - accessor_declaration - body: - block - stmt: - return_expr - value: - binary_expr - operator: infix_operator "*" - left: - name_expr - identifier: identifier "w" - right: - name_expr - identifier: identifier "h" - modifier: modifier "var" - name: identifier "area" - type: - named_type_expr - name: identifier "Double" - accessor_kind: accessor_kind "get" - modifier: modifier "class" - name: identifier "Rect" - -=== -Property with getter and setter -=== - -class Box { - private var _v = 0 - var v: Int { - get { return _v } - set { _v = newValue } - } -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "_v" - value: integer_literal "0" - modifiers: - modifiers - modifier: - visibility_modifier - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - computed_value: - computed_property - accessor: - computed_getter - body: - block - statement: - control_transfer_statement - kind: return - result: simple_identifier "_v" - specifier: - getter_specifier - computed_setter - body: - block - statement: - assignment - operator: = - result: simple_identifier "newValue" - target: - directly_assignable_expression - expr: simple_identifier "_v" - specifier: - setter_specifier - name: - pattern - bound_identifier: simple_identifier "v" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - declaration_kind: class - name: type_identifier "Box" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "_v" - value: int_literal "0" - accessor_declaration - body: - block - stmt: - return_expr - value: - name_expr - identifier: identifier "_v" - modifier: modifier "var" - name: identifier "v" - type: - named_type_expr - name: identifier "Int" - accessor_kind: accessor_kind "get" - accessor_declaration - body: - block - stmt: - assign_expr - target: - name_expr - identifier: identifier "_v" - value: - name_expr - identifier: identifier "newValue" - modifier: - modifier "var" - modifier "chained_declaration" - name: identifier "v" - type: - named_type_expr - name: identifier "Int" - accessor_kind: accessor_kind "set" - modifier: modifier "class" - name: identifier "Box" - -=== -Protocol with read-only and read-write property requirements -=== - -protocol P { - var foo: Int { get } - var bar: String { get set } -} - ---- - -source_file - statement: - protocol_declaration - body: - protocol_body - member: - protocol_property_declaration - name: - pattern - binding: - value_binding_pattern - mutability: var - bound_identifier: simple_identifier "foo" - requirements: - protocol_property_requirements - accessor: - getter_specifier - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - protocol_property_declaration - name: - pattern - binding: - value_binding_pattern - mutability: var - bound_identifier: simple_identifier "bar" - requirements: - protocol_property_requirements - accessor: - getter_specifier - setter_specifier - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "String" - name: type_identifier "P" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - accessor_declaration - name: identifier "foo" - type: - named_type_expr - name: identifier "Int" - accessor_kind: accessor_kind "get" - accessor_declaration - name: identifier "bar" - type: - named_type_expr - name: identifier "String" - accessor_kind: accessor_kind "get" - accessor_declaration - modifier: modifier "chained_declaration" - name: identifier "bar" - type: - named_type_expr - name: identifier "String" - accessor_kind: accessor_kind "set" - modifier: modifier "protocol" - name: identifier "P" - -=== -Enum with comma-separated cases (chained_declaration) -=== - -enum Suit { - case clubs, diamonds, hearts, spades -} - ---- - -source_file - statement: - class_declaration - body: - enum_class_body - member: - enum_entry - case: - enum_case_entry - name: simple_identifier "clubs" - enum_case_entry - name: simple_identifier "diamonds" - enum_case_entry - name: simple_identifier "hearts" - enum_case_entry - name: simple_identifier "spades" - declaration_kind: enum - name: type_identifier "Suit" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "enum_case" - pattern: - name_pattern - identifier: identifier "clubs" - variable_declaration - modifier: - modifier "chained_declaration" - modifier "enum_case" - pattern: - name_pattern - identifier: identifier "diamonds" - variable_declaration - modifier: - modifier "chained_declaration" - modifier "enum_case" - pattern: - name_pattern - identifier: identifier "hearts" - variable_declaration - modifier: - modifier "chained_declaration" - modifier "enum_case" - pattern: - name_pattern - identifier: identifier "spades" - modifier: modifier "enum" - name: identifier "Suit" diff --git a/unified/extractor/tests/corpus/swift/types/class-inheritance.output b/unified/extractor/tests/corpus/swift/types/class-inheritance.output new file mode 100644 index 000000000000..e90cccc4a8b6 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-inheritance.output @@ -0,0 +1,28 @@ +class Dog: Animal {} + +--- + +source_file + statement: + class_declaration + body: + class_body + declaration_kind: class + inherits: + inheritance_specifier + inherits_from: + user_type + part: + simple_user_type + name: type_identifier "Animal" + name: type_identifier "Dog" + +--- + +top_level + body: + block + stmt: + class_like_declaration + modifier: modifier "class" + name: identifier "Dog" diff --git a/unified/extractor/tests/corpus/swift/types/class-inheritance.swift b/unified/extractor/tests/corpus/swift/types/class-inheritance.swift new file mode 100644 index 000000000000..4e23bbf345d7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-inheritance.swift @@ -0,0 +1 @@ +class Dog: Animal {} diff --git a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output new file mode 100644 index 000000000000..13e0097172cc --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output @@ -0,0 +1,96 @@ +class Point { + var x: Int + init(x: Int) { + self.x = x + } +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + init_declaration + body: + block + statement: + assignment + operator: = + result: simple_identifier "x" + target: + directly_assignable_expression + expr: + navigation_expression + suffix: + navigation_suffix + suffix: simple_identifier "x" + target: + self_expression + parameter: + function_parameter + parameter: + parameter + name: simple_identifier "x" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + declaration_kind: class + name: type_identifier "Point" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + constructor_declaration + body: + block + stmt: + assign_expr + target: + member_access_expr + base: + name_expr + identifier: identifier "self" + member: identifier "x" + value: + name_expr + identifier: identifier "x" + modifier: modifier "class" + name: identifier "Point" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-initializer.swift b/unified/extractor/tests/corpus/swift/types/class-with-initializer.swift new file mode 100644 index 000000000000..b6614be2c0f9 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.swift @@ -0,0 +1,6 @@ +class Point { + var x: Int + init(x: Int) { + self.x = x + } +} diff --git a/unified/extractor/tests/corpus/swift/types/class-with-method.output b/unified/extractor/tests/corpus/swift/types/class-with-method.output new file mode 100644 index 000000000000..770030d884a7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-with-method.output @@ -0,0 +1,66 @@ +class Counter { + var n = 0 + func bump() { + n += 1 + } +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "n" + value: integer_literal "0" + function_declaration + body: + block + statement: + assignment + operator: += + result: integer_literal "1" + target: + directly_assignable_expression + expr: simple_identifier "n" + name: simple_identifier "bump" + declaration_kind: class + name: type_identifier "Counter" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "n" + value: int_literal "0" + function_declaration + body: + block + stmt: + compound_assign_expr + operator: infix_operator "+=" + target: + name_expr + identifier: identifier "n" + value: int_literal "1" + name: identifier "bump" + modifier: modifier "class" + name: identifier "Counter" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-method.swift b/unified/extractor/tests/corpus/swift/types/class-with-method.swift new file mode 100644 index 000000000000..21b04669f0de --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-with-method.swift @@ -0,0 +1,6 @@ +class Counter { + var n = 0 + func bump() { + n += 1 + } +} diff --git a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output new file mode 100644 index 000000000000..9d28afe6ae0e --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output @@ -0,0 +1,78 @@ +class Point { + var x: Int + var y: Int +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "y" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + declaration_kind: class + name: type_identifier "Point" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "y" + type: + named_type_expr + name: identifier "Int" + modifier: modifier "class" + name: identifier "Point" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.swift b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.swift new file mode 100644 index 000000000000..737d710ed4d0 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.swift @@ -0,0 +1,4 @@ +class Point { + var x: Int + var y: Int +} diff --git a/unified/extractor/tests/corpus/swift/types/computed-property.output b/unified/extractor/tests/corpus/swift/types/computed-property.output new file mode 100644 index 000000000000..8803e652d316 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/computed-property.output @@ -0,0 +1,129 @@ +class Rect { + var w: Double + var h: Double + var area: Double { + return w * h + } +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "w" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Double" + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "h" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Double" + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + computed_value: + computed_property + statement: + control_transfer_statement + kind: return + result: + multiplicative_expression + lhs: simple_identifier "w" + op: * + rhs: simple_identifier "h" + name: + pattern + bound_identifier: simple_identifier "area" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Double" + declaration_kind: class + name: type_identifier "Rect" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "w" + type: + named_type_expr + name: identifier "Double" + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "h" + type: + named_type_expr + name: identifier "Double" + accessor_declaration + body: + block + stmt: + return_expr + value: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "w" + right: + name_expr + identifier: identifier "h" + modifier: modifier "var" + name: identifier "area" + type: + named_type_expr + name: identifier "Double" + accessor_kind: accessor_kind "get" + modifier: modifier "class" + name: identifier "Rect" diff --git a/unified/extractor/tests/corpus/swift/types/computed-property.swift b/unified/extractor/tests/corpus/swift/types/computed-property.swift new file mode 100644 index 000000000000..579a87200191 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/computed-property.swift @@ -0,0 +1,7 @@ +class Rect { + var w: Double + var h: Double + var area: Double { + return w * h + } +} diff --git a/unified/extractor/tests/corpus/swift/types/empty-class.output b/unified/extractor/tests/corpus/swift/types/empty-class.output new file mode 100644 index 000000000000..761de778543d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/empty-class.output @@ -0,0 +1,21 @@ +class Foo {} + +--- + +source_file + statement: + class_declaration + body: + class_body + declaration_kind: class + name: type_identifier "Foo" + +--- + +top_level + body: + block + stmt: + class_like_declaration + modifier: modifier "class" + name: identifier "Foo" diff --git a/unified/extractor/tests/corpus/swift/types/empty-class.swift b/unified/extractor/tests/corpus/swift/types/empty-class.swift new file mode 100644 index 000000000000..4e6a6de65314 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/empty-class.swift @@ -0,0 +1 @@ +class Foo {} diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output new file mode 100644 index 000000000000..12b5191f69f9 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output @@ -0,0 +1,86 @@ +enum Shape { + case circle(radius: Double) + case square(side: Double) +} + +--- + +source_file + statement: + class_declaration + body: + enum_class_body + member: + enum_entry + case: + enum_case_entry + data_contents: + enum_type_parameters + parameter: + enum_type_parameter + name: simple_identifier "radius" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Double" + name: simple_identifier "circle" + enum_entry + case: + enum_case_entry + data_contents: + enum_type_parameters + parameter: + enum_type_parameter + name: simple_identifier "side" + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Double" + name: simple_identifier "square" + declaration_kind: enum + name: type_identifier "Shape" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + class_like_declaration + member: + constructor_declaration + body: block "circle(radius: Double)" + parameter: + parameter + pattern: + name_pattern + identifier: identifier "radius" + type: + named_type_expr + name: identifier "Double" + modifier: modifier "enum_case" + name: identifier "circle" + class_like_declaration + member: + constructor_declaration + body: block "square(side: Double)" + parameter: + parameter + pattern: + name_pattern + identifier: identifier "side" + type: + named_type_expr + name: identifier "Double" + modifier: modifier "enum_case" + name: identifier "square" + modifier: modifier "enum" + name: identifier "Shape" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.swift b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.swift new file mode 100644 index 000000000000..860944cc5304 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.swift @@ -0,0 +1,4 @@ +enum Shape { + case circle(radius: Double) + case square(side: Double) +} diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output new file mode 100644 index 000000000000..72435fd2b1f7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output @@ -0,0 +1,64 @@ +enum Direction { + case north + case south + case east + case west +} + +--- + +source_file + statement: + class_declaration + body: + enum_class_body + member: + enum_entry + case: + enum_case_entry + name: simple_identifier "north" + enum_entry + case: + enum_case_entry + name: simple_identifier "south" + enum_entry + case: + enum_case_entry + name: simple_identifier "east" + enum_entry + case: + enum_case_entry + name: simple_identifier "west" + declaration_kind: enum + name: type_identifier "Direction" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "enum_case" + pattern: + name_pattern + identifier: identifier "north" + variable_declaration + modifier: modifier "enum_case" + pattern: + name_pattern + identifier: identifier "south" + variable_declaration + modifier: modifier "enum_case" + pattern: + name_pattern + identifier: identifier "east" + variable_declaration + modifier: modifier "enum_case" + pattern: + name_pattern + identifier: identifier "west" + modifier: modifier "enum" + name: identifier "Direction" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-cases.swift b/unified/extractor/tests/corpus/swift/types/enum-with-cases.swift new file mode 100644 index 000000000000..1200f764fd1c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/enum-with-cases.swift @@ -0,0 +1,6 @@ +enum Direction { + case north + case south + case east + case west +} diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output new file mode 100644 index 000000000000..6a4aac4b552d --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output @@ -0,0 +1,61 @@ +enum Suit { + case clubs, diamonds, hearts, spades +} + +--- + +source_file + statement: + class_declaration + body: + enum_class_body + member: + enum_entry + case: + enum_case_entry + name: simple_identifier "clubs" + enum_case_entry + name: simple_identifier "diamonds" + enum_case_entry + name: simple_identifier "hearts" + enum_case_entry + name: simple_identifier "spades" + declaration_kind: enum + name: type_identifier "Suit" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "enum_case" + pattern: + name_pattern + identifier: identifier "clubs" + variable_declaration + modifier: + modifier "chained_declaration" + modifier "enum_case" + pattern: + name_pattern + identifier: identifier "diamonds" + variable_declaration + modifier: + modifier "chained_declaration" + modifier "enum_case" + pattern: + name_pattern + identifier: identifier "hearts" + variable_declaration + modifier: + modifier "chained_declaration" + modifier "enum_case" + pattern: + name_pattern + identifier: identifier "spades" + modifier: modifier "enum" + name: identifier "Suit" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.swift b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.swift new file mode 100644 index 000000000000..efb9ef45d7c8 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.swift @@ -0,0 +1,3 @@ +enum Suit { + case clubs, diamonds, hearts, spades +} diff --git a/unified/extractor/tests/corpus/swift/types/extension.output b/unified/extractor/tests/corpus/swift/types/extension.output new file mode 100644 index 000000000000..ad663cb86e16 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/extension.output @@ -0,0 +1,68 @@ +extension Int { + func squared() -> Int { return self * self } +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + function_declaration + body: + block + statement: + control_transfer_statement + kind: return + result: + multiplicative_expression + lhs: + self_expression + op: * + rhs: + self_expression + name: simple_identifier "squared" + return_type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + declaration_kind: extension + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + function_declaration + body: + block + stmt: + return_expr + value: + binary_expr + operator: infix_operator "*" + left: + name_expr + identifier: identifier "self" + right: + name_expr + identifier: identifier "self" + name: identifier "squared" + return_type: + named_type_expr + name: identifier "Int" + modifier: modifier "extension" + name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/types/extension.swift b/unified/extractor/tests/corpus/swift/types/extension.swift new file mode 100644 index 000000000000..ac537d5c0aa1 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/extension.swift @@ -0,0 +1,3 @@ +extension Int { + func squared() -> Int { return self * self } +} diff --git a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output new file mode 100644 index 000000000000..0a8b2d8cc5d7 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output @@ -0,0 +1,124 @@ +class Box { + private var _v = 0 + var v: Int { + get { return _v } + set { _v = newValue } + } +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "_v" + value: integer_literal "0" + modifiers: + modifiers + modifier: + visibility_modifier + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + computed_value: + computed_property + accessor: + computed_getter + body: + block + statement: + control_transfer_statement + kind: return + result: simple_identifier "_v" + specifier: + getter_specifier + computed_setter + body: + block + statement: + assignment + operator: = + result: simple_identifier "newValue" + target: + directly_assignable_expression + expr: simple_identifier "_v" + specifier: + setter_specifier + name: + pattern + bound_identifier: simple_identifier "v" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + declaration_kind: class + name: type_identifier "Box" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "_v" + value: int_literal "0" + accessor_declaration + body: + block + stmt: + return_expr + value: + name_expr + identifier: identifier "_v" + modifier: modifier "var" + name: identifier "v" + type: + named_type_expr + name: identifier "Int" + accessor_kind: accessor_kind "get" + accessor_declaration + body: + block + stmt: + assign_expr + target: + name_expr + identifier: identifier "_v" + value: + name_expr + identifier: identifier "newValue" + modifier: + modifier "var" + modifier "chained_declaration" + name: identifier "v" + type: + named_type_expr + name: identifier "Int" + accessor_kind: accessor_kind "set" + modifier: modifier "class" + name: identifier "Box" diff --git a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.swift b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.swift new file mode 100644 index 000000000000..98bfd8574933 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.swift @@ -0,0 +1,7 @@ +class Box { + private var _v = 0 + var v: Int { + get { return _v } + set { _v = newValue } + } +} diff --git a/unified/extractor/tests/corpus/swift/types/protocol-declaration.output b/unified/extractor/tests/corpus/swift/types/protocol-declaration.output new file mode 100644 index 000000000000..55a71218c18c --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/protocol-declaration.output @@ -0,0 +1,29 @@ +protocol Drawable { + func draw() +} + +--- + +source_file + statement: + protocol_declaration + body: + protocol_body + member: + protocol_function_declaration + name: simple_identifier "draw" + name: type_identifier "Drawable" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + function_declaration + body: block "func draw()" + name: identifier "draw" + modifier: modifier "protocol" + name: identifier "Drawable" diff --git a/unified/extractor/tests/corpus/swift/types/protocol-declaration.swift b/unified/extractor/tests/corpus/swift/types/protocol-declaration.swift new file mode 100644 index 000000000000..030b68a60c04 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/protocol-declaration.swift @@ -0,0 +1,3 @@ +protocol Drawable { + func draw() +} diff --git a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output new file mode 100644 index 000000000000..0293534adf76 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output @@ -0,0 +1,85 @@ +protocol P { + var foo: Int { get } + var bar: String { get set } +} + +--- + +source_file + statement: + protocol_declaration + body: + protocol_body + member: + protocol_property_declaration + name: + pattern + binding: + value_binding_pattern + mutability: var + bound_identifier: simple_identifier "foo" + requirements: + protocol_property_requirements + accessor: + getter_specifier + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + protocol_property_declaration + name: + pattern + binding: + value_binding_pattern + mutability: var + bound_identifier: simple_identifier "bar" + requirements: + protocol_property_requirements + accessor: + getter_specifier + setter_specifier + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "String" + name: type_identifier "P" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + accessor_declaration + name: identifier "foo" + type: + named_type_expr + name: identifier "Int" + accessor_kind: accessor_kind "get" + accessor_declaration + name: identifier "bar" + type: + named_type_expr + name: identifier "String" + accessor_kind: accessor_kind "get" + accessor_declaration + modifier: modifier "chained_declaration" + name: identifier "bar" + type: + named_type_expr + name: identifier "String" + accessor_kind: accessor_kind "set" + modifier: modifier "protocol" + name: identifier "P" diff --git a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift new file mode 100644 index 000000000000..44299edc15b9 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift @@ -0,0 +1,4 @@ +protocol P { + var foo: Int { get } + var bar: String { get set } +} diff --git a/unified/extractor/tests/corpus/swift/types/struct.output b/unified/extractor/tests/corpus/swift/types/struct.output new file mode 100644 index 000000000000..e130ef9b8623 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/struct.output @@ -0,0 +1,78 @@ +struct Point { + let x: Int + let y: Int +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "y" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + declaration_kind: struct + name: type_identifier "Point" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "y" + type: + named_type_expr + name: identifier "Int" + modifier: modifier "struct" + name: identifier "Point" diff --git a/unified/extractor/tests/corpus/swift/types/struct.swift b/unified/extractor/tests/corpus/swift/types/struct.swift new file mode 100644 index 000000000000..718ecf5e9383 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/struct.swift @@ -0,0 +1,4 @@ +struct Point { + let x: Int + let y: Int +} diff --git a/unified/extractor/tests/corpus/swift/variables.txt b/unified/extractor/tests/corpus/swift/variables.txt deleted file mode 100644 index 78b80d9a5098..000000000000 --- a/unified/extractor/tests/corpus/swift/variables.txt +++ /dev/null @@ -1,448 +0,0 @@ -=== -Let binding -=== - -let x = 1 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - value: integer_literal "1" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "x" - value: int_literal "1" - -=== -Var binding -=== - -var x = 1 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - value: integer_literal "1" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "x" - value: int_literal "1" - -=== -Let with type annotation -=== - -let x: Int = 1 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - value: integer_literal "1" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - value: int_literal "1" - -=== -Var without initialiser -=== - -var x: Int - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - -=== -Tuple destructuring binding -=== - -let (a, b) = pair - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - kind: - tuple_pattern - item: - tuple_pattern_item - pattern: - pattern - kind: simple_identifier "a" - tuple_pattern_item - pattern: - pattern - kind: simple_identifier "b" - value: simple_identifier "pair" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - tuple_pattern - element: - pattern_element - pattern: - expr_equality_pattern - expr: - name_expr - identifier: identifier "a" - pattern_element - pattern: - expr_equality_pattern - expr: - name_expr - identifier: identifier "b" - value: - name_expr - identifier: identifier "pair" - -=== -Multiple bindings on one line -=== - -let x = 1, y = 2 - ---- - -source_file - statement: - property_declaration - binding: - value_binding_pattern - mutability: let - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - value: integer_literal "1" - property_binding - name: - pattern - bound_identifier: simple_identifier "y" - value: integer_literal "2" - ---- - -top_level - body: - block - stmt: - variable_declaration - modifier: modifier "let" - pattern: - name_pattern - identifier: identifier "x" - value: int_literal "1" - variable_declaration - modifier: - modifier "let" - modifier "chained_declaration" - pattern: - name_pattern - identifier: identifier "y" - value: int_literal "2" - -=== -Assignment -=== - -x = 1 - ---- - -source_file - statement: - assignment - operator: = - result: integer_literal "1" - target: - directly_assignable_expression - expr: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - assign_expr - target: - name_expr - identifier: identifier "x" - value: int_literal "1" - -=== -Compound assignment -=== - -x += 1 - ---- - -source_file - statement: - assignment - operator: += - result: integer_literal "1" - target: - directly_assignable_expression - expr: simple_identifier "x" - ---- - -top_level - body: - block - stmt: - compound_assign_expr - operator: infix_operator "+=" - target: - name_expr - identifier: identifier "x" - value: int_literal "1" - -=== -Property with willSet and didSet observers -=== - -class C { - var x: Int = 0 { - willSet { print(newValue) } - didSet { print(oldValue) } - } -} - ---- - -source_file - statement: - class_declaration - body: - class_body - member: - property_declaration - binding: - value_binding_pattern - mutability: var - declarator: - property_binding - name: - pattern - bound_identifier: simple_identifier "x" - observers: - willset_didset_block - didset: - didset_clause - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "oldValue" - willset: - willset_clause - body: - block - statement: - call_expression - function: simple_identifier "print" - suffix: - call_suffix - arguments: - value_arguments - argument: - value_argument - value: simple_identifier "newValue" - type: - type_annotation - type: - type - name: - user_type - part: - simple_user_type - name: type_identifier "Int" - value: integer_literal "0" - declaration_kind: class - name: type_identifier "C" - ---- - -top_level - body: - block - stmt: - class_like_declaration - member: - variable_declaration - modifier: modifier "var" - pattern: - name_pattern - identifier: identifier "x" - type: - named_type_expr - name: identifier "Int" - value: int_literal "0" - accessor_declaration - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "newValue" - callee: - name_expr - identifier: identifier "print" - modifier: - modifier "var" - modifier "chained_declaration" - name: identifier "x" - accessor_kind: accessor_kind "willSet" - accessor_declaration - body: - block - stmt: - call_expr - argument: - argument - value: - name_expr - identifier: identifier "oldValue" - callee: - name_expr - identifier: identifier "print" - modifier: - modifier "var" - modifier "chained_declaration" - name: identifier "x" - accessor_kind: accessor_kind "didSet" - modifier: modifier "class" - name: identifier "C" diff --git a/unified/extractor/tests/corpus/swift/variables/assignment.output b/unified/extractor/tests/corpus/swift/variables/assignment.output new file mode 100644 index 000000000000..9d1a61e89a82 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/assignment.output @@ -0,0 +1,24 @@ +x = 1 + +--- + +source_file + statement: + assignment + operator: = + result: integer_literal "1" + target: + directly_assignable_expression + expr: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + assign_expr + target: + name_expr + identifier: identifier "x" + value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/assignment.swift b/unified/extractor/tests/corpus/swift/variables/assignment.swift new file mode 100644 index 000000000000..7d4290a117a4 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/assignment.swift @@ -0,0 +1 @@ +x = 1 diff --git a/unified/extractor/tests/corpus/swift/variables/compound-assignment.output b/unified/extractor/tests/corpus/swift/variables/compound-assignment.output new file mode 100644 index 000000000000..95b7edb0a6ba --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/compound-assignment.output @@ -0,0 +1,25 @@ +x += 1 + +--- + +source_file + statement: + assignment + operator: += + result: integer_literal "1" + target: + directly_assignable_expression + expr: simple_identifier "x" + +--- + +top_level + body: + block + stmt: + compound_assign_expr + operator: infix_operator "+=" + target: + name_expr + identifier: identifier "x" + value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/compound-assignment.swift b/unified/extractor/tests/corpus/swift/variables/compound-assignment.swift new file mode 100644 index 000000000000..9feca8b76593 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/compound-assignment.swift @@ -0,0 +1 @@ +x += 1 diff --git a/unified/extractor/tests/corpus/swift/variables/let-binding.output b/unified/extractor/tests/corpus/swift/variables/let-binding.output new file mode 100644 index 000000000000..b8b16dc80144 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/let-binding.output @@ -0,0 +1,29 @@ +let x = 1 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + value: integer_literal "1" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "x" + value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/let-binding.swift b/unified/extractor/tests/corpus/swift/variables/let-binding.swift new file mode 100644 index 000000000000..0547b3d0eee9 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/let-binding.swift @@ -0,0 +1 @@ +let x = 1 diff --git a/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output new file mode 100644 index 000000000000..3fd78d09fa42 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output @@ -0,0 +1,41 @@ +let x: Int = 1 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + value: integer_literal "1" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.swift b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.swift new file mode 100644 index 000000000000..4eea1708b6b8 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.swift @@ -0,0 +1 @@ +let x: Int = 1 diff --git a/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output new file mode 100644 index 000000000000..7f202885b9be --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output @@ -0,0 +1,42 @@ +let x = 1, y = 2 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + value: integer_literal "1" + property_binding + name: + pattern + bound_identifier: simple_identifier "y" + value: integer_literal "2" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + name_pattern + identifier: identifier "x" + value: int_literal "1" + variable_declaration + modifier: + modifier "let" + modifier "chained_declaration" + pattern: + name_pattern + identifier: identifier "y" + value: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.swift b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.swift new file mode 100644 index 000000000000..42c4804475bb --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.swift @@ -0,0 +1 @@ +let x = 1, y = 2 diff --git a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output new file mode 100644 index 000000000000..2d612e1d950e --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output @@ -0,0 +1,122 @@ +class C { + var x: Int = 0 { + willSet { print(newValue) } + didSet { print(oldValue) } + } +} + +--- + +source_file + statement: + class_declaration + body: + class_body + member: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + observers: + willset_didset_block + didset: + didset_clause + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "oldValue" + willset: + willset_clause + body: + block + statement: + call_expression + function: simple_identifier "print" + suffix: + call_suffix + arguments: + value_arguments + argument: + value_argument + value: simple_identifier "newValue" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + value: integer_literal "0" + declaration_kind: class + name: type_identifier "C" + +--- + +top_level + body: + block + stmt: + class_like_declaration + member: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" + value: int_literal "0" + accessor_declaration + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "newValue" + callee: + name_expr + identifier: identifier "print" + modifier: + modifier "var" + modifier "chained_declaration" + name: identifier "x" + accessor_kind: accessor_kind "willSet" + accessor_declaration + body: + block + stmt: + call_expr + argument: + argument + value: + name_expr + identifier: identifier "oldValue" + callee: + name_expr + identifier: identifier "print" + modifier: + modifier "var" + modifier "chained_declaration" + name: identifier "x" + accessor_kind: accessor_kind "didSet" + modifier: modifier "class" + name: identifier "C" diff --git a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.swift b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.swift new file mode 100644 index 000000000000..a8ea2d060160 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.swift @@ -0,0 +1,6 @@ +class C { + var x: Int = 0 { + willSet { print(newValue) } + didSet { print(oldValue) } + } +} diff --git a/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output new file mode 100644 index 000000000000..a0a45eb6d22a --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output @@ -0,0 +1,53 @@ +let (a, b) = pair + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: let + declarator: + property_binding + name: + pattern + kind: + tuple_pattern + item: + tuple_pattern_item + pattern: + pattern + kind: simple_identifier "a" + tuple_pattern_item + pattern: + pattern + kind: simple_identifier "b" + value: simple_identifier "pair" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "let" + pattern: + tuple_pattern + element: + pattern_element + pattern: + expr_equality_pattern + expr: + name_expr + identifier: identifier "a" + pattern_element + pattern: + expr_equality_pattern + expr: + name_expr + identifier: identifier "b" + value: + name_expr + identifier: identifier "pair" diff --git a/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.swift b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.swift new file mode 100644 index 000000000000..0d9823c33a36 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.swift @@ -0,0 +1 @@ +let (a, b) = pair diff --git a/unified/extractor/tests/corpus/swift/variables/var-binding.output b/unified/extractor/tests/corpus/swift/variables/var-binding.output new file mode 100644 index 000000000000..b7dc8e772700 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/var-binding.output @@ -0,0 +1,29 @@ +var x = 1 + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + value: integer_literal "1" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "x" + value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/var-binding.swift b/unified/extractor/tests/corpus/swift/variables/var-binding.swift new file mode 100644 index 000000000000..492fc438eaea --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/var-binding.swift @@ -0,0 +1 @@ +var x = 1 diff --git a/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output new file mode 100644 index 000000000000..692befea8553 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output @@ -0,0 +1,39 @@ +var x: Int + +--- + +source_file + statement: + property_declaration + binding: + value_binding_pattern + mutability: var + declarator: + property_binding + name: + pattern + bound_identifier: simple_identifier "x" + type: + type_annotation + type: + type + name: + user_type + part: + simple_user_type + name: type_identifier "Int" + +--- + +top_level + body: + block + stmt: + variable_declaration + modifier: modifier "var" + pattern: + name_pattern + identifier: identifier "x" + type: + named_type_expr + name: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.swift b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.swift new file mode 100644 index 000000000000..6b39ae0ffe97 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.swift @@ -0,0 +1 @@ +var x: Int From 28f0be5c67de3491927da8230a79bfa151e7b767 Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 30 Jun 2026 07:17:23 +0200 Subject: [PATCH 3/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unified/AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unified/AGENTS.md b/unified/AGENTS.md index 1a929c09a715..a50a49868a24 100644 --- a/unified/AGENTS.md +++ b/unified/AGENTS.md @@ -19,7 +19,7 @@ This is a CodeQL extractor based on tree-sitter. - To run tests for the parser and mapping, run `cargo test` in the `extractor` directory. -- Extractor test cases are located at `extractor/test/corpus/swift/*/*.swift`. +- Extractor test cases are located at `extractor/tests/corpus/swift/*/*.swift`. - Each test case has a corresponding `.output` file containing its generated output along with a copy of the test case itself.