//
//  FontNameTests.swift
//  
//
//  Created by Thibaut Schmitt on 05/09/2022.
//

import Foundation
import XCTest

@testable import ResgenSwift

final class FontNameTests: XCTestCase {
 
    func test_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)!
         }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_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)!
         }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_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)!
         }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_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)!
        }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
 
    func test_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)
         }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_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)
         }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_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)
         }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_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)
        }
        """
            
        XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
    }
}
