Skip to content

Commit

Permalink
allow for 1.x.x / x.x / x.x.x wildcard types (Closes zafarkhaja#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
heisluft committed Mar 24, 2019
1 parent b6939b5 commit be1c672
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Library Additions by the AntiLaby team
[#36](https://github.com/zafarkhaja/jsemver/issues/36), [#38](https://github.com/zafarkhaja/jsemver/issues/38),
(#40), (#42),
[#43](https://github.com/zafarkhaja/jsemver/issues/43), [#44](https://github.com/zafarkhaja/jsemver/issues/44),
(#45), [#47](https://github.com/zafarkhaja/jsemver/issues/47)
[#45](https://github.com/zafarkhaja/jsemver/issues/45), [#47](https://github.com/zafarkhaja/jsemver/issues/47)
Issues in parenthesis are not dealt with yet, the others were implemented
* Issues Remaining:
* #9, #12, #15, #41
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ private boolean isWildcardRange() {
*
* <pre>
* {@literal
* <wildcard-range> ::= <wildcard>
* | <major> "." <wildcard>
* <wildcard-range> ::= <wildcard> (optional "." <wildcard> (optional "." <wildcard>))
* | <major> "." <wildcard> (optional "." <wildcard>)
* | <major> "." <minor> "." <wildcard>
*
* <wildcard> ::= "*" | "x" | "X"
Expand All @@ -316,13 +316,27 @@ private boolean isWildcardRange() {
private CompositeExpression parseWildcardRange() {
if (tokens.positiveLookahead(WILDCARD)) {
tokens.consume();
//silently omit trailing .x in x.x or x.x.x
if(tokens.positiveLookahead(DOT)) {
tokens.consume();
tokens.consume(WILDCARD);
}
if(tokens.positiveLookahead(DOT)) {
tokens.consume();
tokens.consume(WILDCARD);
}
return gte(versionFor(0, 0, 0));
}

int major = intOf(consumeNextToken(NUMERIC).lexeme);
consumeNextToken(DOT);
if (tokens.positiveLookahead(WILDCARD)) {
tokens.consume();
//silently omit trailing .x in eg. 2.x.x
if(tokens.positiveLookahead(DOT)) {
tokens.consume();
tokens.consume(WILDCARD);
}
return gte(versionFor(major)).and(lt(versionFor(major + 1)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,23 @@ public void shouldParsePartialVersionRange() {
@Test
public void shouldParseWildcardRange() {
ExpressionParser parser = new ExpressionParser(new ExprLexer());
Expression expr1 = parser.parse("1.*");
assertTrue(expr1.test(Version.valueOf("1.2.3")));
assertFalse(expr1.test(Version.valueOf("3.2.1")));
Expression expr2 = parser.parse("1.2.x");
assertTrue(expr2.test(Version.valueOf("1.2.3")));
assertFalse(expr2.test(Version.valueOf("1.3.2")));
Expression expr3 = parser.parse("X");
assertTrue(expr3.test(Version.valueOf("1.2.3")));
Version v1_2_3 = Version.forIntegers(1, 2, 3);
Version v3_2_1 = Version.forIntegers(3, 2, 1);
Expression expr1 = parser.parse("1.2.*");
assertTrue(expr1.test(v1_2_3));
assertFalse(expr1.test(v3_2_1));
Expression expr2 = parser.parse("1.x");
assertTrue(expr2.test(v1_2_3));
assertFalse(expr2.test(v3_2_1));
Expression expr3 = parser.parse("1.x.x");
assertTrue(expr3.test(v1_2_3));
assertFalse(expr3.test(v3_2_1));
Expression expr4 = parser.parse("X");
assertTrue(expr4.test(v1_2_3));
Expression expr5 = parser.parse("X.X");
assertTrue(expr5.test(v1_2_3));
Expression expr6 = parser.parse("X.X.X");
assertTrue(expr6.test(v1_2_3));
}

@Test
Expand Down

0 comments on commit be1c672

Please sign in to comment.