Publish v1.0
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
Reviewed-on: #1
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
//
|
||||
// FontExtensionGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
import ToolCore
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
let fontNames: [FontName] = [
|
||||
"CircularStd-Regular",
|
||||
"CircularStd-Bold"
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = FontExtensionGenerator.getExtensionContent(fontsNames: fontNames,
|
||||
staticVar: false,
|
||||
extensionName: "GenFonts")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Fonts \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenFonts {
|
||||
|
||||
enum FontName: String {
|
||||
case CircularStdRegular = "CircularStd-Regular"
|
||||
case CircularStdBold = "CircularStd-Bold"
|
||||
}
|
||||
|
||||
// MARK: - Getter
|
||||
|
||||
func CircularStdRegular(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdRegular.rawValue, size: size)!
|
||||
}
|
||||
|
||||
func CircularStdBold(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
||||
}
|
||||
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
}
|
83
Tests/ResgenSwiftTests/Fonts/FontNameTests.swift
Normal file
83
Tests/ResgenSwiftTests/Fonts/FontNameTests.swift
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// FontNameTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontNameTests: XCTestCase {
|
||||
|
||||
func testGeneratedProperty_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.staticProperty
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static let CircularStdBold: ((_ size: CGFloat) -> UIFont) = { size in
|
||||
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedProperty_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.staticProperty
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static let CircularStdBoldUnderline: ((_ size: CGFloat) -> UIFont) = { size in
|
||||
UIFont(name: FontName.CircularStdBoldUnderline.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedMethod_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.method
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
func CircularStdBold(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedMethod_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.method
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
func CircularStdBoldUnderline(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdBoldUnderline.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
}
|
35
Tests/ResgenSwiftTests/Fonts/FontPlistGeneratorTests.swift
Normal file
35
Tests/ResgenSwiftTests/Fonts/FontPlistGeneratorTests.swift
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// FontPlistGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontPlistGeneratorTests: XCTestCase {
|
||||
func testGeneratedPlist() {
|
||||
// Given
|
||||
let fontNames: [FontName] = [
|
||||
"CircularStd-Regular",
|
||||
"CircularStd-Bold"
|
||||
]
|
||||
|
||||
// When
|
||||
let plistContent = FontPlistGenerator.generatePlistUIAppsFontContent(for: fontNames)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>CircularStd-Regular</string>
|
||||
<string>CircularStd-Bold</string>
|
||||
</array>
|
||||
"""
|
||||
|
||||
XCTAssertEqual(plistContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user