- 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()
111 lines
3.1 KiB
Swift
111 lines
3.1 KiB
Swift
//
|
|
// FontExtensionGeneratorTests.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 05/09/2022.
|
|
//
|
|
|
|
import Foundation
|
|
import Testing
|
|
import ToolCore
|
|
|
|
@testable import ResgenSwift
|
|
|
|
struct FontExtensionGeneratorTests {
|
|
|
|
@Test
|
|
func uiKit_GeneratedExtensionContent() {
|
|
// Given
|
|
let fontNames: [FontName] = [
|
|
FontName(postscriptName: "CircularStd-Regular", filename: "CircularStd-Regular", fileExtension: "ttf"),
|
|
FontName(postscriptName: "CircularStd-Bold", filename: "CircularStd-Bold", fileExtension: "ttf")
|
|
]
|
|
|
|
// When
|
|
let extensionContent = FontExtensionGenerator.getExtensionContent(
|
|
fontsNames: fontNames,
|
|
isStatic: false,
|
|
extensionName: "GenFonts",
|
|
isSwiftUI: false,
|
|
visibility: .public
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
// Generated by ResgenSwift.Fonts \(ResgenSwiftVersion)
|
|
|
|
import UIKit
|
|
|
|
extension GenFonts {
|
|
|
|
public enum FontName: String {
|
|
case CircularStdRegular = "CircularStd-Regular"
|
|
case CircularStdBold = "CircularStd-Bold"
|
|
}
|
|
|
|
// MARK: - Getter
|
|
|
|
public func CircularStdRegular(withSize size: CGFloat) -> UIFont {
|
|
UIFont(name: FontName.CircularStdRegular.rawValue, size: size)!
|
|
}
|
|
|
|
public func CircularStdBold(withSize size: CGFloat) -> UIFont {
|
|
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
|
}
|
|
|
|
}
|
|
"""
|
|
|
|
#expect(extensionContent.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
|
|
|
|
@Test
|
|
|
|
|
|
func swiftUI_GeneratedExtensionContent() {
|
|
// Given
|
|
let fontNames: [FontName] = [
|
|
FontName(postscriptName: "CircularStd-Regular", filename: "CircularStd-Regular", fileExtension: "ttf"),
|
|
FontName(postscriptName: "CircularStd-Bold", filename: "CircularStd-Bold", fileExtension: "ttf")
|
|
]
|
|
|
|
// When
|
|
let extensionContent = FontExtensionGenerator.getExtensionContent(
|
|
fontsNames: fontNames,
|
|
isStatic: false,
|
|
extensionName: "GenFonts",
|
|
isSwiftUI: true,
|
|
visibility: .package
|
|
)
|
|
|
|
// Expect
|
|
let expect = """
|
|
// Generated by ResgenSwift.Fonts \(ResgenSwiftVersion)
|
|
|
|
import SwiftUI
|
|
|
|
extension GenFonts {
|
|
|
|
package enum FontName: String {
|
|
case CircularStdRegular = "CircularStd-Regular"
|
|
case CircularStdBold = "CircularStd-Bold"
|
|
}
|
|
|
|
// MARK: - Getter
|
|
|
|
package func CircularStdRegular(withSize size: CGFloat) -> Font {
|
|
Font.custom(FontName.CircularStdRegular.rawValue, size: size)
|
|
}
|
|
|
|
package func CircularStdBold(withSize size: CGFloat) -> Font {
|
|
Font.custom(FontName.CircularStdBold.rawValue, size: size)
|
|
}
|
|
|
|
}
|
|
"""
|
|
|
|
#expect(extensionContent.adaptForTest() == expect.adaptForTest())
|
|
}
|
|
}
|