From 0b563e4a40dd4d08b5c1ccaf86b7b9a9b71d3434 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Mon, 30 Jan 2017 13:07:30 +0100 Subject: [PATCH 1/4] move files --- templates/{colors-default.stencil => colors/default.stencil} | 0 templates/{colors-rawValue.stencil => colors/rawValue.stencil} | 0 templates/{colors-swift3.stencil => colors/swift3.stencil} | 0 templates/{fonts-default.stencil => fonts/default.stencil} | 0 templates/{fonts-swift3.stencil => fonts/swift3.stencil} | 0 templates/{images-allvalues.stencil => images/allvalues.stencil} | 0 templates/{images-default.stencil => images/default.stencil} | 0 .../dot-syntax-swift3.stencil} | 0 .../{images-dot-syntax.stencil => images/dot-syntax.stencil} | 0 templates/{images-swift3.stencil => images/swift3.stencil} | 0 .../{storyboards-default.stencil => storyboards/default.stencil} | 0 .../lowercase.stencil} | 0 .../osx-default.stencil} | 0 .../osx-lowercase.stencil} | 0 .../osx-swift3.stencil} | 0 .../{storyboards-swift3.stencil => storyboards/swift3.stencil} | 0 .../uppercase.stencil} | 0 templates/{strings-default.stencil => strings/default.stencil} | 0 .../dot-syntax-swift3.stencil} | 0 .../{strings-dot-syntax.stencil => strings/dot-syntax.stencil} | 0 .../{strings-genstrings.stencil => strings/genstrings.stencil} | 0 .../no-comments-swift3.stencil} | 0 .../{strings-structured.stencil => strings/structured.stencil} | 0 templates/{strings-swift3.stencil => strings/swift3.stencil} | 0 24 files changed, 0 insertions(+), 0 deletions(-) rename templates/{colors-default.stencil => colors/default.stencil} (100%) rename templates/{colors-rawValue.stencil => colors/rawValue.stencil} (100%) rename templates/{colors-swift3.stencil => colors/swift3.stencil} (100%) rename templates/{fonts-default.stencil => fonts/default.stencil} (100%) rename templates/{fonts-swift3.stencil => fonts/swift3.stencil} (100%) rename templates/{images-allvalues.stencil => images/allvalues.stencil} (100%) rename templates/{images-default.stencil => images/default.stencil} (100%) rename templates/{images-dot-syntax-swift3.stencil => images/dot-syntax-swift3.stencil} (100%) rename templates/{images-dot-syntax.stencil => images/dot-syntax.stencil} (100%) rename templates/{images-swift3.stencil => images/swift3.stencil} (100%) rename templates/{storyboards-default.stencil => storyboards/default.stencil} (100%) rename templates/{storyboards-lowercase.stencil => storyboards/lowercase.stencil} (100%) rename templates/{storyboards-osx-default.stencil => storyboards/osx-default.stencil} (100%) rename templates/{storyboards-osx-lowercase.stencil => storyboards/osx-lowercase.stencil} (100%) rename templates/{storyboards-osx-swift3.stencil => storyboards/osx-swift3.stencil} (100%) rename templates/{storyboards-swift3.stencil => storyboards/swift3.stencil} (100%) rename templates/{storyboards-uppercase.stencil => storyboards/uppercase.stencil} (100%) rename templates/{strings-default.stencil => strings/default.stencil} (100%) rename templates/{strings-dot-syntax-swift3.stencil => strings/dot-syntax-swift3.stencil} (100%) rename templates/{strings-dot-syntax.stencil => strings/dot-syntax.stencil} (100%) rename templates/{strings-genstrings.stencil => strings/genstrings.stencil} (100%) rename templates/{strings-no-comments-swift3.stencil => strings/no-comments-swift3.stencil} (100%) rename templates/{strings-structured.stencil => strings/structured.stencil} (100%) rename templates/{strings-swift3.stencil => strings/swift3.stencil} (100%) diff --git a/templates/colors-default.stencil b/templates/colors/default.stencil similarity index 100% rename from templates/colors-default.stencil rename to templates/colors/default.stencil diff --git a/templates/colors-rawValue.stencil b/templates/colors/rawValue.stencil similarity index 100% rename from templates/colors-rawValue.stencil rename to templates/colors/rawValue.stencil diff --git a/templates/colors-swift3.stencil b/templates/colors/swift3.stencil similarity index 100% rename from templates/colors-swift3.stencil rename to templates/colors/swift3.stencil diff --git a/templates/fonts-default.stencil b/templates/fonts/default.stencil similarity index 100% rename from templates/fonts-default.stencil rename to templates/fonts/default.stencil diff --git a/templates/fonts-swift3.stencil b/templates/fonts/swift3.stencil similarity index 100% rename from templates/fonts-swift3.stencil rename to templates/fonts/swift3.stencil diff --git a/templates/images-allvalues.stencil b/templates/images/allvalues.stencil similarity index 100% rename from templates/images-allvalues.stencil rename to templates/images/allvalues.stencil diff --git a/templates/images-default.stencil b/templates/images/default.stencil similarity index 100% rename from templates/images-default.stencil rename to templates/images/default.stencil diff --git a/templates/images-dot-syntax-swift3.stencil b/templates/images/dot-syntax-swift3.stencil similarity index 100% rename from templates/images-dot-syntax-swift3.stencil rename to templates/images/dot-syntax-swift3.stencil diff --git a/templates/images-dot-syntax.stencil b/templates/images/dot-syntax.stencil similarity index 100% rename from templates/images-dot-syntax.stencil rename to templates/images/dot-syntax.stencil diff --git a/templates/images-swift3.stencil b/templates/images/swift3.stencil similarity index 100% rename from templates/images-swift3.stencil rename to templates/images/swift3.stencil diff --git a/templates/storyboards-default.stencil b/templates/storyboards/default.stencil similarity index 100% rename from templates/storyboards-default.stencil rename to templates/storyboards/default.stencil diff --git a/templates/storyboards-lowercase.stencil b/templates/storyboards/lowercase.stencil similarity index 100% rename from templates/storyboards-lowercase.stencil rename to templates/storyboards/lowercase.stencil diff --git a/templates/storyboards-osx-default.stencil b/templates/storyboards/osx-default.stencil similarity index 100% rename from templates/storyboards-osx-default.stencil rename to templates/storyboards/osx-default.stencil diff --git a/templates/storyboards-osx-lowercase.stencil b/templates/storyboards/osx-lowercase.stencil similarity index 100% rename from templates/storyboards-osx-lowercase.stencil rename to templates/storyboards/osx-lowercase.stencil diff --git a/templates/storyboards-osx-swift3.stencil b/templates/storyboards/osx-swift3.stencil similarity index 100% rename from templates/storyboards-osx-swift3.stencil rename to templates/storyboards/osx-swift3.stencil diff --git a/templates/storyboards-swift3.stencil b/templates/storyboards/swift3.stencil similarity index 100% rename from templates/storyboards-swift3.stencil rename to templates/storyboards/swift3.stencil diff --git a/templates/storyboards-uppercase.stencil b/templates/storyboards/uppercase.stencil similarity index 100% rename from templates/storyboards-uppercase.stencil rename to templates/storyboards/uppercase.stencil diff --git a/templates/strings-default.stencil b/templates/strings/default.stencil similarity index 100% rename from templates/strings-default.stencil rename to templates/strings/default.stencil diff --git a/templates/strings-dot-syntax-swift3.stencil b/templates/strings/dot-syntax-swift3.stencil similarity index 100% rename from templates/strings-dot-syntax-swift3.stencil rename to templates/strings/dot-syntax-swift3.stencil diff --git a/templates/strings-dot-syntax.stencil b/templates/strings/dot-syntax.stencil similarity index 100% rename from templates/strings-dot-syntax.stencil rename to templates/strings/dot-syntax.stencil diff --git a/templates/strings-genstrings.stencil b/templates/strings/genstrings.stencil similarity index 100% rename from templates/strings-genstrings.stencil rename to templates/strings/genstrings.stencil diff --git a/templates/strings-no-comments-swift3.stencil b/templates/strings/no-comments-swift3.stencil similarity index 100% rename from templates/strings-no-comments-swift3.stencil rename to templates/strings/no-comments-swift3.stencil diff --git a/templates/strings-structured.stencil b/templates/strings/structured.stencil similarity index 100% rename from templates/strings-structured.stencil rename to templates/strings/structured.stencil diff --git a/templates/strings-swift3.stencil b/templates/strings/swift3.stencil similarity index 100% rename from templates/strings-swift3.stencil rename to templates/strings/swift3.stencil From 49e7b8643856ef49bed74a0e1f1b70f20f5abfc3 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Mon, 30 Jan 2017 13:18:46 +0100 Subject: [PATCH 2/4] adapt tests --- Tests/TemplatesTests/ColorsTests.swift | 6 +++--- Tests/TemplatesTests/FontsTests.swift | 4 ++-- Tests/TemplatesTests/ImagesTests.swift | 10 +++++----- .../StoryboardsMacOSTests.swift | 15 ++++++++------ .../TemplatesTests/StoryboardsiOSTests.swift | 20 +++++++++++-------- Tests/TemplatesTests/StringsTests.swift | 14 ++++++------- Tests/TemplatesTests/TestsHelper.swift | 15 +++++++++----- 7 files changed, 48 insertions(+), 36 deletions(-) diff --git a/Tests/TemplatesTests/ColorsTests.swift b/Tests/TemplatesTests/ColorsTests.swift index 6c836b7..54134d7 100644 --- a/Tests/TemplatesTests/ColorsTests.swift +++ b/Tests/TemplatesTests/ColorsTests.swift @@ -13,21 +13,21 @@ class ColorsTests: XCTestCase { } func testDefault() { - test(template: "colors-default", + test(template: "default", contextNames: Contexts.all, outputPrefix: "default", directory: .colors) } func testRawValue() { - test(template: "colors-rawValue", + test(template: "rawValue", contextNames: Contexts.rawOnly, outputPrefix: "rawValue", directory: .colors) } func testSwift3() { - test(template: "colors-swift3", + test(template: "swift3", contextNames: Contexts.all, outputPrefix: "swift3", directory: .colors) diff --git a/Tests/TemplatesTests/FontsTests.swift b/Tests/TemplatesTests/FontsTests.swift index 85646dc..b4bf437 100644 --- a/Tests/TemplatesTests/FontsTests.swift +++ b/Tests/TemplatesTests/FontsTests.swift @@ -14,14 +14,14 @@ class FontsTests: XCTestCase { } func testDefault() { - test(template: "fonts-default", + test(template: "default", contextNames: Contexts.all, outputPrefix: "default", directory: .fonts) } func testSwift3() { - test(template: "fonts-swift3", + test(template: "swift3", contextNames: Contexts.all, outputPrefix: "swift3", directory: .fonts) diff --git a/Tests/TemplatesTests/ImagesTests.swift b/Tests/TemplatesTests/ImagesTests.swift index 906cd39..e295d86 100644 --- a/Tests/TemplatesTests/ImagesTests.swift +++ b/Tests/TemplatesTests/ImagesTests.swift @@ -12,35 +12,35 @@ class ImagesTests: XCTestCase { } func testDefault() { - test(template: "images-default", + test(template: "default", contextNames: Contexts.all, outputPrefix: "default", directory: .images) } func testAllValues() { - test(template: "images-allvalues", + test(template: "allvalues", contextNames: Contexts.all, outputPrefix: "allvalues", directory: .images) } func testSwift3() { - test(template: "images-swift3", + test(template: "swift3", contextNames: Contexts.all, outputPrefix: "swift3", directory: .images) } func testDotSyntax() { - test(template: "images-dot-syntax", + test(template: "dot-syntax", contextNames: Contexts.all, outputPrefix: "dot-syntax", directory: .images) } func testDotSyntaxSwift3() { - test(template: "images-dot-syntax-swift3", + test(template: "dot-syntax-swift3", contextNames: Contexts.all, outputPrefix: "dot-syntax-swift3", directory: .images) diff --git a/Tests/TemplatesTests/StoryboardsMacOSTests.swift b/Tests/TemplatesTests/StoryboardsMacOSTests.swift index 54c499f..d6e95bb 100644 --- a/Tests/TemplatesTests/StoryboardsMacOSTests.swift +++ b/Tests/TemplatesTests/StoryboardsMacOSTests.swift @@ -12,23 +12,26 @@ class StoryboardsMacOSTests: XCTestCase { } func testDefault() { - test(template: "storyboards-osx-default", + test(template: "osx-default", contextNames: Contexts.all, outputPrefix: "default", - directory: .storyboardsMacOS) + directory: .storyboards, + resourceDirectory: .storyboardsMacOS) } func testSwift3() { - test(template: "storyboards-osx-swift3", + test(template: "osx-swift3", contextNames: Contexts.all, outputPrefix: "swift3", - directory: .storyboardsMacOS) + directory: .storyboards, + resourceDirectory: .storyboardsMacOS) } func testLowercase() { - test(template: "storyboards-osx-lowercase", + test(template: "osx-lowercase", contextNames: Contexts.all, outputPrefix: "lowercase", - directory: .storyboardsMacOS) + directory: .storyboards, + resourceDirectory: .storyboardsMacOS) } } diff --git a/Tests/TemplatesTests/StoryboardsiOSTests.swift b/Tests/TemplatesTests/StoryboardsiOSTests.swift index 2be03b6..14031cf 100644 --- a/Tests/TemplatesTests/StoryboardsiOSTests.swift +++ b/Tests/TemplatesTests/StoryboardsiOSTests.swift @@ -41,34 +41,38 @@ class StoryboardsiOSTests: XCTestCase { } func testDefault() { - test(template: "storyboards-default", + test(template: "default", contextNames: Contexts.all, outputPrefix: "default", - directory: .storyboardsiOS, + directory: .storyboards, + resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) } func testSwift3() { - test(template: "storyboards-swift3", + test(template: "swift3", contextNames: Contexts.all, outputPrefix: "swift3", - directory: .storyboardsiOS, + directory: .storyboards, + resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) } func testLowercase() { - test(template: "storyboards-lowercase", + test(template: "lowercase", contextNames: Contexts.all, outputPrefix: "lowercase", - directory: .storyboardsiOS, + directory: .storyboards, + resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) } func testUppercase() { - test(template: "storyboards-uppercase", + test(template: "uppercase", contextNames: Contexts.all, outputPrefix: "uppercase", - directory: .storyboardsiOS, + directory: .storyboards, + resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) } } diff --git a/Tests/TemplatesTests/StringsTests.swift b/Tests/TemplatesTests/StringsTests.swift index 2ad653f..151d191 100644 --- a/Tests/TemplatesTests/StringsTests.swift +++ b/Tests/TemplatesTests/StringsTests.swift @@ -12,49 +12,49 @@ class StringsTests: XCTestCase { } func testDefault() { - test(template: "strings-default", + test(template: "default", contextNames: Contexts.all, outputPrefix: "default", directory: .strings) } func testSwift3() { - test(template: "strings-swift3", + test(template: "swift3", contextNames: Contexts.all, outputPrefix: "swift3", directory: .strings) } func testNoCommentsSwift3() { - test(template: "strings-no-comments-swift3", + test(template: "no-comments-swift3", contextNames: Contexts.all, outputPrefix: "no-comments-swift3", directory: .strings) } func testGenstrings() { - test(template: "strings-genstrings", + test(template: "genstrings", contextNames: Contexts.all, outputPrefix: "genstrings", directory: .strings) } func testStructured() { - test(template: "strings-structured", + test(template: "structured", contextNames: Contexts.all, outputPrefix: "structured", directory: .strings) } func testDotSyntax() { - test(template: "strings-dot-syntax", + test(template: "dot-syntax", contextNames: Contexts.all, outputPrefix: "dot-syntax", directory: .strings) } func testDotSyntaxSwift3() { - test(template: "strings-dot-syntax-swift3", + test(template: "dot-syntax-swift3", contextNames: Contexts.all, outputPrefix: "dot-syntax-swift3", directory: .strings) diff --git a/Tests/TemplatesTests/TestsHelper.swift b/Tests/TemplatesTests/TestsHelper.swift index aa8565f..3bf70e0 100644 --- a/Tests/TemplatesTests/TestsHelper.swift +++ b/Tests/TemplatesTests/TestsHelper.swift @@ -71,6 +71,7 @@ class Fixtures { case colors = "Colors" case fonts = "Fonts" case images = "Images" + case storyboards = "Storyboards" case storyboardsiOS = "Storyboards-iOS" case storyboardsMacOS = "Storyboards-macOS" case strings = "Strings" @@ -110,8 +111,8 @@ class Fixtures { return data } - static func template(for name: String) -> String { - return string(for: name, subDirectory: "templates") + static func template(for name: String, sub: Directory) -> String { + return string(for: name, subDirectory: "templates/\(sub.rawValue.lowercased())") } static func output(for name: String, sub: Directory) -> String { @@ -144,26 +145,30 @@ extension XCTestCase { - Parameter contextNames: A list of context names (without the `plist` extension) - Parameter outputPrefix: Prefix for the output files, becomes "{outputPrefix}-context-{contextName}.swift" - Parameter directory: The directory to look for files in (correspons to de command) + - Parameter resourceDirectory: The directory to look for files in (corresponds to de command) - Parameter contextVariations: Optional closure to generate context variations. */ func test(template templateName: String, contextNames: [String], outputPrefix: String, directory: Fixtures.Directory, + resourceDirectory: Fixtures.Directory? = nil, contextVariations: VariationGenerator? = nil) { - let template = StencilSwiftTemplate(templateString: Fixtures.template(for: "\(templateName).stencil"), + let templateString = Fixtures.template(for: "\(templateName).stencil", sub: directory) + let template = StencilSwiftTemplate(templateString: templateString, environment: stencilSwiftEnvironment()) let contextVariations = contextVariations ?? { [(context: $1, suffix: "")] } + let resourceDir = resourceDirectory ?? directory for contextName in contextNames { print("Testing context '\(contextName)'...") - let context = Fixtures.context(for: "\(contextName).plist", sub: directory) + let context = Fixtures.context(for: "\(contextName).plist", sub: resourceDir) for (context, suffix) in contextVariations(contextName, context) { guard let result = try? template.render(context) else { fatalError("Unable to render template") } - let expected = Fixtures.output(for: "\(outputPrefix)-context-\(contextName)\(suffix).swift", sub: directory) + let expected = Fixtures.output(for: "\(outputPrefix)-context-\(contextName)\(suffix).swift", sub: resourceDir) XCTDiffStrings(result, expected) } } From ae209bd8bf6467797c975ce50e73b83a5bc5e54a Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sun, 19 Feb 2017 16:19:17 +0100 Subject: [PATCH 3/4] simplify test command a bit --- Tests/TemplatesTests/ColorsTests.swift | 3 --- Tests/TemplatesTests/FontsTests.swift | 2 -- Tests/TemplatesTests/ImagesTests.swift | 5 ----- Tests/TemplatesTests/StoryboardsiOSTests.swift | 4 ---- Tests/TemplatesTests/StringsTests.swift | 7 ------- Tests/TemplatesTests/TestsHelper.swift | 10 +++++++--- 6 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Tests/TemplatesTests/ColorsTests.swift b/Tests/TemplatesTests/ColorsTests.swift index 54134d7..8e0426c 100644 --- a/Tests/TemplatesTests/ColorsTests.swift +++ b/Tests/TemplatesTests/ColorsTests.swift @@ -15,21 +15,18 @@ class ColorsTests: XCTestCase { func testDefault() { test(template: "default", contextNames: Contexts.all, - outputPrefix: "default", directory: .colors) } func testRawValue() { test(template: "rawValue", contextNames: Contexts.rawOnly, - outputPrefix: "rawValue", directory: .colors) } func testSwift3() { test(template: "swift3", contextNames: Contexts.all, - outputPrefix: "swift3", directory: .colors) } } diff --git a/Tests/TemplatesTests/FontsTests.swift b/Tests/TemplatesTests/FontsTests.swift index b4bf437..90f62b8 100644 --- a/Tests/TemplatesTests/FontsTests.swift +++ b/Tests/TemplatesTests/FontsTests.swift @@ -16,14 +16,12 @@ class FontsTests: XCTestCase { func testDefault() { test(template: "default", contextNames: Contexts.all, - outputPrefix: "default", directory: .fonts) } func testSwift3() { test(template: "swift3", contextNames: Contexts.all, - outputPrefix: "swift3", directory: .fonts) } } diff --git a/Tests/TemplatesTests/ImagesTests.swift b/Tests/TemplatesTests/ImagesTests.swift index e295d86..17ac741 100644 --- a/Tests/TemplatesTests/ImagesTests.swift +++ b/Tests/TemplatesTests/ImagesTests.swift @@ -14,35 +14,30 @@ class ImagesTests: XCTestCase { func testDefault() { test(template: "default", contextNames: Contexts.all, - outputPrefix: "default", directory: .images) } func testAllValues() { test(template: "allvalues", contextNames: Contexts.all, - outputPrefix: "allvalues", directory: .images) } func testSwift3() { test(template: "swift3", contextNames: Contexts.all, - outputPrefix: "swift3", directory: .images) } func testDotSyntax() { test(template: "dot-syntax", contextNames: Contexts.all, - outputPrefix: "dot-syntax", directory: .images) } func testDotSyntaxSwift3() { test(template: "dot-syntax-swift3", contextNames: Contexts.all, - outputPrefix: "dot-syntax-swift3", directory: .images) } } diff --git a/Tests/TemplatesTests/StoryboardsiOSTests.swift b/Tests/TemplatesTests/StoryboardsiOSTests.swift index 14031cf..f8af33e 100644 --- a/Tests/TemplatesTests/StoryboardsiOSTests.swift +++ b/Tests/TemplatesTests/StoryboardsiOSTests.swift @@ -43,7 +43,6 @@ class StoryboardsiOSTests: XCTestCase { func testDefault() { test(template: "default", contextNames: Contexts.all, - outputPrefix: "default", directory: .storyboards, resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) @@ -52,7 +51,6 @@ class StoryboardsiOSTests: XCTestCase { func testSwift3() { test(template: "swift3", contextNames: Contexts.all, - outputPrefix: "swift3", directory: .storyboards, resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) @@ -61,7 +59,6 @@ class StoryboardsiOSTests: XCTestCase { func testLowercase() { test(template: "lowercase", contextNames: Contexts.all, - outputPrefix: "lowercase", directory: .storyboards, resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) @@ -70,7 +67,6 @@ class StoryboardsiOSTests: XCTestCase { func testUppercase() { test(template: "uppercase", contextNames: Contexts.all, - outputPrefix: "uppercase", directory: .storyboards, resourceDirectory: .storyboardsiOS, contextVariations: StoryboardsiOSTests.variations) diff --git a/Tests/TemplatesTests/StringsTests.swift b/Tests/TemplatesTests/StringsTests.swift index 151d191..4ed3df1 100644 --- a/Tests/TemplatesTests/StringsTests.swift +++ b/Tests/TemplatesTests/StringsTests.swift @@ -14,49 +14,42 @@ class StringsTests: XCTestCase { func testDefault() { test(template: "default", contextNames: Contexts.all, - outputPrefix: "default", directory: .strings) } func testSwift3() { test(template: "swift3", contextNames: Contexts.all, - outputPrefix: "swift3", directory: .strings) } func testNoCommentsSwift3() { test(template: "no-comments-swift3", contextNames: Contexts.all, - outputPrefix: "no-comments-swift3", directory: .strings) } func testGenstrings() { test(template: "genstrings", contextNames: Contexts.all, - outputPrefix: "genstrings", directory: .strings) } func testStructured() { test(template: "structured", contextNames: Contexts.all, - outputPrefix: "structured", directory: .strings) } func testDotSyntax() { test(template: "dot-syntax", contextNames: Contexts.all, - outputPrefix: "dot-syntax", directory: .strings) } func testDotSyntaxSwift3() { test(template: "dot-syntax-swift3", contextNames: Contexts.all, - outputPrefix: "dot-syntax-swift3", directory: .strings) } } diff --git a/Tests/TemplatesTests/TestsHelper.swift b/Tests/TemplatesTests/TestsHelper.swift index 3bf70e0..a787819 100644 --- a/Tests/TemplatesTests/TestsHelper.swift +++ b/Tests/TemplatesTests/TestsHelper.swift @@ -143,21 +143,25 @@ extension XCTestCase { - Parameter template: The name of the template (without the `stencil` extension) - Parameter contextNames: A list of context names (without the `plist` extension) - - Parameter outputPrefix: Prefix for the output files, becomes "{outputPrefix}-context-{contextName}.swift" + - Parameter outputPrefix: Prefix for the output files, becomes "{outputPrefix}-context-{contextName}.swift". + Defaults to template name. - Parameter directory: The directory to look for files in (correspons to de command) - Parameter resourceDirectory: The directory to look for files in (corresponds to de command) - Parameter contextVariations: Optional closure to generate context variations. */ func test(template templateName: String, contextNames: [String], - outputPrefix: String, + outputPrefix: String? = nil, directory: Fixtures.Directory, resourceDirectory: Fixtures.Directory? = nil, contextVariations: VariationGenerator? = nil) { let templateString = Fixtures.template(for: "\(templateName).stencil", sub: directory) let template = StencilSwiftTemplate(templateString: templateString, environment: stencilSwiftEnvironment()) + + // default values let contextVariations = contextVariations ?? { [(context: $1, suffix: "")] } + let prefix = outputPrefix ?? templateName let resourceDir = resourceDirectory ?? directory for contextName in contextNames { @@ -168,7 +172,7 @@ extension XCTestCase { guard let result = try? template.render(context) else { fatalError("Unable to render template") } - let expected = Fixtures.output(for: "\(outputPrefix)-context-\(contextName)\(suffix).swift", sub: resourceDir) + let expected = Fixtures.output(for: "\(prefix)-context-\(contextName)\(suffix).swift", sub: resourceDir) XCTDiffStrings(result, expected) } } From 922e0c9cf2169bfce09f091a0444312f6f2f3da2 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sun, 19 Feb 2017 16:27:31 +0100 Subject: [PATCH 4/4] Changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edf2fd5..e4306ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,9 @@ _None_ ### Breaking Changes -_None_ +* Templates are now organized in subdirectories for each command. + [@djbe](https://github.com/djbe) + [#13](https://github.com/SwiftGen/templates/issues/13) ### New Features