Skip to content

Commit

Permalink
Allow ranges in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
goretkin committed Jun 17, 2019
1 parent 0aa9c7b commit 86f3f49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 9 additions & 0 deletions docs/src/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ PkgB = "≥ 1.2.3" # [1.2.3, ∞)
PkgC = "= 1.2.3" # [1.2.3, 1.2.3]
PkgD = "< 1.2.3" # [0.0.0, 1.2.2]
```

### Range specifiers

Ranges can also be used to specify version ranges:

```toml
[compat]
PkgA = ""0.1 - 0.2.3"" # [0.1.0, 0.2.3)
```
18 changes: 13 additions & 5 deletions src/versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,19 @@ function semver_spec(s::String)
for ver in split(s, ',')
range = nothing
found_match = false
for (ver_reg, f) in ver_regs
if occursin(ver_reg, ver)
range = f(match(ver_reg, ver))
found_match = true
break
try
range = VersionRange(ver)
found_match = true
catch err
(err isa ArgumentError) || rethrow()
end
if !found_match
for (ver_reg, f) in ver_regs
if occursin(ver_reg, ver)
range = f(match(ver_reg, ver))
found_match = true
break
end
end
end
found_match || error("invalid version specifier: $s")
Expand Down
4 changes: 4 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ import Pkg.Types: semver_spec, VersionSpec
@test v"1.2.3" in semver_spec(">=1.2.3")
@test !(v"1.2.2" in semver_spec(">=1.2.3"))

@test semver_spec("0.1.0 - 0.2.2") == VersionSpec("0.1.0 - 0.2.2")
@test semver_spec("0.1.0 - 0.2.2, 1.2") == VersionSpec(["0.1.0 - 0.2.2", "1.2.0-1"])
@test semver_spec("0.1.0 - 0.2.2, >=1.2") == VersionSpec(["0.1.0 - 0.2.2", "1.2.0-*"])

@test_throws ErrorException semver_spec("^^0.2.3")
@test_throws ErrorException semver_spec("^^0.2.3.4")
@test_throws ErrorException semver_spec("0.0.0")
Expand Down

0 comments on commit 86f3f49

Please sign in to comment.