Correction des commentaires des strings
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
This commit is contained in:
@ -13,13 +13,16 @@ import ToolCore
|
||||
|
||||
final class StringsFileGeneratorTests: XCTestCase {
|
||||
|
||||
private func getDefinition(name: String, translations: [String: String], tags: [String]) -> Definition {
|
||||
private func getDefinition(name: String, translations: [String: String], tags: [String], comment: String? = nil) -> Definition {
|
||||
let definition = Definition(name: name)
|
||||
definition.tags = tags
|
||||
definition.translations = translations
|
||||
definition.comment = comment
|
||||
return definition
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Strings File Content
|
||||
|
||||
func testGenerateStringsFileContent() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
@ -99,7 +102,92 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(stringsFileContentFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(stringsFileContentEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
}
|
||||
|
||||
|
||||
func testGenerateStringsFileContentWithComment() {
|
||||
// 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"],
|
||||
comment: "This is a comment"),
|
||||
getDefinition(name: "s1_def_two",
|
||||
translations: ["fr": "Section Un - Definition Deux",
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"],
|
||||
comment: "This is a comment")
|
||||
]
|
||||
|
||||
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"],
|
||||
comment: "This is a comment"),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"],
|
||||
comment: "This is a comment")
|
||||
]
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
||||
// MARK: - Extension Content
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
@ -195,7 +283,112 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
|
||||
func testGeneratedExtensionContentWithComment() {
|
||||
// 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"],
|
||||
comment: "This is a comment"),
|
||||
getDefinition(name: "s1_def_two",
|
||||
translations: ["fr": "Section Un - Definition Deux",
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"],
|
||||
comment: "This is a comment")
|
||||
]
|
||||
|
||||
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"],
|
||||
comment: "This is a comment"),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"],
|
||||
comment: "This is a comment")
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = StringsFileGenerator.getExtensionContent(sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: false,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
fileprivate let kStringsFileName = "myInputFilename"
|
||||
|
||||
extension GenStrings {
|
||||
|
||||
enum KeyStrings: String {
|
||||
case s1_def_one = "s1_def_one"
|
||||
case s1_def_two = "s1_def_two"
|
||||
case s2_def_one = "s2_def_one"
|
||||
case s2_def_two = "s2_def_two"
|
||||
|
||||
var keyPath: KeyPath<GenStrings, String> {
|
||||
switch self {
|
||||
case .s1_def_one: return \\GenStrings.s1_def_one
|
||||
case .s1_def_two: return \\GenStrings.s1_def_two
|
||||
case .s2_def_one: return \\GenStrings.s2_def_one
|
||||
case .s2_def_two: return \\GenStrings.s2_def_two
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - section_one
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Un
|
||||
/// This is a comment
|
||||
var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "This is a comment")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Deux
|
||||
/// This is a comment
|
||||
var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "This is a comment")
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Un
|
||||
/// This is a comment
|
||||
var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "This is a comment")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Deux
|
||||
/// This is a comment
|
||||
var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "This is a comment")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
if extensionContent != expect {
|
||||
print(prettyFirstDifferenceBetweenStrings(s1: extensionContent, s2: expect))
|
||||
}
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
// MARK: - Extension Content Static
|
||||
func testGeneratedExtensionContentWithStaticVar() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
@ -291,5 +484,109 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentWithStaticVarWithComment() {
|
||||
// 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"],
|
||||
comment: "This is a comment"),
|
||||
getDefinition(name: "s1_def_two",
|
||||
translations: ["fr": "Section Un - Definition Deux",
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"],
|
||||
comment: "This is a comment")
|
||||
]
|
||||
|
||||
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"],
|
||||
comment: "This is a comment"),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"],
|
||||
comment: "This is a comment")
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = StringsFileGenerator.getExtensionContent(sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: true,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
fileprivate let kStringsFileName = "myInputFilename"
|
||||
|
||||
extension GenStrings {
|
||||
|
||||
enum KeyStrings: String {
|
||||
case s1_def_one = "s1_def_one"
|
||||
case s1_def_two = "s1_def_two"
|
||||
case s2_def_one = "s2_def_one"
|
||||
case s2_def_two = "s2_def_two"
|
||||
|
||||
var keyPath: KeyPath<GenStrings, String> {
|
||||
switch self {
|
||||
case .s1_def_one: return \\GenStrings.s1_def_one
|
||||
case .s1_def_two: return \\GenStrings.s1_def_two
|
||||
case .s2_def_one: return \\GenStrings.s2_def_one
|
||||
case .s2_def_two: return \\GenStrings.s2_def_two
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - section_one
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Un
|
||||
/// This is a comment
|
||||
static var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "This is a comment")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Deux
|
||||
/// This is a comment
|
||||
static var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "This is a comment")
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Un
|
||||
/// This is a comment
|
||||
static var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "This is a comment")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Deux
|
||||
/// This is a comment
|
||||
static var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "This is a comment")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
if extensionContent != expect {
|
||||
print(prettyFirstDifferenceBetweenStrings(s1: extensionContent, s2: expect))
|
||||
}
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user