Skip to content

Commit 979ccd1

Browse files
committed
[Test] Use swift-ide-test for signature help tests
1 parent 85bf842 commit 979ccd1

27 files changed

+415
-1216
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=CLOSURE_PARAM -source-filename=%s | %FileCheck %s --check-prefix=CLOSURE_PARAM
2+
3+
func apply<Value, Result>(value: Value, body: (Value) -> Result) -> Result {
4+
return body(#^CLOSURE_PARAM^#)
5+
}
6+
7+
// CLOSURE_PARAM: Begin signatures, 1 items
8+
// CLOSURE_PARAM-NEXT: Signature[Active]: body(<param name="" active>Value</param>) -> Result
9+
// CLOSURE_PARAM-NEXT: End signatures
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=CURRY_TOPLEVEL -source-filename=%s | %FileCheck %s --check-prefix=CURRY_TOPLEVEL
2+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=CURRY_MEMBER_PARTIAL -source-filename=%s | %FileCheck %s --check-prefix=CURRY_MEMBER_PARTIAL
3+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=CURRY_MEMBER_FULL -source-filename=%s | %FileCheck %s --check-prefix=CURRY_MEMBER_FULL
4+
5+
struct Adder {
6+
func add(_ x: Int, to y: Int) -> Int {
7+
return x + y
8+
}
9+
10+
func add(oneTo x: inout Int) {
11+
x += 1
12+
}
13+
14+
func add<T: AdditiveArithmetic>(_ x: T, to y: T) -> T {
15+
return x + y
16+
}
17+
18+
func add(first: Double!, second: Float, third: Int) -> Double {
19+
return first + Double(second) + Double(third)
20+
}
21+
22+
func add(arg1 param1: Double, arg2: Float, arg3 param3: Int) -> Double {
23+
return param1 + Double(arg2) + Double(param3)
24+
}
25+
26+
func add(numbers: Double...) -> Double {
27+
return numbers.reduce(into: 0) { $0 += $1 }
28+
}
29+
30+
func add(x: Int, y: Int, with adder: (Int, Int) throws -> Int) rethrows -> Int! {
31+
return try adder(x, y)
32+
}
33+
34+
func add(x: Int) -> (Int) -> Int {
35+
return { (y: Int) in x + y }
36+
}
37+
}
38+
39+
func topLevelCurried(x: Int) -> (Double) -> (String) -> Void {
40+
fatalError()
41+
}
42+
43+
func testCurryTopLevel() {
44+
topLevelCurried(x: 1)(#^CURRY_TOPLEVEL^#)
45+
}
46+
47+
func testCurryMemberPartial() {
48+
Adder.add(#^CURRY_MEMBER_PARTIAL^#)
49+
}
50+
51+
func testCurryMemberFull() {
52+
let adder = Adder()
53+
Adder.add(adder)(#^CURRY_MEMBER_FULL^#)
54+
}
55+
56+
// CURRY_TOPLEVEL: Begin signatures, 1 items
57+
// CURRY_TOPLEVEL-NEXT: Signature[Active]: (<param name="" active>Double</param>) -> (String) -> Void
58+
// CURRY_TOPLEVEL-NEXT: End signatures
59+
60+
// CURRY_MEMBER_PARTIAL: Begin signatures, 8 items
61+
// CURRY_MEMBER_PARTIAL-NEXT: Signature[Active]: add(<param name="self" active>_ self: Adder</param>) -> (Int, Int) -> Int
62+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (inout Int) -> ()
63+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (AdditiveArithmetic, AdditiveArithmetic) -> AdditiveArithmetic
64+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (Double?, Float, Int) -> Double
65+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (Double, Float, Int) -> Double
66+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (Double...) -> Double
67+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (Int, Int, (Int, Int) throws -> Int) throws -> Int?
68+
// CURRY_MEMBER_PARTIAL-NEXT: Signature: add(<param name="self" active>_ self: Adder</param>) -> (Int) -> (Int) -> Int
69+
// CURRY_MEMBER_PARTIAL-NEXT: End signatures
70+
71+
// CURRY_MEMBER_FULL: Begin signatures, 8 items
72+
// CURRY_MEMBER_FULL-NEXT: Signature[Active]: (<param name="x" active>_ x: Int</param>, <param name="y">to: Int</param>) -> Int
73+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="x" active>oneTo: inout Int</param>)
74+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="x" active>_ x: AdditiveArithmetic</param>, <param name="y">to: AdditiveArithmetic</param>) -> AdditiveArithmetic
75+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="first" active>first: Double!</param>, <param name="second">second: Float</param>, <param name="third">third: Int</param>) -> Double
76+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="param1" active>arg1: Double</param>, <param name="arg2">arg2: Float</param>, <param name="param3">arg3: Int</param>) -> Double
77+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="numbers" active>numbers: Double...</param>) -> Double
78+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="x" active>x: Int</param>, <param name="y">y: Int</param>, <param name="adder">with: (Int, Int) throws -> Int</param>) throws -> Int!
79+
// CURRY_MEMBER_FULL-NEXT: Signature: (<param name="x" active>x: Int</param>) -> (Int) -> Int
80+
// CURRY_MEMBER_FULL-NEXT: End signatures
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=DEFAULT_ARGS -source-filename=%s | %FileCheck %s --check-prefix=DEFAULT_ARGS
2+
3+
func add(_ x: Int = 10, to y: Int) -> Int {}
4+
5+
func add(oneTo x: inout Int) {}
6+
7+
func add(_ x: Int, to y: Int? = nil) -> String {}
8+
9+
func add(first: Double!, second: Float = .pi, third: Int) -> Double {}
10+
11+
struct S {
12+
let a: Bool
13+
}
14+
15+
func add(s: S = S(a: false)) -> Double {}
16+
17+
func add(x: Int, y: Int, with adder: (Int, Int) -> Int = { $0 + $1 }) -> Int {}
18+
19+
let importantValue = 42
20+
21+
func add(x: Int = importantValue) {}
22+
23+
func add(x: Int, line: UInt = #line, file: StaticString = #file) {}
24+
25+
add(#^DEFAULT_ARGS^#)
26+
27+
// DEFAULT_ARGS: Begin signatures, 8 items
28+
// DEFAULT_ARGS-NEXT: Signature[Active]: add(<param name="x" active>_ x: Int = 10</param>, <param name="y">to: Int</param>) -> Int
29+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="x" active>oneTo: inout Int</param>)
30+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="x" active>_ x: Int</param>, <param name="y">to: Int? = nil</param>) -> String
31+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="first" active>first: Double!</param>, <param name="second">second: Float = .pi</param>, <param name="third">third: Int</param>) -> Double
32+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="s" active>s: S = S(a: false)</param>) -> Double
33+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="x" active>x: Int</param>, <param name="y">y: Int</param>, <param name="adder">with: (Int, Int) -> Int = { $0 + $1 }</param>) -> Int
34+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="x" active>x: Int = importantValue</param>)
35+
// DEFAULT_ARGS-NEXT: Signature: add(<param name="x" active>x: Int</param>, <param name="line">line: UInt = #line</param>, <param name="file">file: StaticString = #file</param>)
36+
// DEFAULT_ARGS-NEXT: End signatures

test/IDE/signature_help_doc.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=DOC -source-filename=%s | %FileCheck %s --check-prefix=DOC
2+
3+
/// Adds two integers.
4+
///
5+
/// - Parameters:
6+
/// - x: The first integer to add.
7+
/// - y: The second integer to add.
8+
///
9+
/// Usage:
10+
/// ```swift
11+
/// add(1, to: 2) // 3
12+
/// ```
13+
///
14+
/// - Returns: The sum of the two integers.
15+
func add(_ x: Int, to y: Int) -> Int {
16+
return x + y
17+
}
18+
19+
add(#^DOC^#)
20+
21+
// DOC: Begin signatures, 1 items
22+
// DOC-NEXT: Signature[Active]: add(<param name="x" active>_ x: Int</param>, <param name="y">to: Int</param>) -> Int; Documentation=Adds two integers.\n\n- Parameters:\n - x: The first integer to add.\n - y: The second integer to add.\n\nUsage:\n```swift\nadd(1, to: 2) // 3\n```\n\n- Returns: The sum of the two integers.
23+
// DOC-NEXT: End signatures
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=LABELLED -source-filename=%s | %FileCheck %s --check-prefix=LABELLED
2+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=UNLABELLED -source-filename=%s | %FileCheck %s --check-prefix=UNLABELLED
3+
4+
enum Barcode {
5+
case upc(numberSystem: Int, manufacturer: Int, product: Int, check: Int)
6+
case qrCode(String)
7+
}
8+
9+
func testLabeled() {
10+
Barcode.upc(#^LABELLED^#, manufacturer: 85909, product: 51226, check: 3)
11+
}
12+
13+
func testUnlabled() {
14+
Barcode.qrCode(#^UNLABELLED^#)
15+
}
16+
17+
// LABELLED: Begin signatures, 1 items
18+
// LABELLED-NEXT: Signature[Active]: upc(<param name="numberSystem" active>numberSystem: Int</param>, <param name="manufacturer">manufacturer: Int</param>, <param name="product">product: Int</param>, <param name="check">check: Int</param>) -> Barcode
19+
// LABELLED-NEXT: End signatures
20+
21+
// UNLABELLED: Begin signatures, 1 items
22+
// UNLABELLED-NEXT: Signature[Active]: qrCode(<param name="" active>String</param>) -> Barcode
23+
// UNLABELLED-NEXT: End signatures

test/IDE/signature_help_init.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=INIT -source-filename=%s | %FileCheck %s --check-prefix=INIT
2+
3+
struct Person {
4+
init(name: String, age: Int, profession job: String) { }
5+
}
6+
7+
Person(name: "John", age: #^INIT^#)
8+
9+
// INIT: Begin signatures, 1 items
10+
// INIT-NEXT: Signature[Active]: init(<param name="name">name: String</param>, <param name="age" active>age: Int</param>, <param name="job">profession: String</param>)
11+
// INIT-NEXT: End signatures
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=MEMBER_CLOSURE -source-filename=%s | %FileCheck %s --check-prefix=MEMBER_CLOSURE
2+
3+
struct Observable {
4+
var observer: (String, Int?, [AnyHashable: [Double?]]) async throws -> [Observable?]
5+
6+
func notify() async throws {
7+
_ = try await observer("EVENT", #^MEMBER_CLOSURE^#, [:])
8+
}
9+
}
10+
11+
// MEMBER_CLOSURE: Begin signatures, 1 items
12+
// MEMBER_CLOSURE-NEXT: Signature[Active]: observer(<param name="">String</param>, <param name="" active>Int?</param>, <param name="">[AnyHashable : [Double?]]</param>) async throws -> [Observable?]
13+
// MEMBER_CLOSURE-NEXT: End signatures
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=MEMBER_FUNC -source-filename=%s | %FileCheck %s --check-prefix=MEMBER_FUNC
2+
3+
struct Adder {
4+
func add(_ x: Int, to y: Int) -> Int {
5+
return x + y
6+
}
7+
8+
func add(oneTo x: inout Int) {
9+
x += 1
10+
}
11+
12+
func add<T: AdditiveArithmetic>(_ x: T, to y: T) -> T {
13+
return x + y
14+
}
15+
16+
func add(first: Double!, second: Float, third: Int) -> Double {
17+
return first + Double(second) + Double(third)
18+
}
19+
20+
func add(arg1 param1: Double, arg2: Float, arg3 param3: Int) -> Double {
21+
return param1 + Double(arg2) + Double(param3)
22+
}
23+
24+
func add(numbers: Double...) -> Double {
25+
return numbers.reduce(into: 0) { $0 += $1 }
26+
}
27+
28+
func add(x: Int, y: Int, with adder: (Int, Int) -> Int) -> Int {
29+
return adder(x, y)
30+
}
31+
32+
func add(x: Int) -> (Int) -> Int {
33+
return { (y: Int) in x + y }
34+
}
35+
}
36+
37+
let adder = Adder()
38+
adder.add(#^MEMBER_FUNC^#)
39+
40+
// MEMBER_FUNC: Begin signatures, 8 items
41+
// MEMBER_FUNC-NEXT: Signature[Active]: add(<param name="x" active>_ x: Int</param>, <param name="y">to: Int</param>) -> Int
42+
// MEMBER_FUNC-NEXT: Signature: add(<param name="x" active>oneTo: inout Int</param>)
43+
// MEMBER_FUNC-NEXT: Signature: add(<param name="x" active>_ x: AdditiveArithmetic</param>, <param name="y">to: AdditiveArithmetic</param>) -> AdditiveArithmetic
44+
// MEMBER_FUNC-NEXT: Signature: add(<param name="first" active>first: Double!</param>, <param name="second">second: Float</param>, <param name="third">third: Int</param>) -> Double
45+
// MEMBER_FUNC-NEXT: Signature: add(<param name="param1" active>arg1: Double</param>, <param name="arg2">arg2: Float</param>, <param name="param3">arg3: Int</param>) -> Double
46+
// MEMBER_FUNC-NEXT: Signature: add(<param name="numbers" active>numbers: Double...</param>) -> Double
47+
// MEMBER_FUNC-NEXT: Signature: add(<param name="x" active>x: Int</param>, <param name="y">y: Int</param>, <param name="adder">with: (Int, Int) -> Int</param>) -> Int
48+
// MEMBER_FUNC-NEXT: Signature: add(<param name="x" active>x: Int</param>) -> (Int) -> Int
49+
// MEMBER_FUNC-NEXT: End signatures
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=MEMBER_GENERIC -source-filename=%s | %FileCheck %s --check-prefix=MEMBER_GENERIC
2+
3+
struct Vector<Value> {
4+
init(elements: [Value]) { }
5+
6+
func dot(with other: Vector<Value>) -> Value { fatalError() }
7+
}
8+
9+
let vec = Vector(elements: [1.0, 2.1, 3.4])
10+
vec.dot(with: #^MEMBER_GENERIC^#)
11+
12+
// MEMBER_GENERIC: Begin signatures, 1 items
13+
// MEMBER_GENERIC-NEXT: Signature[Active]: dot(<param name="other" active>with: Vector<Double></param>) -> Double
14+
// MEMBER_GENERIC-NEXT: End signatures
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-ide-test -signature-help -code-completion-token=MEMBER_SUBSCRIPT -source-filename=%s | %FileCheck %s --check-prefix=MEMBER_SUBSCRIPT
2+
3+
struct Matrix {
4+
subscript(row: Int, column: Int) -> Int {
5+
return 0
6+
}
7+
8+
subscript(row r: Int) -> [Int] {
9+
return []
10+
}
11+
12+
subscript(column c: Int) -> [Int] {
13+
return []
14+
}
15+
}
16+
17+
let matrix = Matrix()
18+
matrix[#^MEMBER_SUBSCRIPT^#]
19+
20+
// MEMBER_SUBSCRIPT: Begin signatures, 4 items
21+
// MEMBER_SUBSCRIPT-NEXT: Signature[Active]: subscript(<param name="" active>keyPath: KeyPath<Matrix, Value></param>) -> Value
22+
// MEMBER_SUBSCRIPT-NEXT: Signature: subscript(<param name="row" active>row: Int</param>, <param name="column">column: Int</param>) -> Int
23+
// MEMBER_SUBSCRIPT-NEXT: Signature: subscript(<param name="r" active>row: Int</param>) -> [Int]
24+
// MEMBER_SUBSCRIPT-NEXT: Signature: subscript(<param name="c" active>column: Int</param>) -> [Int]
25+
// MEMBER_SUBSCRIPT-NEXT: End signatures

0 commit comments

Comments
 (0)