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:
374
Tests/ResgenSwiftTests/Strings/DefinitionTests.swift
Normal file
374
Tests/ResgenSwiftTests/Strings/DefinitionTests.swift
Normal file
@ -0,0 +1,374 @@
|
||||
//
|
||||
// DefinitionTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 06/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class DefinitionTests: XCTestCase {
|
||||
|
||||
// MARK: - Match line
|
||||
|
||||
func testMatchingDefinition() {
|
||||
// Given
|
||||
let line = "[definition_name]"
|
||||
|
||||
// When
|
||||
let definition = Definition.match(line)
|
||||
|
||||
// Expect
|
||||
XCTAssertNotNil(definition)
|
||||
XCTAssertEqual(definition?.name, "definition_name")
|
||||
}
|
||||
|
||||
func testNotMatchingDefinition() {
|
||||
// Given
|
||||
let line1 = "definition_name"
|
||||
let line2 = "[definition_name"
|
||||
let line3 = "definition_name]"
|
||||
|
||||
// When
|
||||
let definition1 = Definition.match(line1)
|
||||
let definition2 = Definition.match(line2)
|
||||
let definition3 = Definition.match(line3)
|
||||
|
||||
// Expect
|
||||
XCTAssertNil(definition1)
|
||||
XCTAssertNil(definition2)
|
||||
XCTAssertNil(definition3)
|
||||
}
|
||||
|
||||
// MARK: - Matching tags
|
||||
|
||||
func testMatchingTags() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
|
||||
// When
|
||||
let match1 = definition.hasOneOrMoreMatchingTags(inputTags: ["ios"])
|
||||
let match2 = definition.hasOneOrMoreMatchingTags(inputTags: ["iosonly"])
|
||||
let match3 = definition.hasOneOrMoreMatchingTags(inputTags: ["notranslation"])
|
||||
|
||||
|
||||
// Expect
|
||||
XCTAssertTrue(match1)
|
||||
XCTAssertTrue(match2)
|
||||
XCTAssertTrue(match3)
|
||||
}
|
||||
|
||||
func testNotMatchingTags() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
|
||||
// When
|
||||
let match1 = definition.hasOneOrMoreMatchingTags(inputTags: ["droid"])
|
||||
let match2 = definition.hasOneOrMoreMatchingTags(inputTags: ["droidonly"])
|
||||
let match3 = definition.hasOneOrMoreMatchingTags(inputTags: ["azerty"])
|
||||
|
||||
// Expect
|
||||
XCTAssertFalse(match1)
|
||||
XCTAssertFalse(match2)
|
||||
XCTAssertFalse(match3)
|
||||
}
|
||||
|
||||
// MARK: - getNSLocalizedStringProperty
|
||||
|
||||
func testGeneratedNSLocalizedStringProperty() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "C'est la traduction francaise",
|
||||
"en": "This is the english translation",
|
||||
"en-us": "This is the english us translation"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr")
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en")
|
||||
let propertyEnUs = definition.getNSLocalizedStringProperty(forLang: "en-us")
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// C'est la traduction francaise
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "")
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEn = """
|
||||
/// Translation in en :
|
||||
/// This is the english translation
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "")
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEnUs = """
|
||||
/// Translation in en-us :
|
||||
/// This is the english us translation
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEnUs.adaptForXCTest(), expectEnUs.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedNSLocalizedStringStaticProperty() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "C'est la traduction francaise",
|
||||
"en": "This is the english translation",
|
||||
"en-us": "This is the english us translation"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringStaticProperty(forLang: "fr")
|
||||
let propertyEn = definition.getNSLocalizedStringStaticProperty(forLang: "en")
|
||||
let propertyEnUs = definition.getNSLocalizedStringStaticProperty(forLang: "en-us")
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// C'est la traduction francaise
|
||||
static var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "")
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEn = """
|
||||
/// Translation in en :
|
||||
/// This is the english translation
|
||||
static var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "")
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEnUs = """
|
||||
/// Translation in en-us :
|
||||
/// This is the english us translation
|
||||
static var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEnUs.adaptForXCTest(), expectEnUs.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedNSLocalizedStringPropertyWithOneArgument() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "Welcome \"%@\" !"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr")
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// Welcome "%@" !
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "Welcome \"%@\" !", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Welcome "%@" !
|
||||
func definition_name(arg0: String) -> String {
|
||||
String(format: self.definition_name, arg0)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedNSLocalizedStringPropertyWithMultipleArgument() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "Welcome \"%@\" ! Your age is %d :) Your weight is %f ;-)"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr")
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// Welcome "%@" ! Your age is %d :) Your weight is %f ;-)
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "Welcome \"%@\" ! Your age is %d :) Your weight is %f ;-)", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Welcome "%@" ! Your age is %d :) Your weight is %f ;-)
|
||||
func definition_name(arg0: String, arg1: Int, arg2: Double) -> String {
|
||||
String(format: self.definition_name, arg0, arg1, arg2)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedNSLocalizedStringPropertyWithNumberedArguments() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "Vous %%: %1$@ %2$@ Age: %3$d",
|
||||
"en": "You %%: %2$@ %1$@ Age: %3$d"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getNSLocalizedStringProperty(forLang: "fr")
|
||||
let propertyEn = definition.getNSLocalizedStringProperty(forLang: "en")
|
||||
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// Vous %%: %1$@ %2$@ Age: %3$d
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "Vous %%: %1$@ %2$@ Age: %3$d", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Vous %%: %1$@ %2$@ Age: %3$d
|
||||
func definition_name(arg0: String, arg1: String, arg2: Int) -> String {
|
||||
String(format: self.definition_name, arg0, arg1, arg2)
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEn = """
|
||||
/// Translation in en :
|
||||
/// You %%: %2$@ %1$@ Age: %3$d
|
||||
var definition_name: String {
|
||||
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "You %%: %2$@ %1$@ Age: %3$d", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in en :
|
||||
/// You %%: %2$@ %1$@ Age: %3$d
|
||||
func definition_name(arg0: String, arg1: String, arg2: Int) -> String {
|
||||
String(format: self.definition_name, arg0, arg1, arg2)
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
}
|
||||
|
||||
// MARK: - Raw properties
|
||||
|
||||
func testGeneratedRawProperty() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "C'est la traduction francaise",
|
||||
"en": "This is the english translation",
|
||||
"en-us": "This is the english us translation"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getProperty(forLang: "fr")
|
||||
let propertyEn = definition.getProperty(forLang: "en")
|
||||
let propertyEnUs = definition.getProperty(forLang: "en-us")
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// C'est la traduction francaise
|
||||
var definition_name: String {
|
||||
"C'est la traduction francaise"
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEn = """
|
||||
/// Translation in en :
|
||||
/// This is the english translation
|
||||
var definition_name: String {
|
||||
"This is the english translation"
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEnUs = """
|
||||
/// Translation in en-us :
|
||||
/// This is the english us translation
|
||||
var definition_name: String {
|
||||
"This is the english us translation"
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEnUs.adaptForXCTest(), expectEnUs.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedRawStaticProperty() {
|
||||
// Given
|
||||
let definition = Definition(name: "definition_name")
|
||||
definition.tags = ["ios","iosonly","notranslation"]
|
||||
definition.comment = "This is a comment"
|
||||
definition.translations = [
|
||||
"fr": "C'est la traduction francaise",
|
||||
"en": "This is the english translation",
|
||||
"en-us": "This is the english us translation"
|
||||
]
|
||||
|
||||
// When
|
||||
let propertyFr = definition.getStaticProperty(forLang: "fr")
|
||||
let propertyEn = definition.getStaticProperty(forLang: "en")
|
||||
let propertyEnUs = definition.getStaticProperty(forLang: "en-us")
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/// Translation in fr :
|
||||
/// C'est la traduction francaise
|
||||
static var definition_name: String {
|
||||
"C'est la traduction francaise"
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEn = """
|
||||
/// Translation in en :
|
||||
/// This is the english translation
|
||||
static var definition_name: String {
|
||||
"This is the english translation"
|
||||
}
|
||||
"""
|
||||
|
||||
let expectEnUs = """
|
||||
/// Translation in en-us :
|
||||
/// This is the english us translation
|
||||
static var definition_name: String {
|
||||
"This is the english us translation"
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(propertyFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
XCTAssertEqual(propertyEnUs.adaptForXCTest(), expectEnUs.adaptForXCTest())
|
||||
}
|
||||
}
|
104
Tests/ResgenSwiftTests/Strings/SectionTests.swift
Normal file
104
Tests/ResgenSwiftTests/Strings/SectionTests.swift
Normal file
@ -0,0 +1,104 @@
|
||||
//
|
||||
// SectionTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 06/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class SectionTests: XCTestCase {
|
||||
|
||||
// MARK: - Match line
|
||||
|
||||
func testMatchingDefinition() {
|
||||
// Given
|
||||
let line = "[[section_name]]"
|
||||
|
||||
// When
|
||||
let section = Section.match(line)
|
||||
|
||||
// Expect
|
||||
XCTAssertNotNil(section)
|
||||
XCTAssertEqual(section?.name, "section_name")
|
||||
}
|
||||
|
||||
func testNotMatchingDefinition() {
|
||||
// Given
|
||||
let lines = ["section_name",
|
||||
"[section_name]",
|
||||
"[section_name",
|
||||
"[[section_name",
|
||||
"[[section_name]",
|
||||
"section_name]",
|
||||
"section_name]]",
|
||||
"[section_name]]"]
|
||||
|
||||
// When
|
||||
let matches = lines.compactMap { Section.match($0) }
|
||||
|
||||
// Expect
|
||||
XCTAssertEqual(matches.isEmpty, true)
|
||||
}
|
||||
|
||||
// MARK: - Matching tags
|
||||
|
||||
func testMatchingTags() {
|
||||
// Given
|
||||
let section = Section(name: "section_name")
|
||||
section.definitions = [
|
||||
{
|
||||
let def = Definition(name: "definition_name")
|
||||
def.tags = ["ios","iosonly"]
|
||||
return def
|
||||
}(),
|
||||
{
|
||||
let def = Definition(name: "definition_name_two")
|
||||
def.tags = ["droid","droidonly"]
|
||||
return def
|
||||
}()
|
||||
]
|
||||
|
||||
// When
|
||||
let match1 = section.hasOneOrMoreMatchingTags(tags: ["ios"])
|
||||
let match2 = section.hasOneOrMoreMatchingTags(tags: ["iosonly"])
|
||||
let match3 = section.hasOneOrMoreMatchingTags(tags: ["droid"])
|
||||
let match4 = section.hasOneOrMoreMatchingTags(tags: ["droidonly"])
|
||||
|
||||
// Expect
|
||||
XCTAssertTrue(match1)
|
||||
XCTAssertTrue(match2)
|
||||
XCTAssertTrue(match3)
|
||||
XCTAssertTrue(match4)
|
||||
}
|
||||
|
||||
func testNotMatchingTags() {
|
||||
// Given
|
||||
let section = Section(name: "section_name")
|
||||
section.definitions = [
|
||||
{
|
||||
let def = Definition(name: "definition_name")
|
||||
def.tags = ["ios","iosonly"]
|
||||
return def
|
||||
}(),
|
||||
{
|
||||
let def = Definition(name: "definition_name_two")
|
||||
def.tags = ["droid","droidonly"]
|
||||
return def
|
||||
}()
|
||||
]
|
||||
|
||||
// When
|
||||
let match1 = section.hasOneOrMoreMatchingTags(tags: ["web"])
|
||||
let match2 = section.hasOneOrMoreMatchingTags(tags: ["webonly"])
|
||||
let match3 = section.hasOneOrMoreMatchingTags(tags: ["azerty"])
|
||||
|
||||
// Expect
|
||||
XCTAssertFalse(match1)
|
||||
XCTAssertFalse(match2)
|
||||
XCTAssertFalse(match3)
|
||||
}
|
||||
}
|
255
Tests/ResgenSwiftTests/Strings/StringsFileGeneratorTests.swift
Normal file
255
Tests/ResgenSwiftTests/Strings/StringsFileGeneratorTests.swift
Normal file
@ -0,0 +1,255 @@
|
||||
//
|
||||
// StringsFileGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 06/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
import ToolCore
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class StringsFileGeneratorTests: XCTestCase {
|
||||
|
||||
private func getDefinition(name: String, translations: [String: String], tags: [String]) -> Definition {
|
||||
let definition = Definition(name: name)
|
||||
definition.tags = tags
|
||||
definition.translations = translations
|
||||
return definition
|
||||
}
|
||||
|
||||
func testGenerateStringsFileContent() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
sectionOne.definitions = [
|
||||
getDefinition(name: "s1_def_one",
|
||||
translations: ["fr": "Section Un - Definition Un",
|
||||
"en": "Section One - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s1_def_two",
|
||||
translations: ["fr": "Section Un - Definition Deux",
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"])
|
||||
]
|
||||
|
||||
let sectionTwo = Section(name: "section_two")
|
||||
sectionTwo.definitions = [
|
||||
getDefinition(name: "s2_def_one",
|
||||
translations: ["fr": "Section Deux - Definition Un",
|
||||
"en": "Section Two - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
// When
|
||||
let stringsFileContentFr = StringsFileGenerator.generateStringsFileContent(lang: "fr",
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
sections: [sectionOne, sectionTwo])
|
||||
let stringsFileContentEn = StringsFileGenerator.generateStringsFileContent(lang: "en",
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
sections: [sectionOne, sectionTwo])
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/**
|
||||
* Apple Strings File
|
||||
* Generated by ResgenSwift \(ResgenSwiftVersion)
|
||||
* Language: fr
|
||||
*/
|
||||
|
||||
/********** section_one **********/
|
||||
|
||||
"s1_def_one" = "Section Un - Definition Un";
|
||||
|
||||
"s1_def_two" = "Section Un - Definition Deux";
|
||||
|
||||
/********** section_two **********/
|
||||
|
||||
"s2_def_one" = "Section Deux - Definition Un";
|
||||
|
||||
"s2_def_two" = "Section Deux - Definition Deux";
|
||||
"""
|
||||
|
||||
let expectEn = """
|
||||
/**
|
||||
* Apple Strings File
|
||||
* Generated by ResgenSwift \(ResgenSwiftVersion)
|
||||
* Language: en
|
||||
*/
|
||||
|
||||
/********** section_one **********/
|
||||
|
||||
"s1_def_one" = "Section One - Definition One";
|
||||
|
||||
"s1_def_two" = "Section One - Definition Two";
|
||||
|
||||
/********** section_two **********/
|
||||
|
||||
"s2_def_one" = "Section Two - Definition One";
|
||||
|
||||
"s2_def_two" = "Section Deux - Definition Deux";
|
||||
"""
|
||||
|
||||
XCTAssertEqual(stringsFileContentFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(stringsFileContentEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
sectionOne.definitions = [
|
||||
getDefinition(name: "s1_def_one",
|
||||
translations: ["fr": "Section Un - Definition Un",
|
||||
"en": "Section One - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s1_def_two",
|
||||
translations: ["fr": "Section Un - Definition Deux",
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"])
|
||||
]
|
||||
|
||||
let sectionTwo = Section(name: "section_two")
|
||||
sectionTwo.definitions = [
|
||||
getDefinition(name: "s2_def_one",
|
||||
translations: ["fr": "Section Deux - Definition Un",
|
||||
"en": "Section Two - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = StringsFileGenerator.getExtensionContent(sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: false,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
fileprivate let kStringsFileName = "myInputFilename"
|
||||
|
||||
extension GenStrings {
|
||||
|
||||
// MARK: - section_one
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Un
|
||||
var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Deux
|
||||
var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "")
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Un
|
||||
var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Deux
|
||||
var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentWithStaticVar() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
sectionOne.definitions = [
|
||||
getDefinition(name: "s1_def_one",
|
||||
translations: ["fr": "Section Un - Definition Un",
|
||||
"en": "Section One - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s1_def_two",
|
||||
translations: ["fr": "Section Un - Definition Deux",
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"])
|
||||
]
|
||||
|
||||
let sectionTwo = Section(name: "section_two")
|
||||
sectionTwo.definitions = [
|
||||
getDefinition(name: "s2_def_one",
|
||||
translations: ["fr": "Section Deux - Definition Un",
|
||||
"en": "Section Two - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = StringsFileGenerator.getExtensionContent(sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: true,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
fileprivate let kStringsFileName = "myInputFilename"
|
||||
|
||||
extension GenStrings {
|
||||
|
||||
// MARK: - section_one
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Un
|
||||
static var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Deux
|
||||
static var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "")
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Un
|
||||
static var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Deux
|
||||
static var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
||||
|
82
Tests/ResgenSwiftTests/Strings/TagsGeneratorTests.swift
Normal file
82
Tests/ResgenSwiftTests/Strings/TagsGeneratorTests.swift
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// 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"],
|
||||
staticVar: false,
|
||||
extensionName: "GenTags")
|
||||
// Expect Tags
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Tags \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenTags {
|
||||
// MARK: - section_one
|
||||
|
||||
/// Translation in ium :
|
||||
/// Some translation
|
||||
var s1_def_one: String {
|
||||
"Some translation"
|
||||
}
|
||||
|
||||
/// Translation in ium :
|
||||
/// Some translation
|
||||
var s1_def_two: String {
|
||||
"Some translation"
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
/// Translation in ium :
|
||||
/// Some translation
|
||||
var s2_def_one: String {
|
||||
"Some translation"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user