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

import Foundation
import XCTest
import ToolCore

@testable import ResgenSwift

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

    
    func test_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)
            }
        
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
}
