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] 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!!!'