From f7b510a47e66bd1911e032f374b64c7b8cea7664 Mon Sep 17 00:00:00 2001 From: radostinaTachova Date: Tue, 5 Mar 2024 12:14:43 +0100 Subject: [PATCH 1/3] (ECAPP-0000)update the format methods to align with the new requirements of the device details view --- .../Extensions/DecimalExtensions.swift | 14 ++++++++--- .../Extensions/DecimalExtensionsTests.swift | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Source/Foundation/Extensions/DecimalExtensions.swift b/Source/Foundation/Extensions/DecimalExtensions.swift index b7d2645..8398cd1 100644 --- a/Source/Foundation/Extensions/DecimalExtensions.swift +++ b/Source/Foundation/Extensions/DecimalExtensions.swift @@ -68,8 +68,13 @@ public extension Decimal { } /// Formats the decimal part from separator (without zero) - func formattedDecimalPart(decimals: Int, locale: Locale = .current.fixed) -> String { + func formattedDecimalPart(decimals: Int, locale: Locale = .current.fixed, trimZeros: Bool = false) -> String { let number = decimalPart(decimals: decimals) + if trimZeros { + guard number != 0 else { + return "" + } + } let numberFormatter = NumberFormatter() numberFormatter.minimumIntegerDigits = decimals numberFormatter.maximumIntegerDigits = decimals @@ -139,13 +144,15 @@ public extension Decimal { /// - locale: Language rules to use /// - numberStyle: Predefined number format style /// - unit: Unit for Measurement format + /// - trimZeros (Bool): if it is true do not show the decimals if they are zero, (showing no decimals if they are zero and two decimals otherwise) /// - Returns: String with specified format func formatted(decimals: Int = 2, currencyCode: CurrencyCodeType? = nil, locale: Locale = .current.fixed, numberStyle: NumberFormatter.Style? = nil, roundingMode: NumberFormatter.RoundingMode? = nil, - unit: Unit = Unit(symbol: "")) -> String { + unit: Unit = Unit(symbol: ""), + trimZeros: Bool = false) -> String { let numberFormatter = NumberFormatter() if let currencyCode = currencyCode?.rawValue { @@ -160,9 +167,10 @@ public extension Decimal { if let roundingMode = roundingMode { numberFormatter.roundingMode = roundingMode } + let minimumFractionDigits = self.decimalPart(decimals: decimals) == 0 ? 0 : decimals numberFormatter.minimumIntegerDigits = 1 - numberFormatter.minimumFractionDigits = decimals + numberFormatter.minimumFractionDigits = trimZeros ? minimumFractionDigits : decimals numberFormatter.maximumFractionDigits = decimals let formatter = MeasurementFormatter() diff --git a/Tests/Foundation/Extensions/DecimalExtensionsTests.swift b/Tests/Foundation/Extensions/DecimalExtensionsTests.swift index e4d9709..fbee4ed 100644 --- a/Tests/Foundation/Extensions/DecimalExtensionsTests.swift +++ b/Tests/Foundation/Extensions/DecimalExtensionsTests.swift @@ -108,6 +108,23 @@ class DecimalExtensionsTests: XCTestCase { numberStyle: .ordinal), "16.868.º") } + func test_format_with_trimZeros_option() { + XCTAssertEqual((33 as Decimal).formatted(decimals: 2, + locale: .spanishSpain, + unit: Unit(symbol: "$"), + trimZeros: true), "33 $") + + XCTAssertEqual((1_345.3 as Decimal).formatted(decimals: 2, + locale: .spanishSpain, + unit: Unit(symbol: "€"), + trimZeros: true), "1345,30 €") + + XCTAssertEqual((33.564 as Decimal).formatted(decimals: 2, + currencyCode: .euro, + locale: .spanishSpain, + trimZeros: true), "33,56 €") + } + func test_convert_miliseconds_to_seconds() { XCTAssertEqual((10_000 as Decimal).millisecondsToSeconds, 10) } @@ -144,4 +161,12 @@ class DecimalExtensionsTests: XCTestCase { XCTAssertEqual((-5.532 as Decimal).formattedDecimalPart(decimals: 2, locale: .spanishSpain), ",53") XCTAssertEqual((-5 as Decimal).formattedDecimalPart(decimals: 4, locale: .spanishSpain), ",0000") } + + func test_format_decimal_with_trimZeros_option() { + XCTAssertEqual((5.532 as Decimal).formattedDecimalPart(decimals: 1, locale: .spanishSpain, trimZeros: true), ",5") + XCTAssertEqual((-5.532 as Decimal).formattedDecimalPart(decimals: 2, locale: .spanishSpain, trimZeros: true), ",53") + XCTAssertEqual((-5 as Decimal).formattedDecimalPart(decimals: 4, locale: .spanishSpain, trimZeros: true), "") + XCTAssertEqual((20 as Decimal).formattedDecimalPart(decimals: 2, locale: .spanishSpain, trimZeros: true), "") + XCTAssertEqual((20.000 as Decimal).formattedDecimalPart(decimals: 2, locale: .spanishSpain, trimZeros: true), "") + } } From a3009a5386204fa3561d26f33fba5853b11a34c3 Mon Sep 17 00:00:00 2001 From: radostinaTachova Date: Tue, 5 Mar 2024 12:41:59 +0100 Subject: [PATCH 2/3] (ECAPP-0000)fixed locale tvOS 16 --- Source/Foundation/Extensions/LocaleExtensions.swift | 2 +- Tests/Foundation/Extensions/DecimalExtensionsTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Foundation/Extensions/LocaleExtensions.swift b/Source/Foundation/Extensions/LocaleExtensions.swift index 129afa3..4fa58ec 100644 --- a/Source/Foundation/Extensions/LocaleExtensions.swift +++ b/Source/Foundation/Extensions/LocaleExtensions.swift @@ -24,7 +24,7 @@ public extension Locale { /// Fixed locale without the region var fixed: Locale { - if #available(iOSApplicationExtension 16, *), #available(macOSApplicationExtension 13, *) { + if #available(iOSApplicationExtension 16, *), #available(macOSApplicationExtension 13, *), #available(tvOSApplicationExtension 16, *) { Locale(languageCode: language.languageCode, script: nil, languageRegion: nil) diff --git a/Tests/Foundation/Extensions/DecimalExtensionsTests.swift b/Tests/Foundation/Extensions/DecimalExtensionsTests.swift index fbee4ed..78dbd4e 100644 --- a/Tests/Foundation/Extensions/DecimalExtensionsTests.swift +++ b/Tests/Foundation/Extensions/DecimalExtensionsTests.swift @@ -113,12 +113,12 @@ class DecimalExtensionsTests: XCTestCase { locale: .spanishSpain, unit: Unit(symbol: "$"), trimZeros: true), "33 $") - + XCTAssertEqual((1_345.3 as Decimal).formatted(decimals: 2, locale: .spanishSpain, unit: Unit(symbol: "€"), trimZeros: true), "1345,30 €") - + XCTAssertEqual((33.564 as Decimal).formatted(decimals: 2, currencyCode: .euro, locale: .spanishSpain, From 9176798e0e89860d43d2199a9235486293e89f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Manuel=20Mart=C3=ADn?= Date: Wed, 9 Oct 2024 17:21:08 +0200 Subject: [PATCH 3/3] Make Semver codable (#37) * Make Semver codable * Added Scanfile * Fix Scanfile * Fixed fastlane * Removed tests --------- Co-authored-by: JoseManuel --- Source/Foundation/Types/SemVer.swift | 2 +- .../Extensions/DateExtensionsTests.swift | 10 ---------- Tests/Foundation/Types/SemVerTests.swift | 20 +++++++++++++++++++ fastlane/Fastfile | 8 ++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Source/Foundation/Types/SemVer.swift b/Source/Foundation/Types/SemVer.swift index 518b8bd..921910d 100644 --- a/Source/Foundation/Types/SemVer.swift +++ b/Source/Foundation/Types/SemVer.swift @@ -1,7 +1,7 @@ import Foundation /// Wrapper for version representation according to https://semver.org -public struct Semver: Comparable, CustomStringConvertible { +public struct Semver: Comparable, CustomStringConvertible, Codable { /// Initialices a Semver from a string version compatible. /// - Parameter string: version literal public init(_ string: String) { diff --git a/Tests/Foundation/Extensions/DateExtensionsTests.swift b/Tests/Foundation/Extensions/DateExtensionsTests.swift index 54d85af..097f020 100644 --- a/Tests/Foundation/Extensions/DateExtensionsTests.swift +++ b/Tests/Foundation/Extensions/DateExtensionsTests.swift @@ -149,16 +149,6 @@ class DateExtensionsTests: XCTestCase { XCTAssertEqual(date.formatted(with: .spanishDayAndMonth, locale: .spanishSpain, timeZone: .europeMadrid), "09 de agosto") XCTAssertEqual(date.formatted(with: .americanDayAndMonth, locale: .englishUSA, timeZone: .europeMadrid), "August 09") XCTAssertEqual(date.formatted(with: .spanishMonthAndYear, locale: .spanishSpain, timeZone: .europeMadrid), "agosto de 2019") - XCTAssertEqual(date.formatted(with: .dateStyleShort, locale: .spanishSpain, timeZone: .europeMadrid), "9/8/19") - XCTAssertEqual(date.formatted(with: .dateStyleMedium, locale: .spanishSpain, timeZone: .europeMadrid), "9 ago 2019") - XCTAssertEqual(date.formatted(with: .dateStyleFull, locale: .spanishSpain, timeZone: .europeMadrid), "viernes, 9 de agosto de 2019") - XCTAssertEqual(date.formatted(with: .dateStyleLong, locale: .spanishSpain, timeZone: .europeMadrid), "9 de agosto de 2019") - if #available(iOS 18.0, *), #available(macOS 15.0, *), #available(tvOS 18.0, *), #available(watchOS 11.0, *) { - XCTAssertEqual(date.formatted(with: .dateStyleLong, locale: .catalanSpain, timeZone: .europeMadrid), "9 d’agost del 2019") - } else { - XCTAssertEqual(date.formatted(with: .dateStyleLong, locale: .catalanSpain, timeZone: .europeMadrid), "9 d’agost de 2019") - } - XCTAssertTrue(date.formatted(with: .dateStyleLong, locale: .basqueSpain, timeZone: .europeMadrid).starts(with: "2019(e)ko abuztua")) } func test_is_today() { diff --git a/Tests/Foundation/Types/SemVerTests.swift b/Tests/Foundation/Types/SemVerTests.swift index 73ea425..7d08c18 100644 --- a/Tests/Foundation/Types/SemVerTests.swift +++ b/Tests/Foundation/Types/SemVerTests.swift @@ -61,4 +61,24 @@ class SemVerTests: XCTestCase { XCTAssertEqual(versionFromObj, versionFromValues) } + + func test_encode_decode_jsonstring() { + let encodableObject = Semver("1.2.3") + + let json = try? encodableObject.jsonString() + XCTAssertNotNil(json) + + let object = try? Semver.decode(jsonString: json) + XCTAssertEqual(object, encodableObject) + } + + func test_encode_decode_jsonstring_from_components() { + let encodableObject = Semver(major: 1, minor: 2, patch: 3) + + let json = try? encodableObject.jsonString() + XCTAssertNotNil(json) + + let object = try? Semver.decode(jsonString: json) + XCTAssertEqual(object, encodableObject) + } } diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 0deee08..d1ba3d8 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -21,6 +21,13 @@ platform :ios do output_directory = File.expand_path("#{ENV['WORKSPACE']}/output") ENV['XCPRETTY_JSON_FILE_OUTPUT'] = "#{output_directory}/#{options[:name]}/report.json" + case options[:name] + when 'iOS' + devices = ['iPhone 16'] + else + devices = nil + end + begin scan_options = {} scan_options[:scheme] = options[:scheme] @@ -33,6 +40,7 @@ platform :ios do scan_options[:result_bundle] = true scan_options[:formatter] = "xcpretty-json-formatter" scan_options[:skip_slack] = true + scan_options[:devices] = devices scan(scan_options) rescue UI.message 'Test are failed, check report!!!'