Skip to content

Commit

Permalink
Revert "Add partial isequal for VersionNumber (#42780)" (#42992)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Nov 8, 2021
1 parent fa6dcb0 commit e3b9290
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.
28 changes: 1 addition & 27 deletions base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ v"1.2.3"
julia> VersionNumber("2.0.1-rc1")
v"2.0.1-rc1"
```
See also: [`isequal`](@ref).
"""
struct VersionNumber
major::VInt
Expand Down Expand Up @@ -167,40 +166,15 @@ function ident_cmp(A::VerTuple, B::VerTuple)
length(B) < length(A) ? +1 : 0
end

"""
isequal(v1::VersionNumber, v2::VersionNumber; downto::Symbol = :patch)
Compare two VersionNumbers for equality in fields cascading down to the `downto` field of the VersionNumbers,
which by default is the `build` thus all fields are compared.
```julia-repl
julia> isequal(v"1.6", v"1.6.3")
false
julia> isequal(v"1.6", v"1.6.3", downto = :minor)
true
julia> isequal(v"1.5", v"1.6.3", downto = :major)
true
```
See also: [`VersionNumber`](@ref).
"""
function isequal(a::VersionNumber, b::VersionNumber; downto::Symbol = :build)
downto in fieldnames(VersionNumber) || error("Unrecognized `downto` value. Must be :major, :minor, :patch, :prerelease, or :build")
function ==(a::VersionNumber, b::VersionNumber)
(a.major != b.major) && return false
downto == :major && return true
(a.minor != b.minor) && return false
downto == :minor && return true
(a.patch != b.patch) && return false
downto == :patch && return true
(ident_cmp(a.prerelease, b.prerelease) != 0) && return false
downto == :prerelease && return true
(ident_cmp(a.build, b.build) != 0) && return false
return true
end

==(a::VersionNumber, b::VersionNumber) = isequal(a, b; downto = :build)

issupbuild(v::VersionNumber) = length(v.build)==1 && isempty(v.build[1])

function isless(a::VersionNumber, b::VersionNumber)
Expand Down
1 change: 0 additions & 1 deletion doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ Base.@static
```@docs
Base.VersionNumber
Base.@v_str
Base.isequal(::VersionNumber, ::VersionNumber)
```

## Errors
Expand Down
33 changes: 0 additions & 33 deletions test/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,6 @@ using Random
@test v"3.2+1.a" == VersionNumber(3, 2, 0, (), (1, "a"))
@test v"4.3.2+1.a" == VersionNumber(4, 3, 2, (), (1, "a"))

# full equality
@test isequal(v"1", v"1")
@test isequal(v"1", v"2") == false
@test isequal(v"1.2", v"1.2")
@test isequal(v"1.1", v"1.2") == false
@test isequal(v"1.2.3", v"1.2.3")
@test isequal(v"1.2.1", v"1.2.3") == false
@test isequal(v"1.2.3-dev", v"1.2.3-dev")
@test isequal(v"1.2.3", v"1.2.3-dev") == false
@test isequal(v"1.2.3-dev+1.a", v"1.2.3-dev+1.a")
@test isequal(v"1.2.3-dev", v"1.2.3-dev+1.a") == false

# partial equality
@test isequal(v"1", v"1", downto = :major)
@test isequal(v"1", v"1.2.3-dev+1.a", downto = :major)
@test isequal(v"1", v"2", downto = :major) == false

@test isequal(v"1.2", v"1.2", downto = :minor)
@test isequal(v"1.2", v"1.2.3-dev+1.a", downto = :minor)
@test isequal(v"1.1", v"1.2", downto = :minor) == false

@test isequal(v"1.2.3", v"1.2.3", downto = :patch)
@test isequal(v"1.2.3", v"1.2.3-dev+1.a", downto = :patch)
@test isequal(v"1.2.1", v"1.2.3", downto = :patch) == false

@test isequal(v"1.2.3-dev", v"1.2.3-dev", downto = :prerelease)
@test isequal(v"1.2.3-dev", v"1.2.3-dev+1.a", downto = :prerelease)
@test isequal(v"1.2.3-foo", v"1.2.3-dev+1.a", downto = :prerelease) == false

@test isequal(v"1.2.3-dev+1.a", v"1.2.3-dev+1.a", downto = :build)
@test isequal(v"1.2.3-dev", v"1.2.3-dev+1.a", downto = :build) == false
@test isequal(v"1.2.3-dev+2.a", v"1.2.3-dev+1.a", downto = :build) == false

# ArgumentErrors in constructor
@test_throws ArgumentError VersionNumber(4, 3, 2, ("nonalphanumeric!",), ())
@test_throws ArgumentError VersionNumber(4, 3, 2, ("nonalphanumeric!", 1), ())
Expand Down

2 comments on commit e3b9290

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.