Remove a lots of code duplication in StringsFileGeneratorTests
Some checks reported warnings
gitea-openium/resgen.swift/pipeline/head This commit is unstable
Some checks reported warnings
gitea-openium/resgen.swift/pipeline/head This commit is unstable
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
//
|
||||
// StringsFileGenerator+OldStringsFile.swift
|
||||
// ResgenSwift
|
||||
//
|
||||
// Created by Thibaut Schmitt on 30/04/2025.
|
||||
//
|
||||
|
||||
import ToolCore
|
||||
|
||||
extension StringsFileGeneratorTests {
|
||||
|
||||
static let appleStringsFileExpectationFr = """
|
||||
/**
|
||||
* 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";
|
||||
"""
|
||||
|
||||
static let appleStringsFileExpectationEn = """
|
||||
/**
|
||||
* 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";
|
||||
"""
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
//
|
||||
// StringsFileGenerator+R2ExtensionsExpectation.swift
|
||||
// ResgenSwift
|
||||
//
|
||||
// Created by Thibaut Schmitt on 30/04/2025.
|
||||
//
|
||||
|
||||
@testable import ResgenSwift
|
||||
import ToolCore
|
||||
|
||||
extension StringsFileGeneratorTests {
|
||||
|
||||
static func getExtensionContentExpectation(
|
||||
staticVar: Bool,
|
||||
s1DefOneFr: String = "Section Un - Definition Un",
|
||||
s1DefOneComment: String = "",
|
||||
s1DefTwoFr: String = "Section Un - Definition Deux",
|
||||
s1DefTwoComment: String = "",
|
||||
s2DefOneFr: String = "Section Deux - Definition Un",
|
||||
s2DefOneComment: String = "",
|
||||
s2DefTwoFr: String = "Section Deux - Definition Deux",
|
||||
s2DefTwoComment: String = "",
|
||||
) -> String {
|
||||
"""
|
||||
// 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 :
|
||||
/// \(s1DefOneFr)
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s1DefOneComment.isEmpty ? "No comment" : s1DefOneComment)
|
||||
\(staticVar ? "static " : "")var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "\(s1DefOneComment)")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// \(s1DefTwoFr)
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s1DefTwoComment.isEmpty ? "No comment" : s1DefTwoComment)
|
||||
\(staticVar ? "static " : "")var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "\(s1DefTwoComment)")
|
||||
}
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
/// Translation in fr :
|
||||
/// \(s2DefOneFr)
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s2DefOneComment.isEmpty ? "No comment" : s2DefOneComment)
|
||||
\(staticVar ? "static " : "")var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "\(s2DefOneComment)")
|
||||
}
|
||||
|
||||
/// Translation in fr :
|
||||
/// \(s2DefTwoFr)
|
||||
///
|
||||
/// Comment :
|
||||
/// \(s2DefTwoComment.isEmpty ? "No comment" : s2DefTwoComment)
|
||||
\(staticVar ? "static " : "")var s2_def_two: String {
|
||||
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "\(s2DefTwoComment)")
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
//
|
||||
// StringsFileGenerator+XCStringsExpectation.swift
|
||||
// ResgenSwift
|
||||
//
|
||||
// Created by Thibaut Schmitt on 30/04/2025.
|
||||
//
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
extension XCStringDefinition {
|
||||
|
||||
enum Mock {
|
||||
|
||||
static func getDefinitionSectionOne(
|
||||
defOneFr: String = "Section Un - Definition Un",
|
||||
defOneEn: String = "Section One - Definition One",
|
||||
defOneComment: String? = nil,
|
||||
defTwoFr: String = "Section Un - Definition Deux",
|
||||
defTwoEn: String = "Section One - Definition Two",
|
||||
defTwoComment: String? = nil
|
||||
) -> [XCStringDefinition] {
|
||||
[
|
||||
XCStringDefinition(
|
||||
title: "s1_def_one",
|
||||
content: XCStringDefinitionContent(
|
||||
comment: defOneComment,
|
||||
extractionState: "manual",
|
||||
localizations: XCStringLocalizationContainer(
|
||||
localizations: getXCStringLocalization(
|
||||
defFr: defOneFr,
|
||||
defEn: defOneEn
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
XCStringDefinition(
|
||||
title: "s1_def_two",
|
||||
content: XCStringDefinitionContent(
|
||||
comment: defTwoComment,
|
||||
extractionState: "manual",
|
||||
localizations: XCStringLocalizationContainer(
|
||||
localizations: getXCStringLocalization(
|
||||
defFr: defTwoFr,
|
||||
defEn: defTwoEn
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
static func getDefinitionSectionTwo(
|
||||
defOneFr: String = "Section Deux - Definition Un",
|
||||
defOneEn: String = "Section Two - Definition One",
|
||||
defOneComment: String? = nil,
|
||||
defTwoFr: String = "Section Deux - Definition Deux",
|
||||
defTwoEn: String? = nil,
|
||||
defTwoComment: String? = nil
|
||||
) -> [XCStringDefinition] {
|
||||
[
|
||||
XCStringDefinition(
|
||||
title: "s2_def_one",
|
||||
content: XCStringDefinitionContent(
|
||||
comment: defOneComment,
|
||||
extractionState: "manual",
|
||||
localizations: XCStringLocalizationContainer(
|
||||
localizations: getXCStringLocalization(
|
||||
defFr: defOneFr,
|
||||
defEn: defOneEn
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
XCStringDefinition(
|
||||
title: "s2_def_two",
|
||||
content: XCStringDefinitionContent(
|
||||
comment: defTwoComment,
|
||||
extractionState: "manual",
|
||||
localizations: XCStringLocalizationContainer(
|
||||
localizations: getXCStringLocalization(
|
||||
defFr: defTwoFr,
|
||||
defEn: defTwoEn ?? ""
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Private methods
|
||||
|
||||
private static func getXCStringLocalization(
|
||||
defFr: String,
|
||||
defEn: String
|
||||
) -> [XCStringLocalization] {
|
||||
var localizations = [XCStringLocalization]()
|
||||
|
||||
if defFr.isEmpty == false {
|
||||
localizations.append(
|
||||
XCStringLocalization(
|
||||
lang: "fr",
|
||||
content: XCStringLocalizationLangContent(
|
||||
stringUnit: DefaultStringUnit(
|
||||
state: "translated",
|
||||
value: defFr
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if defEn.isEmpty == false {
|
||||
localizations.append(
|
||||
XCStringLocalization(
|
||||
lang: "en",
|
||||
content: XCStringLocalizationLangContent(
|
||||
stringUnit: DefaultStringUnit(
|
||||
state: "translated",
|
||||
value: defEn
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return localizations
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user