- Convert XCTestCase classes to structs with @Test functions - Replace XCTAssert* with #expect, and force unwraps/XCTFail with #require - Resolve test bundle via a class token in the CLI smoke test (Swift Testing does not register the .xctest bundle in Bundle.allBundles) - Rename adaptForXCTest() to adaptForTest()
1079 lines
34 KiB
Swift
1079 lines
34 KiB
Swift
//
|
|
// DefinitionTests.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 06/09/2022.
|
|
//
|
|
|
|
// CPD-OFF
|
|
|
|
import Foundation
|
|
@testable import ResgenSwift
|
|
import ToolCore
|
|
import Testing
|
|
|
|
struct DefinitionTests {
|
|
|
|
// MARK: - Match line
|
|
|
|
@Test
|
|
func matchingDefinition() throws {
|
|
// Given
|
|
let line = "[definition_name]"
|
|
|
|
// When
|
|
let definition = try #require(Definition.match(line))
|
|
|
|
// Expect
|
|
#expect(definition.name == "definition_name")
|
|
}
|
|
|
|
@Test
|
|
func notMatchingDefinition() {
|
|
// 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
|
|
#expect(definition1 == nil)
|
|
#expect(definition2 == nil)
|
|
#expect(definition3 == nil)
|
|
}
|
|
|
|
// MARK: - Matching tags
|
|
|
|
@Test
|
|
func matchingTags() {
|
|
// 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
|
|
#expect(match1)
|
|
#expect(match2)
|
|
#expect(match3)
|
|
}
|
|
|
|
@Test
|
|
func notMatchingTags() {
|
|
// 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
|
|
#expect(match1 == false)
|
|
#expect(match2 == false)
|
|
#expect(match3 == false)
|
|
}
|
|
|
|
// MARK: - getNSLocalizedStringProperty
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringProperty() {
|
|
// 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",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
|
forLang: "en-us",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "This is a comment")
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "This is a comment")
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "This is a comment")
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringPropertyWithEmptyComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
definition.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",
|
|
isStatic: false,
|
|
visibility: .private,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: false,
|
|
visibility: .private,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
|
forLang: "en-us",
|
|
isStatic: false,
|
|
visibility: .private,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
private 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
private 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
private var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringPropertyWithNoComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
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",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
|
forLang: "en-us",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
public 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
public 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
public var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
// MARK: - getNSLocalizedStringProperty - static
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringStaticProperty() {
|
|
// 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",
|
|
isStatic: true,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: true,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
|
forLang: "en-us",
|
|
isStatic: true,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public static var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "This is a comment")
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public static var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "This is a comment")
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public static var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "This is a comment")
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringStaticPropertyWithEmptyComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
definition.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",
|
|
isStatic: true,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: true,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
|
forLang: "en-us",
|
|
isStatic: true,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringStaticPropertyWithNoComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
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",
|
|
isStatic: true,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: true,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEnUs = definition.getNSLocalizedStringProperty(
|
|
forLang: "en-us",
|
|
isStatic: true,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal 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
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringPropertyWithOneArgument() {
|
|
// 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",
|
|
isStatic: false,
|
|
visibility: .internal,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// Welcome "%@" !
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
internal var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "Welcome \"%@\" !", comment: "This is a comment")
|
|
}
|
|
|
|
/// Translation in fr :
|
|
/// Welcome "%@" !
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
internal func definition_name(arg0: String) -> String {
|
|
String(format: self.definition_name, arg0)
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringPropertyWithMultipleArgument() {
|
|
// 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",
|
|
isStatic: false,
|
|
visibility: .private,
|
|
assetBundle: .main
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// Welcome "%@" ! Your age is %d :) Your weight is %f ;-)
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
private var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "Welcome \"%@\" ! Your age is %d :) Your weight is %f ;-)", comment: "This is a comment")
|
|
}
|
|
|
|
/// Translation in fr :
|
|
/// Welcome "%@" ! Your age is %d :) Your weight is %f ;-)
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
private func definition_name(arg0: String, arg1: Int, arg2: Double) -> String {
|
|
String(format: self.definition_name, arg0, arg1, arg2)
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedNSLocalizedStringPropertyWithNumberedArguments() {
|
|
// 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",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
let propertyEn = definition.getNSLocalizedStringProperty(
|
|
forLang: "en",
|
|
isStatic: false,
|
|
visibility: .public,
|
|
assetBundle: .main
|
|
)
|
|
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// Vous %%: %1$@ %2$@ Age: %3$d
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "Vous %%: %1$@ %2$@ Age: %3$d", comment: "This is a comment")
|
|
}
|
|
|
|
/// Translation in fr :
|
|
/// Vous %%: %1$@ %2$@ Age: %3$d
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public 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
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "You %%: %2$@ %1$@ Age: %3$d", comment: "This is a comment")
|
|
}
|
|
|
|
/// Translation in en :
|
|
/// You %%: %2$@ %1$@ Age: %3$d
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public func definition_name(arg0: String, arg1: String, arg2: Int) -> String {
|
|
String(format: self.definition_name, arg0, arg1, arg2)
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
}
|
|
|
|
// MARK: - Raw properties
|
|
|
|
@Test
|
|
func generatedRawProperty() {
|
|
// 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",
|
|
visibility: .public,
|
|
isStatic: false
|
|
)
|
|
let propertyEn = definition.getProperty(
|
|
forLang: "en",
|
|
visibility: .public,
|
|
isStatic: false
|
|
)
|
|
let propertyEnUs = definition.getProperty(
|
|
forLang: "en-us",
|
|
visibility: .public,
|
|
isStatic: false
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
"C'est la traduction francaise"
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
"This is the english translation"
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
public var definition_name: String {
|
|
"This is the english us translation"
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedRawPropertyWithEmptyComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
definition.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",
|
|
visibility: .package,
|
|
isStatic: false
|
|
)
|
|
let propertyEn = definition.getProperty(
|
|
forLang: "en",
|
|
visibility: .package,
|
|
isStatic: false
|
|
)
|
|
let propertyEnUs = definition.getProperty(
|
|
forLang: "en-us",
|
|
visibility: .package,
|
|
isStatic: false
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
package var definition_name: String {
|
|
"C'est la traduction francaise"
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
package var definition_name: String {
|
|
"This is the english translation"
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
package var definition_name: String {
|
|
"This is the english us translation"
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedRawPropertyWithNoComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
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",
|
|
visibility: .private,
|
|
isStatic: false
|
|
)
|
|
let propertyEn = definition.getProperty(
|
|
forLang: "en",
|
|
visibility: .private,
|
|
isStatic: false
|
|
)
|
|
let propertyEnUs = definition.getProperty(
|
|
forLang: "en-us",
|
|
visibility: .private,
|
|
isStatic: false
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
private var definition_name: String {
|
|
"C'est la traduction francaise"
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
private var definition_name: String {
|
|
"This is the english translation"
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
private var definition_name: String {
|
|
"This is the english us translation"
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
// MARK: - Raw static properties
|
|
|
|
@Test
|
|
func generatedRawStaticProperty() {
|
|
// 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",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
let propertyEn = definition.getProperty(
|
|
forLang: "en",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
let propertyEnUs = definition.getProperty(
|
|
forLang: "en-us",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
internal static var definition_name: String {
|
|
"C'est la traduction francaise"
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
internal static var definition_name: String {
|
|
"This is the english translation"
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// This is a comment
|
|
internal static var definition_name: String {
|
|
"This is the english us translation"
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedRawStaticPropertyWithEmptyComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
definition.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",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
let propertyEn = definition.getProperty(
|
|
forLang: "en",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
let propertyEnUs = definition.getProperty(
|
|
forLang: "en-us",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
"C'est la traduction francaise"
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
"This is the english translation"
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
"This is the english us translation"
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
|
|
@Test
|
|
func generatedRawStaticPropertyWithNoComment() {
|
|
// Given
|
|
let definition = Definition(name: "definition_name")
|
|
definition.tags = ["ios","iosonly","notranslation"]
|
|
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",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
let propertyEn = definition.getProperty(
|
|
forLang: "en",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
let propertyEnUs = definition.getProperty(
|
|
forLang: "en-us",
|
|
visibility: .internal,
|
|
isStatic: true
|
|
)
|
|
|
|
// Expect
|
|
let expectFr = """
|
|
/// Translation in fr :
|
|
/// C'est la traduction francaise
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
"C'est la traduction francaise"
|
|
}
|
|
"""
|
|
|
|
let expectEn = """
|
|
/// Translation in en :
|
|
/// This is the english translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
"This is the english translation"
|
|
}
|
|
"""
|
|
|
|
let expectEnUs = """
|
|
/// Translation in en-us :
|
|
/// This is the english us translation
|
|
///
|
|
/// Comment :
|
|
/// No comment
|
|
internal static var definition_name: String {
|
|
"This is the english us translation"
|
|
}
|
|
"""
|
|
|
|
#expect(propertyFr.adaptForTest() == expectFr.adaptForTest())
|
|
#expect(propertyEn.adaptForTest() == expectEn.adaptForTest())
|
|
#expect(propertyEnUs.adaptForTest() == expectEnUs.adaptForTest())
|
|
}
|
|
}
|
|
|
|
// CPD-ON
|