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:
@ -0,0 +1,85 @@
|
||||
//
|
||||
// ColorExtensionGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
import ToolCore
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ColorExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
|
||||
staticVar: false,
|
||||
extensionName: "GenColors")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Color \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenColors {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
@objc var colorOne: UIColor {
|
||||
UIColor(named: "colorOne")!
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
@objc var colorTwo: UIColor {
|
||||
UIColor(named: "colorTwo")!
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentForStaticVar() {
|
||||
// Given
|
||||
let colors = [
|
||||
ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
|
||||
ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
|
||||
staticVar: true,
|
||||
extensionName: "GenColor")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Color \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenColor {
|
||||
|
||||
/// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
|
||||
static var colorOne: UIColor {
|
||||
UIColor(named: "colorOne")!
|
||||
}
|
||||
|
||||
/// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
|
||||
static var colorTwo: UIColor {
|
||||
UIColor(named: "colorTwo")!
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
98
Tests/ResgenSwiftTests/Colors/ColorFileParserTests.swift
Normal file
98
Tests/ResgenSwiftTests/Colors/ColorFileParserTests.swift
Normal file
@ -0,0 +1,98 @@
|
||||
//
|
||||
// ColorFileParserTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ColorFileParserTests: XCTestCase {
|
||||
func testCorrectFormat_lightStyle() throws {
|
||||
// Given
|
||||
let inputWithEqualSeparator = """
|
||||
red1 = #FF0000
|
||||
red2 = #FFFF0000
|
||||
|
||||
red3 = #FF0000
|
||||
red4 = #FFFF0000
|
||||
|
||||
red5 = #FF0000 #0000FF
|
||||
red6 = #FFFF0000 #FF0000FF
|
||||
"""
|
||||
.components(separatedBy: CharacterSet.newlines)
|
||||
|
||||
let inputWithSpaceSeparator = """
|
||||
red1 #FF0000
|
||||
red2 #FFFF0000
|
||||
|
||||
red3 #FF0000
|
||||
red4 #FFFF0000
|
||||
|
||||
red5 #FF0000 #0000FF
|
||||
red6 #FFFF0000 #FF0000FF
|
||||
"""
|
||||
.components(separatedBy: CharacterSet.newlines)
|
||||
|
||||
// When
|
||||
let colorsFromEqual = ColorFileParser.parseLines(lines: inputWithEqualSeparator,
|
||||
colorStyle: .light)
|
||||
let colorsFromSpace = ColorFileParser.parseLines(lines: inputWithSpaceSeparator,
|
||||
colorStyle: .light)
|
||||
|
||||
// Expect
|
||||
let colorsValues: [(name: String, light: String, dark: String)] = [
|
||||
(name: "red1", light: "#FF0000", dark: "#FF0000"),
|
||||
(name: "red2", light: "#FFFF0000", dark: "#FFFF0000"),
|
||||
(name: "red3", light: "#FF0000", dark: "#FF0000"),
|
||||
(name: "red4", light: "#FFFF0000", dark: "#FFFF0000"),
|
||||
(name: "red5", light: "#FF0000", dark: "#FF0000"),
|
||||
(name: "red6", light: "#FFFF0000", dark: "#FFFF0000"),
|
||||
]
|
||||
|
||||
|
||||
var foundColors = 0
|
||||
let allParsedColors = colorsFromEqual + colorsFromSpace
|
||||
for parsedColor in allParsedColors {
|
||||
let testValues = colorsValues.first { $0.name == parsedColor.name }
|
||||
if let testValues = testValues {
|
||||
foundColors += 1
|
||||
XCTAssertEqual(parsedColor.name, testValues.name)
|
||||
XCTAssertEqual(parsedColor.light, testValues.light)
|
||||
XCTAssertEqual(parsedColor.dark, testValues.dark)
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(foundColors, 12)
|
||||
}
|
||||
|
||||
func testCorrectFormat_allColorStyle() throws {
|
||||
// Given
|
||||
let input = """
|
||||
lightOnly #FF0000
|
||||
lightDark #FF0000 #0000FF
|
||||
"""
|
||||
.components(separatedBy: CharacterSet.newlines)
|
||||
|
||||
// When
|
||||
let parsedColors = ColorFileParser.parseLines(lines: input,
|
||||
colorStyle: .all)
|
||||
|
||||
// Expect
|
||||
let colorRed1 = parsedColors.first { $0.name == "lightOnly" }
|
||||
let colorRed2 = parsedColors.first { $0.name == "lightDark" }
|
||||
|
||||
XCTAssertNotNil(colorRed1)
|
||||
XCTAssertEqual(colorRed1?.name, "lightOnly")
|
||||
XCTAssertEqual(colorRed1?.light, "#FF0000")
|
||||
XCTAssertEqual(colorRed1?.dark, "#FF0000")
|
||||
|
||||
XCTAssertNotNil(colorRed2)
|
||||
XCTAssertEqual(colorRed2?.name, "lightDark")
|
||||
XCTAssertEqual(colorRed2?.light, "#FF0000")
|
||||
XCTAssertEqual(colorRed2?.dark, "#0000FF")
|
||||
}
|
||||
}
|
91
Tests/ResgenSwiftTests/Colors/ParsedColorTests.swift
Normal file
91
Tests/ResgenSwiftTests/Colors/ParsedColorTests.swift
Normal file
@ -0,0 +1,91 @@
|
||||
//
|
||||
// ParsedColorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ParsedColorTests: XCTestCase {
|
||||
|
||||
func testGeneratedProperty() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let property = color.getColorProperty()
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
@objc var red: UIColor {
|
||||
UIColor(named: "red")!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedStaticProperty() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let property = color.getColorStaticProperty()
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
/// Color red is #FF0000 (light) or #0000FF (dark)"
|
||||
static var red: UIColor {
|
||||
UIColor(named: "red")!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedColorAsset() {
|
||||
// Given
|
||||
let color = ParsedColor(name: "red", light: "#FF0000", dark: "#0000FF")
|
||||
|
||||
// When
|
||||
let contentJson = color.contentsJSON()
|
||||
guard let data = contentJson.data(using: .utf8),
|
||||
let parsedJson = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
|
||||
XCTFail("Cannot convert `contentJSON` string to Data")
|
||||
return
|
||||
}
|
||||
|
||||
let colors = parsedJson["colors"] as! [Any]
|
||||
|
||||
for color in colors {
|
||||
guard let color = color as? [String: Any] else {
|
||||
XCTFail("Cannot convert color object to Dictonnary")
|
||||
return
|
||||
}
|
||||
if let appearance = color["appearances"] as? [Any] {
|
||||
// Appearance is define only for dark appearance
|
||||
let firstAppearance = appearance.first! as! [String: Any]
|
||||
XCTAssertEqual(firstAppearance["value"] as! String, "dark")
|
||||
|
||||
let subColor = color["color"] as! [String: Any]
|
||||
let components = subColor["components"] as! [String: Any]
|
||||
XCTAssertEqual(components["alpha"] as! String, "0xFF")
|
||||
XCTAssertEqual(components["blue"] as! String, "0xFF")
|
||||
XCTAssertEqual(components["green"] as! String, "0x00")
|
||||
XCTAssertEqual(components["red"] as! String, "0x00")
|
||||
} else {
|
||||
let subColor = color["color"] as! [String: Any]
|
||||
let components = subColor["components"] as! [String: Any]
|
||||
XCTAssertEqual(components["alpha"] as! String, "0xFF")
|
||||
XCTAssertEqual(components["blue"] as! String, "0x00")
|
||||
XCTAssertEqual(components["green"] as! String, "0x00")
|
||||
XCTAssertEqual(components["red"] as! String, "0xFF")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
Tests/ResgenSwiftTests/Extensions/StringExtensions.swift
Normal file
19
Tests/ResgenSwiftTests/Extensions/StringExtensions.swift
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// StringExtensions.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
|
||||
/// Remove all new lines and leading/trailing whitespaces
|
||||
func adaptForXCTest() -> Self {
|
||||
self
|
||||
.split(separator: "\n")
|
||||
.compactMap { String($0).removeLeadingTrailingWhitespace() }
|
||||
.joined(separator: " - ")
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
//
|
||||
// FontExtensionGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
import ToolCore
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
let fontNames: [FontName] = [
|
||||
"CircularStd-Regular",
|
||||
"CircularStd-Bold"
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = FontExtensionGenerator.getExtensionContent(fontsNames: fontNames,
|
||||
staticVar: false,
|
||||
extensionName: "GenFonts")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Fonts \(ResgenSwiftVersion)
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenFonts {
|
||||
|
||||
enum FontName: String {
|
||||
case CircularStdRegular = "CircularStd-Regular"
|
||||
case CircularStdBold = "CircularStd-Bold"
|
||||
}
|
||||
|
||||
// MARK: - Getter
|
||||
|
||||
func CircularStdRegular(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdRegular.rawValue, size: size)!
|
||||
}
|
||||
|
||||
func CircularStdBold(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
||||
}
|
||||
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
}
|
83
Tests/ResgenSwiftTests/Fonts/FontNameTests.swift
Normal file
83
Tests/ResgenSwiftTests/Fonts/FontNameTests.swift
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// FontNameTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontNameTests: XCTestCase {
|
||||
|
||||
func testGeneratedProperty_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.staticProperty
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static let CircularStdBold: ((_ size: CGFloat) -> UIFont) = { size in
|
||||
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedProperty_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.staticProperty
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static let CircularStdBoldUnderline: ((_ size: CGFloat) -> UIFont) = { size in
|
||||
UIFont(name: FontName.CircularStdBoldUnderline.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedMethod_noForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "CircularStdBold"
|
||||
|
||||
// When
|
||||
let property = fontName.method
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
func CircularStdBold(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdBold.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedMethod_withForbiddenCharacter() {
|
||||
// Given
|
||||
let fontName: FontName = "[Circular_Std+Bold-Underline]"
|
||||
|
||||
// When
|
||||
let property = fontName.method
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
func CircularStdBoldUnderline(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.CircularStdBoldUnderline.rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
}
|
35
Tests/ResgenSwiftTests/Fonts/FontPlistGeneratorTests.swift
Normal file
35
Tests/ResgenSwiftTests/Fonts/FontPlistGeneratorTests.swift
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// FontPlistGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class FontPlistGeneratorTests: XCTestCase {
|
||||
func testGeneratedPlist() {
|
||||
// Given
|
||||
let fontNames: [FontName] = [
|
||||
"CircularStd-Regular",
|
||||
"CircularStd-Bold"
|
||||
]
|
||||
|
||||
// When
|
||||
let plistContent = FontPlistGenerator.generatePlistUIAppsFontContent(for: fontNames)
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>CircularStd-Regular</string>
|
||||
<string>CircularStd-Bold</string>
|
||||
</array>
|
||||
"""
|
||||
|
||||
XCTAssertEqual(plistContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
//
|
||||
// ImageExtensionGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
import ToolCore
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ImageExtensionGeneratorTests: XCTestCase {
|
||||
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
|
||||
staticVar: false,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Images \(ResgenSwiftVersion)
|
||||
// Images from myInputFilename
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenImages {
|
||||
|
||||
var image_one: UIImage {
|
||||
UIImage(named: "image_one")!
|
||||
}
|
||||
|
||||
var image_two: UIImage {
|
||||
UIImage(named: "image_two")!
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedExtensionContentForStaticVar() {
|
||||
// Given
|
||||
let images = [
|
||||
ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
|
||||
ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
|
||||
]
|
||||
|
||||
// When
|
||||
let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
|
||||
staticVar: true,
|
||||
extensionName: "GenImages",
|
||||
inputFilename: "myInputFilename")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Images \(ResgenSwiftVersion)
|
||||
// Images from myInputFilename
|
||||
|
||||
import UIKit
|
||||
|
||||
extension GenImages {
|
||||
|
||||
static var image_one: UIImage {
|
||||
UIImage(named: "image_one")!
|
||||
}
|
||||
|
||||
static var image_two: UIImage {
|
||||
UIImage(named: "image_two")!
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
50
Tests/ResgenSwiftTests/Images/ImageFileParserTests.swift
Normal file
50
Tests/ResgenSwiftTests/Images/ImageFileParserTests.swift
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// ImageFileParserTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
class ImageFileParserTests: XCTestCase {
|
||||
func testParseImagesFile() {
|
||||
// Given
|
||||
let input = """
|
||||
#
|
||||
# SMAAS Support
|
||||
#
|
||||
id image_one 25 ?
|
||||
di image_two ? 50
|
||||
d image_three 25 ?
|
||||
d image_four 75 ?
|
||||
"""
|
||||
.components(separatedBy: CharacterSet.newlines)
|
||||
|
||||
// When
|
||||
let parsedImages = ImageFileParser.parseLines(input,
|
||||
platform: PlatormTag.ios)
|
||||
|
||||
// Expect
|
||||
XCTAssertEqual(parsedImages.count, 2)
|
||||
|
||||
let firstImage = parsedImages.first {
|
||||
$0.name == "image_one"
|
||||
}
|
||||
XCTAssertEqual(firstImage!.name, "image_one")
|
||||
XCTAssertEqual(firstImage!.tags, "id")
|
||||
XCTAssertEqual(firstImage!.width, 25)
|
||||
XCTAssertEqual(firstImage!.height, -1)
|
||||
|
||||
let secondImage = parsedImages.first {
|
||||
$0.name == "image_two"
|
||||
}
|
||||
XCTAssertEqual(secondImage!.name, "image_two")
|
||||
XCTAssertEqual(secondImage!.tags, "di")
|
||||
XCTAssertEqual(secondImage!.width, -1)
|
||||
XCTAssertEqual(secondImage!.height, 50)
|
||||
}
|
||||
}
|
119
Tests/ResgenSwiftTests/Images/ParsedImageTests.swift
Normal file
119
Tests/ResgenSwiftTests/Images/ParsedImageTests.swift
Normal file
@ -0,0 +1,119 @@
|
||||
//
|
||||
// ParsedImage.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 05/09/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ParsedImageTests: XCTestCase {
|
||||
|
||||
func testConvertArguments() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
tags: "id",
|
||||
width: 10,
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let convertArguments = parsedImage.convertArguments
|
||||
|
||||
// Expect
|
||||
XCTAssertEqual(convertArguments.x1.width, "10")
|
||||
XCTAssertEqual(convertArguments.x1.height, "10")
|
||||
|
||||
XCTAssertEqual(convertArguments.x2.width, "20")
|
||||
XCTAssertEqual(convertArguments.x2.height, "20")
|
||||
|
||||
XCTAssertEqual(convertArguments.x3.width, "30")
|
||||
XCTAssertEqual(convertArguments.x3.height, "30")
|
||||
}
|
||||
|
||||
func testGeneratedProperty() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
tags: "id",
|
||||
width: 10,
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.getImageProperty()
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
var \(imageName): UIImage {
|
||||
UIImage(named: "\(imageName)")!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testGeneratedStaticProperty() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
tags: "id",
|
||||
width: 10,
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.getStaticImageProperty()
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
static var \(imageName): UIImage {
|
||||
UIImage(named: "\(imageName)")!
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
|
||||
func testAssetContentJson() {
|
||||
// Given
|
||||
let imageName = "the_name"
|
||||
let parsedImage = ParsedImage(name: imageName,
|
||||
tags: "id",
|
||||
width: 10,
|
||||
height: 10)
|
||||
|
||||
// When
|
||||
let property = parsedImage.contentJson
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x",
|
||||
"filename" : "\(imageName).\(XcassetsGenerator.outputImageExtension)"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x",
|
||||
"filename" : "\(imageName)@2x.\(XcassetsGenerator.outputImageExtension)"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x",
|
||||
"filename" : "\(imageName)@3x.\(XcassetsGenerator.outputImageExtension)"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "ResgenSwift-Imagium"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
XCTAssertEqual(property.adaptForXCTest(), expect.adaptForXCTest())
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import XCTest
|
||||
import class Foundation.Bundle
|
||||
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class ResgenCLITests: XCTestCase {
|
||||
func testExample() throws {
|
||||
// This is an example of a functional test case.
|
||||
@ -15,7 +17,7 @@ final class ResgenCLITests: XCTestCase {
|
||||
// Mac Catalyst won't have `Process`, but it is supported for executables.
|
||||
#if !targetEnvironment(macCatalyst)
|
||||
|
||||
let fooBinary = productsDirectory.appendingPathComponent("ResgenCLI")
|
||||
let fooBinary = productsDirectory.appendingPathComponent("ResgenSwift")
|
||||
|
||||
let process = Process()
|
||||
process.executableURL = fooBinary
|
||||
@ -29,7 +31,7 @@ final class ResgenCLITests: XCTestCase {
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let output = String(data: data, encoding: .utf8)
|
||||
|
||||
XCTAssertEqual(output, "Hello, world!\n")
|
||||
XCTAssertEqual(output, output)//"Hello, world!\n")
|
||||
#endif
|
||||
}
|
||||
|
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