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

Require space in ranges #67

Merged
merged 2 commits into from
Apr 3, 2018
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 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*`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only nit would be that \s* and \s* could be replaced with \s+. The * is for zero or more while the + is for one or more.

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