Skip to content

Commit fcb50d6

Browse files
committed
[SourceKit] Add more test cases for fast completions
1 parent 0f45267 commit fcb50d6

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

test/SourceKit/CodeComplete/complete_sequence.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,30 @@ func bar(arg: Bar) {
1717

1818
// NOTE: Tests for 'key.codecomplete.reuseastcontex' option.
1919

20+
// Disabled.
2021
// RUN: %sourcekitd-test \
2122
// RUN: -req=track-compiles == \
2223
// RUN: -req=complete -pos=12:11 %s -- %s == \
2324
// RUN: -req=complete -pos=15:11 %s -- %s > %t.response
2425
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
2526
// RUN: %FileCheck --check-prefix=TRACE_NORMAL %s < %t.response
2627

28+
// Enabled.
2729
// RUN: %sourcekitd-test \
2830
// RUN: -req=track-compiles == \
2931
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=12:11 %s -- %s == \
3032
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=15:11 %s -- %s > %t.response.reuseastcontext
3133
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.reuseastcontext
3234
// RUN: %FileCheck --check-prefix=TRACE_REUSEAST %s < %t.response.reuseastcontext
3335

36+
// Enabled - compiler argument mismatch.
37+
// RUN: %sourcekitd-test \
38+
// RUN: -req=track-compiles == \
39+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=12:11 %s -- %s -DNOTUSED == \
40+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=15:11 %s -- -DNOTUSED %s > %t.response.reuseastcontext_argmismatch
41+
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.reuseastcontext_argmismatch
42+
// RUN: %FileCheck --check-prefix=TRACE_NORMAL %s < %t.response.reuseastcontext_argmismatch
43+
3444
// RESULT-LABEL: key.results: [
3545
// RESULT-DAG: key.name: "fooMethod()"
3646
// RESULT-DAG: key.name: "self"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// BEGIN file1.swift
2+
class Foo {
3+
var x: Int
4+
var y: Int
5+
}
6+
7+
func foo(arg: Foo) {
8+
_ = arg.
9+
}
10+
11+
class Bar {
12+
var a: Int
13+
var b: Int
14+
func barMethod() {}
15+
}
16+
17+
// BEGIN file2.swift
18+
extension Foo {
19+
func fooMethod() {}
20+
}
21+
22+
func bar(arg: Bar) {
23+
_ = arg.
24+
}
25+
26+
extension Bar {
27+
func barMethod() {}
28+
}
29+
30+
// BEGIN dummy.swift
31+
32+
// RUN: %empty-directory(%t)
33+
// RUN: %{python} %utils/split_file.py -o %t %s
34+
35+
// RUN: %sourcekitd-test \
36+
// RUN: -req=track-compiles == \
37+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=7:11 %t/file1.swift -- %t/file1.swift %t/file2.swift == \
38+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=6:11 %t/file2.swift -- %t/file1.swift %t/file2.swift > %t.response
39+
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
40+
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response
41+
42+
// RESULT-LABEL: key.results: [
43+
// RESULT-DAG: key.name: "fooMethod()"
44+
// RESULT-DAG: key.name: "self"
45+
// RESULT-DAG: key.name: "x"
46+
// RESULT-DAG: key.name: "y"
47+
// RESULT: ]
48+
// RESULT-LABEL: key.results: [
49+
// RESULT-DAG: key.name: "barMethod()"
50+
// RESULT-DAG: key.name: "self"
51+
// RESULT-DAG: key.name: "a"
52+
// RESULT-DAG: key.name: "b"
53+
// RESULT: ]
54+
55+
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// BEGIN State1.swift
2+
// Initial state.
3+
class Foo {
4+
var x: Int
5+
var y: Int
6+
func fooMethod() {}
7+
}
8+
func foo(arg: Foo) {
9+
_ = arg.
10+
}
11+
12+
// BEGIN State2.swift
13+
// Compatible change: implemented 'Foo.fooMethod()', indentation change, added white line.
14+
class Foo {
15+
var x: Int
16+
var y: Int
17+
func fooMethod() {
18+
print(x + y)
19+
}
20+
}
21+
22+
func foo(arg: Foo) {
23+
_ = arg.
24+
}
25+
26+
// BEGIN State3.swift
27+
// Incompatible change: added 'Foo.z'
28+
class Foo {
29+
var x: Int
30+
var y: Int
31+
var z: Int
32+
func fooMethod() {
33+
print(x + y)
34+
}
35+
}
36+
37+
func foo(arg: Foo) {
38+
_ = arg.
39+
}
40+
41+
// BEGIN DUMMY.swift
42+
43+
// RUN: %empty-directory(%t)
44+
// RUN: %{python} %utils/split_file.py -o %t %s
45+
46+
// RUN: %sourcekitd-test \
47+
// RUN: -req=track-compiles == \
48+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=8:11 -name file.swift -text-input %t/State1.swift -- file.swift == \
49+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=11:13 -name file.swift -text-input %t/State2.swift -- file.swift == \
50+
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=12:13 -name file.swift -text-input %t/State3.swift -- file.swift > %t.response
51+
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
52+
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response
53+
54+
// RESULT-LABEL: key.results: [
55+
// RESULT-NOT: key.name: "z"
56+
// RESULT-DAG: key.name: "fooMethod()"
57+
// RESULT-DAG: key.name: "self"
58+
// RESULT-DAG: key.name: "x"
59+
// RESULT-DAG: key.name: "y"
60+
// RESULT: ]
61+
62+
// RESULT-LABEL: key.results: [
63+
// RESULT-NOT: key.name: "z"
64+
// RESULT-DAG: key.name: "fooMethod()"
65+
// RESULT-DAG: key.name: "self"
66+
// RESULT-DAG: key.name: "x"
67+
// RESULT-DAG: key.name: "y"
68+
// RESULT: ]
69+
70+
// RESULT-LABEL: key.results: [
71+
// RESULT-DAG: key.name: "fooMethod()"
72+
// RESULT-DAG: key.name: "self"
73+
// RESULT-DAG: key.name: "x"
74+
// RESULT-DAG: key.name: "y"
75+
// RESULT-DAG: key.name: "z"
76+
// RESULT: ]
77+
78+
// TRACE: key.notification: source.notification.compile-did-finish,
79+
// TRACE-NEXT: key.diagnostics: [
80+
// TRACE-NEXT: ]
81+
82+
// TRACE: key.notification: source.notification.compile-did-finish,
83+
// TRACE-NEXT: key.diagnostics: [
84+
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
85+
// TRACE: ]
86+
87+
// TRACE: key.notification: source.notification.compile-did-finish,
88+
// TRACE-NEXT: key.diagnostics: [
89+
// TRACE-NEXT: ]

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
573573
case SourceKitRequest::CodeComplete:
574574
sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestCodeComplete);
575575
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
576+
sourcekitd_request_dictionary_set_string(Req, KeyName, SemaName.c_str());
576577
addCodeCompleteOptions(Req, Opts);
577578
break;
578579

@@ -971,6 +972,8 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
971972
if (Opts.SourceText) {
972973
sourcekitd_request_dictionary_set_string(Req, KeySourceText,
973974
Opts.SourceText->c_str());
975+
sourcekitd_request_dictionary_set_string(Req, KeySourceFile,
976+
SemaName.c_str());
974977
}
975978

976979
if (!Opts.CompilerArgs.empty()) {

0 commit comments

Comments
 (0)