diff --git a/Sources/SemanticVersion/SemanticVersion.swift b/Sources/SemanticVersion/SemanticVersion.swift index 7d865aa..f53daae 100644 --- a/Sources/SemanticVersion/SemanticVersion.swift +++ b/Sources/SemanticVersion/SemanticVersion.swift @@ -68,6 +68,8 @@ extension SemanticVersion { // Source: https://regex101.com/r/Ly7O1x/3/ // Linked from https://semver.org +#if swift(>=5) + let semVerRegex = NSRegularExpression(#""" ^ v? # SPI extension: allow leading 'v' @@ -91,3 +93,31 @@ v? # SPI extension: allow leading 'v' )? $ """#, options: [.allowCommentsAndWhitespace]) + +#else + +let semVerRegex = NSRegularExpression(""" +^ +v? # SPI extension: allow leading 'v' +(?0|[1-9]\\d*) +\\. +(?0|[1-9]\\d*) +\\. +(?0|[1-9]\\d*) +(?:- + (? + (?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*) + (?:\\. + (?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*) + ) + *) +)? +(?:\\+ + (?[0-9a-zA-Z-]+ + (?:\\.[0-9a-zA-Z-]+) + *) +)? +$ +""", options: [.allowCommentsAndWhitespace]) + +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index ae29d60..4a04bfd 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,8 +1,28 @@ -// -// File.swift -// -// -// Created by Sven A. Schmidt on 01/09/2020. -// - -import Foundation +#if swift(>=5) + +#else + +import XCTest + +@testable import SemanticVersionTests + +extension SemanticVersionTests { + static var allTests: [(String, (SemanticVersionTests) -> () throws -> Void)] = [ + ("test_semVerRegex_valid", test_semVerRegex_valid), + ("test_allow_leading_v", test_allow_leading_v), + ("test_semVerRegex_invalid", test_semVerRegex_invalid), + ("test_init", test_init), + ("test_description", test_description), + ("test_Comparable", test_Comparable), + ("test_isStable", test_isStable), + ("test_isMajorRelease", test_isMajorRelease), + ("test_isMinorRelease", test_isMinorRelease), + ("test_isPatchRelease", test_isPatchRelease), + ] +} + +XCTMain([ + testCase(SemanticVersionTests.allTests) +]) + +#endif