- Convert XCTestCase classes to structs with @Test functions - Replace XCTAssert* with #expect, and force unwraps/XCTFail with #require - Resolve test bundle via a class token in the CLI smoke test (Swift Testing does not register the .xctest bundle in Bundle.allBundles) - Rename adaptForXCTest() to adaptForTest()
223 lines
6.0 KiB
Swift
223 lines
6.0 KiB
Swift
//
|
|
// FontNameTests.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 05/09/2022.
|
|
//
|
|
|
|
import Foundation
|
|
import Testing
|
|
|
|
@testable import ResgenSwift
|
|
|
|
struct FontNameTests {
|
|
|
|
@Test
|
|
func uiKit_GeneratedProperty_noForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "CircularStdBold",
|
|
filename: "CircularStd-Bold",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: true,
|
|
isSwiftUI: false,
|
|
visibility: .internal
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
internal static let CircularStdBold: ((_ size: CGFloat) -> UIFont) = { size in
|
|
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func uiKit_GeneratedProperty_withForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "[Circular_Std+Bold-Underline]",
|
|
filename: "Circular_Std+Bold-Underline",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: true,
|
|
isSwiftUI: false,
|
|
visibility: .package
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
package static let CircularStdBoldUnderline: ((_ size: CGFloat) -> UIFont) = { size in
|
|
UIFont(name: FontName.CircularStdBoldUnderline.rawValue, size: size)!
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func uiKit_GeneratedMethod_noForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "CircularStdBold",
|
|
filename: "CircularStd-Bold",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: false,
|
|
isSwiftUI: false,
|
|
visibility: .private
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
private func CircularStdBold(withSize size: CGFloat) -> UIFont {
|
|
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func uiKit_GeneratedMethod_withForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "[Circular_Std+Bold-Underline]",
|
|
filename: "Circular_Std+Bold-Underline",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: false,
|
|
isSwiftUI: false,
|
|
visibility: .public
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
public func CircularStdBoldUnderline(withSize size: CGFloat) -> UIFont {
|
|
UIFont(name: FontName.CircularStdBoldUnderline.rawValue, size: size)!
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func swiftUI_GeneratedProperty_noForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "CircularStdBold",
|
|
filename: "CircularStd-Bold",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: true,
|
|
isSwiftUI: true,
|
|
visibility: .public
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
public static let CircularStdBold: ((_ size: CGFloat) -> Font) = { size in
|
|
Font.custom(FontName.CircularStdBold.rawValue, size: size)
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func swiftUI_GeneratedProperty_withForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "[Circular_Std+Bold-Underline]",
|
|
filename: "Circular_Std+Bold-Underline",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: true,
|
|
isSwiftUI: true,
|
|
visibility: .package
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
package static let CircularStdBoldUnderline: ((_ size: CGFloat) -> Font) = { size in
|
|
Font.custom(FontName.CircularStdBoldUnderline.rawValue, size: size)
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func swiftUI_GeneratedMethod_noForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "CircularStdBold",
|
|
filename: "CircularStd-Bold",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: false,
|
|
isSwiftUI: true,
|
|
visibility: .package
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
package func CircularStdBold(withSize size: CGFloat) -> Font {
|
|
Font.custom(FontName.CircularStdBold.rawValue, size: size)
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func swiftUI_GeneratedMethod_withForbiddenCharacter() {
|
|
// Given
|
|
let fontName = FontName(
|
|
postscriptName: "[Circular_Std+Bold-Underline]",
|
|
filename: "Circular_Std+Bold-Underline",
|
|
fileExtension: "ttf"
|
|
)
|
|
|
|
// When
|
|
let property = fontName.getProperty(
|
|
isStatic: false,
|
|
isSwiftUI: true,
|
|
visibility: .internal
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
internal func CircularStdBoldUnderline(withSize size: CGFloat) -> Font {
|
|
Font.custom(FontName.CircularStdBoldUnderline.rawValue, size: size)
|
|
}
|
|
"""
|
|
|
|
#expect(property.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
}
|