Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update regex to support partial versions #2

Merged
merged 1 commit into from
Feb 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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