Skip to content

Commit

Permalink
Merge pull request #67 from carolynvs/require-space-in-ranges
Browse files Browse the repository at this point in the history
Require space in ranges
  • Loading branch information
mattfarina authored Apr 3, 2018
2 parents c2e7f6c + 97599fc commit 24642bd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
cvRegex))

constraintRangeRegex = regexp.MustCompile(fmt.Sprintf(
`\s*(%s)\s*-\s*(%s)\s*`,
`\s*(%s)\s* - \s*(%s)\s*`,
cvRegex, cvRegex))
}

Expand Down
44 changes: 38 additions & 6 deletions constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestParseConstraint(t *testing.T) {
}

if !constraintEq(tc.c, c) {
t.Errorf("Incorrect version found on %s", tc.in)
t.Errorf("%q produced constraint %q, but expected %q", tc.in, c, tc.c)
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestNewConstraint(t *testing.T) {
includeMin: true,
},
}, false},
{"3-4 || => 1.0, < 2", Union(
{"3 - 4 || => 1.0, < 2", Union(
rangeConstraint{
min: newV(3, 0, 0),
max: newV(4, 0, 0),
Expand All @@ -265,7 +265,7 @@ func TestNewConstraint(t *testing.T) {
},
), false},
// demonstrates union compression
{"3-4 || => 3.0, < 4", rangeConstraint{
{"3 - 4 || => 3.0, < 4", rangeConstraint{
min: newV(3, 0, 0),
max: newV(4, 0, 0),
includeMin: true,
Expand All @@ -292,6 +292,17 @@ func TestNewConstraint(t *testing.T) {
newV(1, 4, 0),
},
}, false},
{"1.1.0 - 12-abc123", rangeConstraint{
min: newV(1,1,0),
max: Version{major: 12, minor: 0, patch: 0, pre: "abc123"},
includeMin: true,
includeMax: true,
}, false},
{"1.1.0-12-abc123", Version{
major: 1,
minor: 1,
patch: 0,
pre: "12-abc123"}, false},
}

for _, tc := range tests {
Expand Down Expand Up @@ -545,9 +556,30 @@ func TestRewriteRange(t *testing.T) {
c string
nc string
}{
{"2-3", ">= 2, <= 3"},
{"2-3, 2-3", ">= 2, <= 3,>= 2, <= 3"},
{"2-3, 4.0.0-5.1", ">= 2, <= 3,>= 4.0.0, <= 5.1"},
{"2 - 3", ">= 2, <= 3"},
{"2 - 3, 2 - 3", ">= 2, <= 3,>= 2, <= 3"},
{"2 - 3, 4.0.0 - 5.1", ">= 2, <= 3,>= 4.0.0, <= 5.1"},
}

for _, tc := range tests {
o := rewriteRange(tc.c)

if o != tc.nc {
t.Errorf("Range %s rewritten incorrectly as '%s'", tc.c, o)
}
}
}

func TestRewriteRange_InvalidRange(t *testing.T) {
// Ranges require a space to be recognized

tests := []struct {
c string
nc string
}{
{"2-3", "2-3"},
{"2-3, 2 - 3","2-3,>= 2, <= 3"},
{"2-3, 4.0.0 - 5.1", "2-3,>= 4.0.0, <= 5.1"},
}

for _, tc := range tests {
Expand Down

0 comments on commit 24642bd

Please sign in to comment.