|
| 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 | +// RUN: %empty-directory(%t) |
| 9 | +// RUN: %{python} %utils/split_file.py -o %t %s |
| 10 | + |
| 11 | +// RUN: %target-swift-frontend %t/FileLogging.swift -module-name AppleLogging -module-alias XLogging=AppleLogging -emit-module -o %t/AppleLogging.swiftmodule |
| 12 | + |
| 13 | +// RUN: %target-swift-ide-test -code-completion -code-completion-token=MODULE_NAME -source-filename %t/FileLib1.swift -module-alias XLogging=AppleLogging -I %t > %t/result1.txt |
| 14 | +// RUN: %FileCheck %s -check-prefix CHECK1 < %t/result1.txt |
| 15 | + |
| 16 | +// CHECK1-NOT: AppleLogging |
| 17 | +// CHECK1: found code completion token MODULE_NAME at offset 43 |
| 18 | +// CHECK1: Begin completions, 335 items |
| 19 | +// CHECK1: Decl[Module]/None: XLogging[#Module#]; name=XLogging |
| 20 | +// CHECK1: Decl[Protocol]/OtherModule[XLogging]: Logging[#Logging#]; name=Logging |
| 21 | +// CHECK1: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger |
| 22 | +// CHECK1: End completions |
| 23 | + |
| 24 | + |
| 25 | +// RUN: %target-swift-ide-test -code-completion -code-completion-token=MODULE_NAME -source-filename %t/FileLib2.swift -module-alias XLogging=AppleLogging -I %t > %t/result2.txt |
| 26 | +// RUN: %FileCheck %s -check-prefix CHECK2 < %t/result2.txt |
| 27 | + |
| 28 | +// CHECK2-NOT: AppleLogging |
| 29 | +// CHECK2: found code completion token MODULE_NAME at offset 48 |
| 30 | +// CHECK2: Begin completions, 335 items |
| 31 | +// CHECK2: Decl[Module]/None: XLogging[#Module#]; name=XLogging |
| 32 | +// CHECK2: Decl[Protocol]/OtherModule[XLogging]: Logging[#Logging#]; name=Logging |
| 33 | +// CHECK2: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger |
| 34 | +// CHECK2: End completions |
| 35 | + |
| 36 | + |
| 37 | +// RUN: %target-swift-ide-test -code-completion -code-completion-token=MODULE_NAME -source-filename %t/FileLib3.swift -module-alias XLogging=AppleLogging -I %t > %t/result3.txt |
| 38 | +// RUN: %FileCheck %s -check-prefix CHECK3 < %t/result3.txt |
| 39 | + |
| 40 | +// CHECK3-NOT: AppleLogging |
| 41 | +// CHECK3: found code completion token MODULE_NAME at offset 49 |
| 42 | +// CHECK3: Begin completions, 516 items |
| 43 | +// CHECK3: Decl[Module]/None: XLogging[#Module#]; name=XLogging |
| 44 | +// CHECK3: Decl[Protocol]/OtherModule[XLogging]/Flair[RareType]: Logging[#Logging#]; name=Logging |
| 45 | +// CHECK3: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger |
| 46 | +// CHECK3: Decl[FreeFunction]/OtherModule[XLogging]: setupLogger()[#Logger?#]; name=setupLogger() |
| 47 | +// CHECK3: End completions |
| 48 | + |
| 49 | + |
| 50 | +// RUN: %target-swift-ide-test -code-completion -code-completion-token=MODULE_NAME -source-filename %t/FileLib4.swift -module-alias XLogging=AppleLogging -I %t > %t/result4.txt |
| 51 | +// RUN: %FileCheck %s -check-prefix CHECK4 < %t/result4.txt |
| 52 | + |
| 53 | +// CHECK4-NOT: AppleLogging |
| 54 | +// CHECK4: found code completion token MODULE_NAME at offset 58 |
| 55 | +// CHECK4: Begin completions, 3 items |
| 56 | +// CHECK4: Decl[Protocol]/OtherModule[XLogging]/Flair[RareType]: Logging[#Logging#]; name=Logging |
| 57 | +// CHECK4: Decl[Struct]/OtherModule[XLogging]: Logger[#Logger#]; name=Logger |
| 58 | +// CHECK4: Decl[FreeFunction]/OtherModule[XLogging]: setupLogger()[#Logger?#]; name=setupLogger() |
| 59 | +// CHECK4: End completions |
| 60 | + |
| 61 | +/// In the following, the module alias name should be shown as a module that can be imported instead of the real name |
| 62 | +/// |
| 63 | +// RUN: %target-swift-ide-test -code-completion -code-completion-token=MODULE_NAME -source-filename %t/FileLib5.swift -module-alias XLogging=AppleLogging -I %t > %t/result5.txt |
| 64 | +// RUN: %FileCheck %s -check-prefix CHECK5 < %t/result5.txt |
| 65 | + |
| 66 | +/// In search paths, only AppleLogging.swiftmodule exists, but when `-module-alias XLogging=AppleLogging` is passed, |
| 67 | +/// we want to only show XLogging as an option to import, not AppleLogging |
| 68 | +// CHECK5-NOT: AppleLogging |
| 69 | +// CHECK5: found code completion token MODULE_NAME at offset 7 |
| 70 | +// CHECK5: Begin completions, 233 items |
| 71 | +// CHECK5: Decl[Module]/None: XLogging[#Module#]; name=XLogging |
| 72 | +// CHECK5: End completions |
| 73 | + |
| 74 | + |
| 75 | +// RUN: %target-swift-ide-test -code-completion -code-completion-token=MODULE_NAME -source-filename %t/FileLib5.swift -I %t > %t/result6.txt |
| 76 | +// RUN: %FileCheck %s -check-prefix CHECK6 < %t/result6.txt |
| 77 | + |
| 78 | +/// In search paths, only AppleLogging.swiftmodule exists, and no module aliasing option is passed, so |
| 79 | +/// just show AppleLogging as one of the modules that can be imported |
| 80 | +// CHECK6-NOT: XLogging |
| 81 | +// CHECK6: found code completion token MODULE_NAME at offset 7 |
| 82 | +// CHECK6: Begin completions, 233 items |
| 83 | +// CHECK6: Decl[Module]/None: AppleLogging[#Module#]; name=AppleLogging |
| 84 | +// CHECK6: End completions |
| 85 | + |
| 86 | + |
| 87 | +// BEGIN FileLogging.swift |
| 88 | +public struct Logger { |
| 89 | + public init() {} |
| 90 | +} |
| 91 | + |
| 92 | +public protocol Logging { |
| 93 | + var content: String { get } |
| 94 | +} |
| 95 | + |
| 96 | +public func setupLogger() -> XLogging.Logger? { |
| 97 | + return Logger() |
| 98 | +} |
| 99 | + |
| 100 | +// BEGIN FileLib1.swift |
| 101 | +import XLogging |
| 102 | + |
| 103 | +class ModuleNameInClause: #^MODULE_NAME^# { |
| 104 | +} |
| 105 | + |
| 106 | +// BEGIN FileLib2.swift |
| 107 | +import XLogging |
| 108 | + |
| 109 | +func testModuleNameInDecl() -> #^MODULE_NAME^# { |
| 110 | +} |
| 111 | + |
| 112 | +// BEGIN FileLib3.swift |
| 113 | +import XLogging |
| 114 | + |
| 115 | +func testModuleNameInBody() { |
| 116 | + #^MODULE_NAME^# |
| 117 | +} |
| 118 | + |
| 119 | +// BEGIN FileLib4.swift |
| 120 | +import XLogging |
| 121 | + |
| 122 | +func testModuleNameInBody() { |
| 123 | + XLogging.#^MODULE_NAME^# |
| 124 | +} |
| 125 | + |
| 126 | +// BEGIN FileLib5.swift |
| 127 | +import #^MODULE_NAME^# |
| 128 | + |
0 commit comments