Skip to content

Commit

Permalink
Merge pull request #2 from wlisac/master
Browse files Browse the repository at this point in the history
Update regex to support partial versions
  • Loading branch information
samuelwford committed Feb 7, 2016
2 parents 76804ab + ccfb49b commit 3458fd3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SWFSemanticVersion/SWFSemanticVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ + (NSRegularExpression *)regex
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSError *error;
_regex = [NSRegularExpression regularExpressionWithPattern:@"\\A(\\d+\\.\\d+\\.\\d+)(-([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?\\Z" options:0 error:&error];
_regex = [NSRegularExpression regularExpressionWithPattern:@"\\A(\\d+\\.\\d+\\.\\d+)(-([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?\\Z|\\A(\\d+)\\Z|\\A(\\d+\\.\\d+)\\Z" options:0 error:&error];
});
return _regex;
}
Expand Down
27 changes: 27 additions & 0 deletions SWFSemanticVersionTests/SWFSemanticVersionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ - (void)tearDown
[super tearDown];
}

- (void)testSimplestPartialVersion
{
SWFSemanticVersion *semVer = [SWFSemanticVersion semanticVersionWithString:@"1"];

XCTAssert(semVer, @"where are you, semVer?");
XCTAssertEqualObjects(@1, semVer.major);
XCTAssertEqualObjects(@0, semVer.minor);
XCTAssertEqualObjects(@0, semVer.patch);
}

- (void)testPartialVersion
{
SWFSemanticVersion *semVer = [SWFSemanticVersion semanticVersionWithString:@"2.1"];

XCTAssert(semVer, @"where are you, semVer?");
XCTAssertEqualObjects(@2, semVer.major);
XCTAssertEqualObjects(@1, semVer.minor);
XCTAssertEqualObjects(@0, semVer.patch);
}

- (void)testSimplestVersion
{
SWFSemanticVersion *semVer = [SWFSemanticVersion semanticVersionWithString:@"0.1.0"];
Expand All @@ -34,6 +54,13 @@ - (void)testSimplestVersion
XCTAssertEqualObjects(@1, semVer.minor);
}

- (void)testInvalidPartialVersion
{
SWFSemanticVersion *semVer = [SWFSemanticVersion semanticVersionWithString:@"1-beta"];

XCTAssertNil(semVer, @"wha?");
}

- (void)testInvalidVersionsAreNil
{
SWFSemanticVersion *semVer = [SWFSemanticVersion semanticVersionWithString:@"pretzels"];
Expand Down

0 comments on commit 3458fd3

Please sign in to comment.