File tree Expand file tree Collapse file tree 3 files changed +34
-12
lines changed
Tests/GRPCCodeGenTests/Internal/Translator Expand file tree Collapse file tree 3 files changed +34
-12
lines changed Original file line number Diff line number Diff line change @@ -72,13 +72,23 @@ struct IDLToStructuredSwiftTranslator: Translator {
7272 }
7373 }
7474
75- let fileDescription = FileDescription (
76- topComment: . preFormatted( codeGenerationRequest. leadingTrivia) ,
77- imports: try self . makeImports (
75+ let imports : [ ImportDescription ]
76+ if codeBlocks. isEmpty {
77+ imports = [ ]
78+ codeBlocks. append (
79+ CodeBlock ( comment: . inline( " This file contained no services. " ) )
80+ )
81+ } else {
82+ imports = try self . makeImports (
7883 dependencies: codeGenerationRequest. dependencies,
7984 accessLevel: accessLevel,
8085 accessLevelOnImports: accessLevelOnImports
81- ) ,
86+ )
87+ }
88+
89+ let fileDescription = FileDescription (
90+ topComment: . preFormatted( codeGenerationRequest. leadingTrivia) ,
91+ imports: imports,
8292 codeBlocks: codeBlocks
8393 )
8494
Original file line number Diff line number Diff line change @@ -87,21 +87,14 @@ public struct SourceGenerator: Sendable {
8787 let translator = IDLToStructuredSwiftTranslator ( )
8888 let textRenderer = TextBasedRenderer ( indentation: self . config. indentation)
8989
90- var structuredSwiftRepresentation = try translator. translate (
90+ let structuredSwiftRepresentation = try translator. translate (
9191 codeGenerationRequest: request,
9292 accessLevel: self . config. accessLevel,
9393 accessLevelOnImports: self . config. accessLevelOnImports,
9494 client: self . config. client,
9595 server: self . config. server
9696 )
9797
98- if structuredSwiftRepresentation. file. contents. codeBlocks. isEmpty {
99- structuredSwiftRepresentation. file. contents. imports = [ ]
100- structuredSwiftRepresentation. file. contents. codeBlocks. append (
101- CodeBlock ( comment: . inline( " This file contained no services. " ) )
102- )
103- }
104-
10598 let sourceFile = try textRenderer. render ( structured: structuredSwiftRepresentation)
10699
107100 return sourceFile
Original file line number Diff line number Diff line change @@ -298,6 +298,25 @@ final class IDLToStructuredSwiftTranslatorSnippetBasedTests: XCTestCase {
298298 )
299299 }
300300
301+ func testEmptyFileGeneration( ) throws {
302+ let expectedSwift =
303+ """
304+ /// Some really exciting license header 2023.
305+
306+
307+ // This file contained no services.
308+ """
309+ try self . assertIDLToStructuredSwiftTranslation (
310+ codeGenerationRequest: makeCodeGenerationRequest (
311+ services: [ ] ,
312+ dependencies: [ ]
313+ ) ,
314+ expectedSwift: expectedSwift,
315+ accessLevel: . public,
316+ server: true
317+ )
318+ }
319+
301320 private func assertIDLToStructuredSwiftTranslation(
302321 codeGenerationRequest: CodeGenerationRequest ,
303322 expectedSwift: String ,
You can’t perform that action at this time.
0 commit comments