Skip to content

Commit 7245f58

Browse files
authored
Merge pull request #58890 from ahoppen/pr/add-more-fixed-test-cases
[CodeCompletion] Add test cases that were fixed and had reduced reproducers
2 parents af713bc + 49f8bdb commit 7245f58

File tree

7 files changed

+268
-0
lines changed

7 files changed

+268
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %swift-ide-test --code-completion --code-completion-token COMPLETE --source-filename %s
2+
3+
protocol View2 {}
4+
5+
struct Foo {
6+
init() {}
7+
func pnReceive(perform action: (MyResult) -> Void) -> some View2 {
8+
fatalError()
9+
}
10+
}
11+
12+
struct SomeStruct {
13+
var string: String
14+
}
15+
16+
@resultBuilder public struct ViewBuilder2 {
17+
public static func buildBlock<Content>(_ content: Content) -> Content where Content : View2 { fatalError() }
18+
}
19+
20+
@ViewBuilder2 var body: some View2 {
21+
Foo().pnReceive() { (value) in
22+
switch value {
23+
case let .success(#^COMPLETE^#raw, pretty):
24+
break
25+
}
26+
}
27+
}
28+
29+
enum MyResult {
30+
case success(SomeStruct)
31+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
enum A {
5+
case one, two
6+
}
7+
8+
struct B<T> {
9+
let value: T
10+
11+
init(_ value: T) {
12+
self.value = value
13+
}
14+
15+
static func void() -> B<Void> {
16+
return B<Void>(())
17+
}
18+
19+
static func data(_ data: Data) -> B<Data> {
20+
return B<Data>(data)
21+
}
22+
}
23+
24+
class C {
25+
func a(s: String = "", a: A) {}
26+
func b(s: String = "", i: Int = 0, a: A) {}
27+
}
28+
29+
class D {
30+
func a<T>(b: B<T>, s: String = "") {}
31+
func b<T>(s: String = "", i: Int = 0, b: B<T>) {}
32+
}
33+
34+
// type a point "." in placeholders to see the substitution list
35+
36+
// correct substitution
37+
C().a(s: .#^STR_1?check=STRING^#, a: .#^A_1?check=A^#)
38+
C().a(a: .#^A_2?check=A^#)
39+
40+
C().b(s: .#^STR_2?check=STRING^#, i: .#^INT_1?check=INT^#, a: .#^A_3?check=A^#)
41+
C().b(i: .#^INT_2?check=INT^#, a: .#^A_4?check=A^#)
42+
C().b(a: .#^A_5?check=A^#)
43+
44+
D().a(b: .#^B_1?check=B^#, s: .#^STR_3?check=STRING^#)
45+
D().a(b: .#^B_2?check=B^#)
46+
47+
D().b(s: .#^STR_4?check=STRING^#, i: .#^INT_3?check=INT^#, b: .#^B_3?check=B^#)
48+
49+
// // incorrect substitution from previous parameter
50+
D().b(i: .#^INT_4?check=INT^#, b: .#^B_4?check=B^#)
51+
D().b(b: .#^B_5?check=B^#)
52+
53+
// INT: Begin completions
54+
// INT-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Convertible]: init({#bitPattern: UInt#})[#Int#]; name=init(bitPattern:)
55+
// INT: End completions
56+
57+
// STRING: Begin completions
58+
// STRING-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Convertible]: init()[#String#]; name=init()
59+
// STRING: End completions
60+
61+
// A: Begin completions, 3 items
62+
// A-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: one[#A#]; name=one
63+
// A-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: two[#A#]; name=two
64+
// A-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): A#})[#(into: inout Hasher) -> Void#]; name=hash(:)
65+
// A: End completions
66+
67+
// B: Begin completions, 3 items
68+
// B-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init({#(value): T#})[#B<T>#]; name=init(:)
69+
// B-DAG: Decl[StaticMethod]/CurrNominal/TypeRelation[Convertible]: void()[#B<Void>#]; name=void()
70+
// B-DAG: Decl[StaticMethod]/CurrNominal: data({#(data): <<error type>>#})[#<<error type>>#]; name=data(:)
71+
// B: End completions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
struct Earthquake {
5+
var magnitude: Float
6+
}
7+
8+
@resultBuilder
9+
struct TestBuilder<Q> {
10+
static func buildBlock(_ exp: String) -> String { "test" }
11+
static func buildExpression<T>(_ sample: KeyPath<Q, T>) -> String { "test" }
12+
static func buildExpression(_ func: (Q) -> Bool) -> String { "test" }
13+
}
14+
15+
func ==<V, T: Equatable> (left: KeyPath<V, T>, right: T) -> (V) -> Bool {
16+
return { $0[keyPath: left] == right }
17+
}
18+
19+
func ||<T> (left: @escaping (T) -> Bool, right: @escaping (T) -> Bool) -> (T) -> Bool {
20+
return { left($0) || right($0) }
21+
}
22+
23+
class Test<Q> {
24+
init(@TestBuilder<Q> _ builder: () -> String) {}
25+
}
26+
27+
func test() {
28+
_ = Test<Earthquake> {
29+
\.magnitude == 2 || \.#^COMPLETE_1?check=CHECK^#
30+
}
31+
_ = Test<Earthquake> {
32+
\.magnitude == 2 || \.#^COMPLETE_2?check=CHECK^# == 3
33+
}
34+
}
35+
36+
// CHECK: Begin completions, 1 items
37+
// CHECK: Decl[InstanceVar]/CurrNominal: magnitude[#Float#]; name=magnitude
38+
// CHECK: End completions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
enum E {
5+
case foo, bar
6+
}
7+
let _: E = .#^COMPLETE^#
8+
9+
// COMPLETE: Begin completions, 3 items
10+
// COMPLETE-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: foo[#E#]; name=foo
11+
// COMPLETE-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: bar[#E#]; name=bar
12+
// COMPLETE-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): E#})[#(into: inout Hasher) -> Void#]; name=hash(:)
13+
// COMPLETE: End completions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
struct ButtonStyleConfiguration {}
5+
6+
protocol ButtonStyle {
7+
typealias Configuration = ButtonStyleConfiguration
8+
}
9+
10+
struct BorderedBarButtonStyle: ButtonStyle {
11+
init() { }
12+
func makeBody(configuration: #^COMPLETE^#) {}
13+
}
14+
15+
// COMPLETE: Begin completions
16+
// COMPLETE: Decl[TypeAlias]/Super: Configuration[#ButtonStyleConfiguration#]; name=Configuration
17+
// COMPLETE: End completions
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
public protocol View2 {
5+
associatedtype Body : View2
6+
@ViewBuilder2 var body: Self.Body { get }
7+
}
8+
9+
extension View2 {
10+
@inlinable public func frame(width: Int? = nil, height: Int? = nil) -> Never { fatalError() }
11+
12+
}
13+
14+
extension Never : View2 {}
15+
16+
extension Optional : View2 where Wrapped: View2 {
17+
public var body: Never {
18+
fatalError()
19+
}
20+
}
21+
22+
@resultBuilder public struct ViewBuilder2 {
23+
public static func buildBlock() -> Never { fatalError() }
24+
public static func buildBlock<Content>(_ content: Content) -> Content where Content : View2 { fatalError() }
25+
public static func buildIf<Content>(_ content: Content?) -> Content? where Content : View2 { fatalError() }
26+
public static func buildBlock<C0, C1>(_ c0: C0, _ c1: C1) -> Never where C0 : View2, C1 : View2 { fatalError() }
27+
}
28+
29+
public enum OutlineMenu2: Int {
30+
case popular
31+
}
32+
33+
public struct OutlineRow : View2 {
34+
let item: OutlineMenu2
35+
36+
public var body: some View2 {
37+
fatalError()
38+
}
39+
}
40+
41+
42+
public struct ForEach2<Content> {
43+
public var data: [OutlineMenu2]
44+
45+
public var content: (OutlineMenu2) -> Content
46+
}
47+
48+
extension ForEach2 : View2 {
49+
public var body: Never {
50+
fatalError()
51+
}
52+
public typealias Body = Never
53+
}
54+
55+
extension ForEach2 where Content : View2 {
56+
public init(_ data: [OutlineMenu2], @ViewBuilder2 content: @escaping (OutlineMenu2) -> Content) {
57+
fatalError()
58+
}
59+
}
60+
61+
struct SplitView: View2 {
62+
var body: some View2 {
63+
ForEach2([OutlineMenu2.popular]) { menu in
64+
OutlineRow(item: menu)
65+
.#^COMPLETE^#frame(height: 50)
66+
if true {
67+
}
68+
}
69+
}
70+
}
71+
72+
// COMPLETE: Begin completions
73+
// COMPLETE-DAG: Decl[InstanceMethod]/Super: frame()[#Never#]; name=frame()
74+
// COMPLETE-DAG: Decl[InstanceMethod]/Super: frame({#width: Int?#}, {#height: Int?#})[#Never#]; name=frame(width:height:)
75+
// COMPLETE: End completions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
struct TodayView {
5+
func foo() {
6+
Uext(verbatim: #^COMPLETE^#)
7+
}
8+
9+
private func dateString2() -> String {
10+
return "abc"
11+
}
12+
}
13+
14+
struct Uext {
15+
init(verbatim content: String)
16+
init<F : GormatStyle>(_ input: F.FormatInput) where F.FormatInput : Equatable
17+
}
18+
19+
protocol GormatStyle {
20+
associatedtype FormatInput
21+
}
22+
23+
// COMPLETE: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: dateString2()[#String#];

0 commit comments

Comments
 (0)