Squashed commit of the following:
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
commit aa59ef28ea56315eb421ba044ddaf0c4066bfff8 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Mon Nov 7 10:26:28 2022 +0100 Add trailing carrier at the end of generated extension files commit e985950aa1e39d81d4938e15f8724c0f7723b003 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Fri Nov 4 16:37:34 2022 +0100 Replace installation script by script that install completion file Setup a Makefile to install resgen commit d574384c151259610a4c2f837b14068bb7716e44 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Fri Nov 4 14:33:39 2022 +0100 Refactor Improve testability Add tests on SwiftUI generated code Add tests on command commit d9e76632c3037da0ed9e1dd37056685416579da9 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Thu Nov 3 15:43:47 2022 +0100 Fixing bad merge on FontOptions commit 76b5ebfcd1cde7a7d4c83f516a4fc937841e7715 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Thu Nov 3 15:37:28 2022 +0100 Squashed commit of the following: commit085f1ffc33
Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Thu Nov 3 15:00:27 2022 +0100 Refactor SwiftUI extension generation and generation SwiftUI extension for images commit4f7d7e18b1
Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Mon Oct 31 16:21:32 2022 +0100 Génération de composant SwiftUI: Color et Image commit0797667b25
Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Mon Oct 31 16:21:12 2022 +0100 Génération de composant SwiftUI: Color et Image commit 417a2630925841dd486ae1d684d28ab7dca240e0 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Wed Oct 19 17:13:03 2022 +0200 Update Info.plist UIAppFonts key when generating fonts (if plist path if defined)
This commit is contained in:
@ -13,7 +13,7 @@ import ToolCore
|
||||
|
||||
final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
func test_uiKit_GeneratedExtensionContent() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
@ -23,7 +23,8 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
|
||||
staticVar: false,
|
||||
extensionName: "GenColors")
|
||||
extensionName: "GenColors",
|
||||
isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -48,7 +49,7 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentForStaticVar() {
|
||||
func test_uiKit_GeneratedExtensionContentForStaticVar() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
@ -58,7 +59,8 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
|
||||
staticVar: true,
|
||||
extensionName: "GenColor")
|
||||
extensionName: "GenColor",
|
||||
isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -82,4 +84,76 @@ final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContent() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
|
||||
staticVar: false,
|
||||
extensionName: "GenColors",
|
||||
isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Color \(ResgenSwiftVersion)
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension GenColors {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
var colorOne: Color {
|
||||
Color("colorOne")
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
var colorTwo: Color {
|
||||
Color("colorTwo")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContentForStaticVar() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
|
||||
staticVar: true,
|
||||
extensionName: "GenColor",
|
||||
isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Color \(ResgenSwiftVersion)
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension GenColor {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
static var colorOne: Color {
|
||||
Color("colorOne")
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
static var colorTwo: Color {
|
||||
Color("colorTwo")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ import XCTest
|
||||
|
||||
final class ParsedColorTests: XCTestCase {
|
||||
|
||||
func testGeneratedProperty() {
|
||||
func test_uiKit_GeneratedProperty() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let property = color.getColorProperty()
|
||||
let property = color.getColorProperty(isStatic: false, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -30,12 +30,12 @@ final class ParsedColorTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedStaticProperty() {
|
||||
func test_uiKit_GeneratedStaticProperty() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let property = color.getColorStaticProperty()
|
||||
let property = color.getColorProperty(isStatic: true, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -48,6 +48,42 @@ final class ParsedColorTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedProperty() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let property = color.getColorProperty(isStatic: false, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
var red: Color {
|
||||
Color("red")
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedStaticProperty() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let property = color.getColorProperty(isStatic: true, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
static var red: Color {
|
||||
Color("red")
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedColorAsset() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
@ -13,7 +13,7 @@ import ToolCore
|
||||
|
||||
final class FontExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
func test_uiKit_GeneratedExtensionContent() {
|
||||
// Given
|
||||
let fontNames: [FontName] = [
|
||||
"CircularStd-Regular",
|
||||
@ -23,7 +23,8 @@ final class FontExtensionGeneratorTests: XCTestCase {
|
||||
// When
|
||||
let extensionContent = FontExtensionGenerator.getExtensionContent(fontsNames: fontNames,
|
||||
staticVar: false,
|
||||
extensionName: "GenFonts")
|
||||
extensionName: "GenFonts",
|
||||
isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -53,5 +54,47 @@ final class FontExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContent() {
|
||||
// Given
|
||||
let fontNames: [FontName] = [
|
||||
"CircularStd-Regular",
|
||||
"CircularStd-Bold"
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = FontExtensionGenerator.getExtensionContent(fontsNames: fontNames,
|
||||
staticVar: false,
|
||||
extensionName: "GenFonts",
|
||||
isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Fonts \(ResgenSwiftVersion)
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension GenFonts {
|
||||
|
||||
enum FontName: String {
|
||||
case CircularStdRegular = "CircularStd-Regular"
|
||||
case CircularStdBold = "CircularStd-Bold"
|
||||
}
|
||||
|
||||
// MARK: - Getter
|
||||
|
||||
func CircularStdRegular(withSize size: CGFloat) -> Font {
|
||||
Font.custom(FontName.CircularStdRegular.rawValue, size: size)
|
||||
}
|
||||
|
||||
func CircularStdBold(withSize size: CGFloat) -> Font {
|
||||
Font.custom(FontName.CircularStdBold.rawValue, size: size)
|
||||
}
|
||||
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ import XCTest
|
||||
|
||||
final class FontNameTests: XCTestCase {
|
||||
|
||||
func testGeneratedProperty_noForbiddenCharacter() {
|
||||
func test_uiKit_GeneratedProperty_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.staticProperty
|
||||
let property = fontName.getProperty(isStatic: true, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -29,12 +29,12 @@ final class FontNameTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedProperty_withForbiddenCharacter() {
|
||||
func test_uiKit_GeneratedProperty_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.staticProperty
|
||||
let property = fontName.getProperty(isStatic: true, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -46,12 +46,12 @@ final class FontNameTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedMethod_noForbiddenCharacter() {
|
||||
func test_uiKit_GeneratedMethod_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.method
|
||||
let property = fontName.getProperty(isStatic: false, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -63,12 +63,12 @@ final class FontNameTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedMethod_withForbiddenCharacter() {
|
||||
func test_uiKit_GeneratedMethod_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.method
|
||||
let property = fontName.getProperty(isStatic: false, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -79,5 +79,72 @@ final class FontNameTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedProperty_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.getProperty(isStatic: true, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static let CircularStdBold: ((_ size: CGFloat) -> Font) = { size in
|
||||
Font.custom(FontName.CircularStdBold.rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedProperty_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.getProperty(isStatic: true, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static let CircularStdBoldUnderline: ((_ size: CGFloat) -> Font) = { size in
|
||||
Font.custom(FontName.CircularStdBoldUnderline.rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedMethod_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.getProperty(isStatic: false, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
func CircularStdBold(withSize size: CGFloat) -> Font {
|
||||
Font.custom(FontName.CircularStdBold.rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedMethod_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.getProperty(isStatic: false, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
func CircularStdBoldUnderline(withSize size: CGFloat) -> Font {
|
||||
Font.custom(FontName.CircularStdBoldUnderline.rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ final class FontPlistGeneratorTests: XCTestCase {
|
||||
]
|
||||
|
||||
// When
|
||||
let plistContent = FontPlistGenerator.generatePlistUIAppsFontContent(for: fontNames)
|
||||
let plistContent = FontPlistGenerator.generatePlistUIAppsFontContent(for: fontNames, infoPlistPaths: [String]())
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
|
@ -0,0 +1,81 @@
|
||||
//
|
||||
// ColorsConfigurationTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 04/11/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ColorsConfigurationTests: XCTestCase {
|
||||
|
||||
let projectDirectory = "projectDirectory/"
|
||||
|
||||
func test_argsGeneration_requiredArgs() {
|
||||
// Given
|
||||
let testingConfiguration = ColorsConfiguration(inputFile: "path/to/colors.txt",
|
||||
style: ColorStyle.all.rawValue,
|
||||
xcassetsPath: "path/to/assets.xcassets",
|
||||
extensionOutputPath: "Colors/Generated",
|
||||
extensionName: nil,
|
||||
extensionNameSwiftUI: nil,
|
||||
extensionSuffix: nil,
|
||||
staticMembers: false)
|
||||
// When
|
||||
let arguments = testingConfiguration.getArguments(projectDirectory: projectDirectory, force: false)
|
||||
|
||||
// Expect
|
||||
let expectedArguments = [
|
||||
"projectDirectory/path/to/colors.txt",
|
||||
"--style",
|
||||
"all",
|
||||
"--xcassets-path",
|
||||
"projectDirectory/path/to/assets.xcassets",
|
||||
"--extension-output-path",
|
||||
"projectDirectory/Colors/Generated",
|
||||
"--static-members",
|
||||
"false"
|
||||
]
|
||||
|
||||
XCTAssertEqual(arguments, expectedArguments)
|
||||
}
|
||||
|
||||
func test_argsGeneration_allArguments() {
|
||||
// Given
|
||||
let testingConfiguration = ColorsConfiguration(inputFile: "path/to/colors.txt",
|
||||
style: ColorStyle.all.rawValue,
|
||||
xcassetsPath: "path/to/assets.xcassets",
|
||||
extensionOutputPath: "Colors/Generated",
|
||||
extensionName: "AppUIColor",
|
||||
extensionNameSwiftUI: "AppColor",
|
||||
extensionSuffix: "Testing",
|
||||
staticMembers: false)
|
||||
// When
|
||||
let arguments = testingConfiguration.getArguments(projectDirectory: projectDirectory, force: true)
|
||||
|
||||
// Expect
|
||||
let expectedArguments = [
|
||||
"-f",
|
||||
"projectDirectory/path/to/colors.txt",
|
||||
"--style",
|
||||
"all",
|
||||
"--xcassets-path",
|
||||
"projectDirectory/path/to/assets.xcassets",
|
||||
"--extension-output-path",
|
||||
"projectDirectory/Colors/Generated",
|
||||
"--static-members",
|
||||
"false",
|
||||
"--extension-name",
|
||||
"AppUIColor",
|
||||
"--extension-name-swift-ui",
|
||||
"AppColor",
|
||||
"--extension-suffix",
|
||||
"Testing",
|
||||
]
|
||||
|
||||
XCTAssertEqual(arguments, expectedArguments)
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
//
|
||||
// FontsConfigurationTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 04/11/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontsConfigurationTests: XCTestCase {
|
||||
|
||||
let projectDirectory = "projectDirectory/"
|
||||
|
||||
func test_argsGeneration_requiredArgs() {
|
||||
// Given
|
||||
let testingConfiguration = FontsConfiguration(inputFile: "path/to/fonts.txt",
|
||||
extensionOutputPath: "Fonts/Generated",
|
||||
extensionName: nil,
|
||||
extensionNameSwiftUI: nil,
|
||||
extensionSuffix: nil,
|
||||
infoPlistPaths: nil,
|
||||
staticMembers: nil)
|
||||
// When
|
||||
let arguments = testingConfiguration.getArguments(projectDirectory: projectDirectory, force: false)
|
||||
|
||||
// Expect
|
||||
let expectedArguments = [
|
||||
"projectDirectory/path/to/fonts.txt",
|
||||
"--extension-output-path",
|
||||
"projectDirectory/Fonts/Generated",
|
||||
"--static-members",
|
||||
"false"
|
||||
]
|
||||
|
||||
XCTAssertEqual(arguments, expectedArguments)
|
||||
}
|
||||
|
||||
func test_argsGeneration_allArguments() {
|
||||
// Given
|
||||
let testingConfiguration = FontsConfiguration(inputFile: "path/to/fonts.txt",
|
||||
extensionOutputPath: "Fonts/Generated",
|
||||
extensionName: "AppUIFont",
|
||||
extensionNameSwiftUI: "AppFont",
|
||||
extensionSuffix: "Testing",
|
||||
infoPlistPaths: "path/to/plist1.plist path/to/plist2.plist",
|
||||
staticMembers: true)
|
||||
// When
|
||||
let arguments = testingConfiguration.getArguments(projectDirectory: projectDirectory, force: true)
|
||||
|
||||
// Expect
|
||||
let expectedArguments = [
|
||||
"-f",
|
||||
"projectDirectory/path/to/fonts.txt",
|
||||
"--extension-output-path",
|
||||
"projectDirectory/Fonts/Generated",
|
||||
"--static-members",
|
||||
"true",
|
||||
"--extension-name",
|
||||
"AppUIFont",
|
||||
"--extension-name-swift-ui",
|
||||
"AppFont",
|
||||
"--extension-suffix",
|
||||
"Testing",
|
||||
"--info-plist-paths",
|
||||
"projectDirectory/path/to/plist1.plist projectDirectory/path/to/plist2.plist"
|
||||
]
|
||||
|
||||
XCTAssertEqual(arguments, expectedArguments)
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
//
|
||||
// ImagesConfigurationTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 04/11/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ImagesConfigurationTests: XCTestCase {
|
||||
|
||||
let projectDirectory = "projectDirectory/"
|
||||
|
||||
func test_argsGeneration_requiredArgs() {
|
||||
// Given
|
||||
let testingConfiguration = ImagesConfiguration(inputFile: "path/to/images.txt",
|
||||
xcassetsPath: "path/to/assets.xcassets",
|
||||
extensionOutputPath: "Images/Generated",
|
||||
extensionName: nil,
|
||||
extensionNameSwiftUI: nil,
|
||||
extensionSuffix: nil,
|
||||
staticMembers: nil)
|
||||
|
||||
// When
|
||||
let arguments = testingConfiguration.getArguments(projectDirectory: projectDirectory, force: false)
|
||||
|
||||
// Expect
|
||||
let expectedArguments = [
|
||||
"projectDirectory/path/to/images.txt",
|
||||
"--xcassets-path",
|
||||
"projectDirectory/path/to/assets.xcassets",
|
||||
"--extension-output-path",
|
||||
"projectDirectory/Images/Generated",
|
||||
"--static-members",
|
||||
"false"
|
||||
]
|
||||
|
||||
XCTAssertEqual(arguments, expectedArguments)
|
||||
}
|
||||
|
||||
func test_argsGeneration_allArguments() {
|
||||
// Given
|
||||
let testingConfiguration = ImagesConfiguration(inputFile: "path/to/images.txt",
|
||||
xcassetsPath: "path/to/assets.xcassets",
|
||||
extensionOutputPath: "Images/Generated",
|
||||
extensionName: "AppUIImage",
|
||||
extensionNameSwiftUI: "AppImage",
|
||||
extensionSuffix: "Testing",
|
||||
staticMembers: true)
|
||||
|
||||
// When
|
||||
let arguments = testingConfiguration.getArguments(projectDirectory: projectDirectory, force: true)
|
||||
|
||||
// Expect
|
||||
let expectedArguments = [
|
||||
"-f",
|
||||
"projectDirectory/path/to/images.txt",
|
||||
"--xcassets-path",
|
||||
"projectDirectory/path/to/assets.xcassets",
|
||||
"--extension-output-path",
|
||||
"projectDirectory/Images/Generated",
|
||||
"--static-members",
|
||||
"true",
|
||||
"--extension-name",
|
||||
"AppUIImage",
|
||||
"--extension-name-swift-ui",
|
||||
"AppImage",
|
||||
"--extension-suffix",
|
||||
"Testing",
|
||||
]
|
||||
|
||||
XCTAssertEqual(arguments, expectedArguments)
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import ToolCore
|
||||
|
||||
final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
func test_uiKit_GeneratedExtensionContent() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
@ -24,7 +24,8 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
|
||||
staticVar: false,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename")
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -48,7 +49,7 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentForStaticVar() {
|
||||
func test_uiKit_GeneratedExtensionContentForStaticVar() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
@ -59,7 +60,8 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
|
||||
staticVar: true,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename")
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -82,4 +84,76 @@ final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContent() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
|
||||
staticVar: false,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Images \(ResgenSwiftVersion)
|
||||
// Images from myInputFilename
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension GenImages {
|
||||
|
||||
var image_one: Image {
|
||||
Image("image_one")
|
||||
}
|
||||
|
||||
var image_two: Image {
|
||||
Image("image_two")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedExtensionContentForStaticVar() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
|
||||
staticVar: true,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename",
|
||||
isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Images \(ResgenSwiftVersion)
|
||||
// Images from myInputFilename
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension GenImages {
|
||||
|
||||
static var image_one: Image {
|
||||
Image("image_one")
|
||||
}
|
||||
|
||||
static var image_two: Image {
|
||||
Image("image_two")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ final class ParsedImageTests: XCTestCase {
|
||||
XCTAssertEqual(convertArguments.x3.height, "30")
|
||||
}
|
||||
|
||||
func testGeneratedProperty() {
|
||||
func test_uiKit_GeneratedProperty() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
@ -43,7 +43,7 @@ final class ParsedImageTests: XCTestCase {
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.getImageProperty()
|
||||
let property = parsedImage.getImageProperty(isStatic: false, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -55,7 +55,7 @@ final class ParsedImageTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedStaticProperty() {
|
||||
func test_uiKit_GeneratedStaticProperty() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
@ -64,7 +64,7 @@ final class ParsedImageTests: XCTestCase {
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.getStaticImageProperty()
|
||||
let property = parsedImage.getImageProperty(isStatic: true, isSwiftUI: false)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -76,6 +76,48 @@ final class ParsedImageTests: XCTestCase {
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedProperty() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
tags: "id",
|
||||
width: 10,
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.getImageProperty(isStatic: false, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
var \(imageName): Image {
|
||||
Image("\(imageName)")
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func test_swiftUI_GeneratedStaticProperty() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
tags: "id",
|
||||
width: 10,
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.getImageProperty(isStatic: true, isSwiftUI: true)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static var \(imageName): Image {
|
||||
Image("\(imageName)")
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testAssetContentJson() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
|
Reference in New Issue
Block a user