Skip to content

Commit 0ff4195

Browse files
committed
Add repl code complete tests
1 parent 93132b8 commit 0ff4195

File tree

3 files changed

+126
-12
lines changed

3 files changed

+126
-12
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/// Test code completion with module aliasing
2+
/// When -module-alias <alias_name>=<real_name> is applied, code completion should show
3+
/// the <alias_name> as that's the name which should appear in source files including import statements,
4+
/// decls, expressions, etc. while getting visible decls come from the module of <real_name>.
5+
/// Below, XLogging is the alias and mapped to the real name AppleLogging. Note that the real name
6+
/// AppleLogging should not appear in the code completion results.
7+
///
8+
9+
10+
// BEGIN FileLogging.swift
11+
public struct Logger {
12+
public init() {}
13+
}
14+
15+
public protocol Logging {
16+
var content: String { get }
17+
}
18+
19+
public func setupLogger() -> XLogging.Logger? {
20+
return Logger()
21+
}
22+
23+
// BEGIN FileLib1.swift
24+
import XLogging
25+
26+
class ModuleNameInClause: #^MODULE_NAME1^# {
27+
}
28+
29+
// BEGIN FileLib2.swift
30+
import XLogging
31+
32+
func testModuleNameInDecl() -> #^MODULE_NAME2^# {
33+
}
34+
35+
// BEGIN FileLib3.swift
36+
import XLogging
37+
38+
func test() {
39+
let x = #^EXPR^#
40+
}
41+
42+
// BEGIN FileLib4.swift
43+
import XLogging
44+
45+
func testModuleNameInBody() {
46+
XLogging.#^MODULE_NAME4^#
47+
}
48+
49+
// BEGIN FileLib5.swift
50+
import #^MODULE_NAME5^#
51+
52+
53+
// EXPR: Begin completion
54+
// EXPR-NOT: AppleLogging
55+
// EXPR-DAG: Decl[Module]/None: XLogging[#Module#]; name=XLogging
56+
// EXPR-DAG: Decl[Protocol]/OtherModule[XLogging]: Logging[#Logging#]; name=Logging
57+
// EXPR-DAG: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger
58+
// EXPR: End completions
59+
60+
61+
// RUN: %empty-directory(%t)
62+
// RUN: %{python} %utils/split_file.py -o %t %s
63+
64+
// RUN: %empty-directory(%t/modules)
65+
// RUN: %target-swift-frontend %t/FileLogging.swift -module-name AppleLogging -module-alias XLogging=AppleLogging -emit-module -o %t/modules/AppleLogging.swiftmodule
66+
67+
// RUN: %empty-directory(%t/output)
68+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %t/FileLib3.swift -module-alias XLogging=AppleLogging -filecheck %raw-FileCheck -completion-output-dir %t/output -I %t/modules

test/IDE/module-aliasing-code-complete.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// RUN: %FileCheck %s -check-prefix CHECK1 < %t/result1.txt
1515

1616
// CHECK1-NOT: AppleLogging
17-
// CHECK1: found code completion token MODULE_NAME at offset 43
18-
// CHECK1: Begin completions, 335 items
17+
// CHECK1: found code completion token MODULE_NAME
18+
// CHECK1: Begin completions
1919
// CHECK1: Decl[Module]/None: XLogging[#Module#]; name=XLogging
2020
// CHECK1: Decl[Protocol]/OtherModule[XLogging]: Logging[#Logging#]; name=Logging
2121
// CHECK1: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger
@@ -26,8 +26,8 @@
2626
// RUN: %FileCheck %s -check-prefix CHECK2 < %t/result2.txt
2727

2828
// CHECK2-NOT: AppleLogging
29-
// CHECK2: found code completion token MODULE_NAME at offset 48
30-
// CHECK2: Begin completions, 335 items
29+
// CHECK2: found code completion token MODULE_NAME
30+
// CHECK2: Begin completions
3131
// CHECK2: Decl[Module]/None: XLogging[#Module#]; name=XLogging
3232
// CHECK2: Decl[Protocol]/OtherModule[XLogging]: Logging[#Logging#]; name=Logging
3333
// CHECK2: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger
@@ -38,8 +38,8 @@
3838
// RUN: %FileCheck %s -check-prefix CHECK3 < %t/result3.txt
3939

4040
// CHECK3-NOT: AppleLogging
41-
// CHECK3: found code completion token MODULE_NAME at offset 49
42-
// CHECK3: Begin completions, 516 items
41+
// CHECK3: found code completion token MODULE_NAME
42+
// CHECK3: Begin completions
4343
// CHECK3: Decl[Module]/None: XLogging[#Module#]; name=XLogging
4444
// CHECK3: Decl[Protocol]/OtherModule[XLogging]/Flair[RareType]: Logging[#Logging#]; name=Logging
4545
// CHECK3: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger
@@ -51,8 +51,8 @@
5151
// RUN: %FileCheck %s -check-prefix CHECK4 < %t/result4.txt
5252

5353
// CHECK4-NOT: AppleLogging
54-
// CHECK4: found code completion token MODULE_NAME at offset 58
55-
// CHECK4: Begin completions, 3 items
54+
// CHECK4: found code completion token MODULE_NAME
55+
// CHECK4: Begin completions
5656
// CHECK4: Decl[Protocol]/OtherModule[XLogging]/Flair[RareType]: Logging[#Logging#]; name=Logging
5757
// CHECK4: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger
5858
// CHECK4: Decl[FreeFunction]/OtherModule[XLogging]: setupLogger()[#Logger?#]; name=setupLogger()
@@ -66,8 +66,8 @@
6666
/// In search paths, only AppleLogging.swiftmodule exists, but when `-module-alias XLogging=AppleLogging` is passed,
6767
/// we want to only show XLogging as an option to import, not AppleLogging
6868
// CHECK5-NOT: AppleLogging
69-
// CHECK5: found code completion token MODULE_NAME at offset 7
70-
// CHECK5: Begin completions, 233 items
69+
// CHECK5: found code completion token MODULE_NAME
70+
// CHECK5: Begin completions
7171
// CHECK5: Decl[Module]/None: XLogging[#Module#]; name=XLogging
7272
// CHECK5: End completions
7373

@@ -78,8 +78,8 @@
7878
/// In search paths, only AppleLogging.swiftmodule exists, and no module aliasing option is passed, so
7979
/// just show AppleLogging as one of the modules that can be imported
8080
// CHECK6-NOT: XLogging
81-
// CHECK6: found code completion token MODULE_NAME at offset 7
82-
// CHECK6: Begin completions, 233 items
81+
// CHECK6: found code completion token MODULE_NAME
82+
// CHECK6: Begin completions
8383
// CHECK6: Decl[Module]/None: AppleLogging[#Module#]; name=AppleLogging
8484
// CHECK6: End completions
8585

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// Test REPL code completion with module aliasing
2+
/// When -module-alias <alias_name>=<real_name> is applied, code completion should show
3+
/// the <alias_name> as that's the name which should appear in source files including import statements,
4+
/// decls, expressions, etc. while getting visible decls come from the module of <real_name>, which
5+
/// is the name of the binary.
6+
/// Below, XLogging is the alias and mapped to the real name AppleLogging. Note that the binary name
7+
/// AppleLogging should not appear in the code completion results.
8+
///
9+
// RUN: %empty-directory(%t)
10+
// RUN: %{python} %utils/split_file.py -o %t %s
11+
12+
// RUN: %target-swift-frontend %t/FileLogging.swift -module-name AppleLogging -module-alias XLogging=AppleLogging -emit-module -o %t/AppleLogging.swiftmodule
13+
14+
// RUN: %target-swift-ide-test -repl-code-completion -source-filename %t/FileLib1.swift -module-alias XLogging=AppleLogging -I %t > %t/result1.txt
15+
// RUN: %FileCheck %s < %t/result1.txt
16+
17+
// RUN: %target-swift-ide-test -repl-code-completion -source-filename %t/FileLib2.swift -module-alias XLogging=AppleLogging -I %t > %t/result2.txt
18+
// RUN: %FileCheck %s < %t/result2.txt
19+
20+
// CHECK: Begin completions
21+
// CHECK-NOT: AppleLogging
22+
// CHECK-DAG: XLogging
23+
// CHECK: End completions
24+
25+
// BEGIN FileLogging.swift
26+
public struct Logger {
27+
public init() {}
28+
}
29+
30+
public protocol Logging {
31+
var content: String { get }
32+
}
33+
34+
public func setupLogger() -> XLogging.Logger? {
35+
return Logger()
36+
}
37+
38+
// BEGIN FileLib1.swift
39+
import
40+
41+
// BEGIN FileLib2.swift
42+
import XLogging
43+
func f() {
44+
X
45+
}
46+

0 commit comments

Comments
 (0)