//
//  TagsGeneratorTests.swift
//  
//
//  Created by Thibaut Schmitt on 06/09/2022.
//

import Foundation
import XCTest
import ToolCore

@testable import ResgenSwift

final class TagsGeneratorTests: XCTestCase {
    
    private func getDefinition(
        name: String,
        lang: String,
        tags: [String]
    ) -> Definition {
        let definition = Definition(name: name)
        definition.tags = tags
        definition.translations = [lang: "Some translation"]
        return definition
    }
    
    func testGeneratedExtensionContent() {
        // Given
        let sectionOne = Section(name: "section_one")
        sectionOne.definitions = [
            getDefinition(name: "s1_def_one", lang: "ium", tags: ["ios","iosonly"]),
            getDefinition(name: "s1_def_two", lang: "ium", tags: ["ios","iosonly"]),
        ]
        
        let sectionTwo = Section(name: "section_two")
        sectionTwo.definitions = [
            getDefinition(name: "s2_def_one", lang: "ium", tags: ["ios","iosonly"]),
            getDefinition(name: "s2_def_two", lang: "ium", tags: ["droid","droidonly"])
        ]
        
        let sectionThree = Section(name: "section_three")
        sectionThree.definitions = [
            getDefinition(name: "s3_def_one", lang: "ium", tags: ["droid","droidonly"]),
            getDefinition(name: "s3_def_two", lang: "ium", tags: ["droid","droidonly"])
        ]
        
        // When
        let extensionContent = TagsGenerator.getExtensionContent(
            sections: [sectionOne, sectionTwo, sectionThree],
            lang: "ium",
            tags: ["ios", "iosonly"],
            isStatic: false,
            extensionName: "GenTags",
            visibility: .public
        )

        // Expect Tags
        let expect = """
        // Generated by ResgenSwift.Strings.Tags \(ResgenSwiftVersion)
        
        import UIKit
        
        extension GenTags {
            // MARK: - section_one
        
            /// Translation in ium :
            /// Some translation
            ///
            /// Comment :
            /// No comment
            public var s1_def_one: String {
                "Some translation"
            }
        
            /// Translation in ium :
            /// Some translation
            ///
            /// Comment :
            /// No comment
            public var s1_def_two: String {
                "Some translation"
            }
        
            // MARK: - section_two
        
            /// Translation in ium :
            /// Some translation
            ///
            /// Comment :
            /// No comment
            public var s2_def_one: String {
                "Some translation"
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
}
