-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "MLStyle" | ||
uuid = "d8e11817-5142-5d16-987a-aa16d5891078" | ||
authors = ["thautwarm <[email protected]>"] | ||
version = "0.4.16" | ||
version = "0.4.17" | ||
|
||
[deps] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using MLStyle | ||
import MLStyle.AbstractPatterns | ||
|
||
abstract type Enum154 end | ||
|
||
struct Enum154_1_Cons <: Enum154 end | ||
|
||
struct Enum154_2_Cons <: Enum154 | ||
x::Vector{Int} | ||
end | ||
MLStyle.@as_record Enum154_2_Cons | ||
|
||
MLStyle.is_enum(::Enum154) = true | ||
MLStyle.enum_matcher(enum::Enum154, expr) = :($enum === $expr) | ||
|
||
const Enum154_1 = Enum154_1_Cons() | ||
|
||
function Base.:(==)(a::Enum154, b::Enum154) | ||
@match (a, b) begin | ||
(Enum154_1, Enum154_1) => true | ||
(Enum154_2_Cons(xs), Enum154_2_Cons(ys)) => xs == ys | ||
_ => false | ||
end | ||
end | ||
|
||
# traditional behaviour | ||
|
||
@enum JuliaEnum_154 begin | ||
JuliaEnum_154_a | ||
JuliaEnum_154_b | ||
JuliaEnum_154_c | ||
end | ||
|
||
MLStyle.is_enum(::JuliaEnum_154) = true | ||
|
||
MLStyle.pattern_uncall(a::JuliaEnum_154, ::Vararg) = MLStyle.AbstractPatterns.literal(a) | ||
|
||
function eq_154(a, b) | ||
@match (a, b) begin | ||
(JuliaEnum_154_a, JuliaEnum_154_a) => true | ||
(JuliaEnum_154_b, JuliaEnum_154_b) => true | ||
(JuliaEnum_154_c, JuliaEnum_154_c) => true | ||
_ => false | ||
end | ||
end | ||
|
||
@testset "issue 154" begin | ||
@testset "tag matching support" begin | ||
@test Enum154_1 == Enum154_1 | ||
@test Enum154_2_Cons([1, 2, 3]) == Enum154_2_Cons([1, 2, 3]) | ||
@test Enum154_2_Cons([1, 2, 3]) != Enum154_2_Cons([1, 2, 4]) | ||
@test Enum154_1 != Enum154_2_Cons([1, 2, 3]) | ||
end | ||
|
||
@testset "traditional" begin | ||
@test eq_154(JuliaEnum_154_a, JuliaEnum_154_a) | ||
@test eq_154(JuliaEnum_154_b, JuliaEnum_154_b) | ||
@test eq_154(JuliaEnum_154_c, JuliaEnum_154_c) | ||
@test !eq_154(JuliaEnum_154_a, JuliaEnum_154_b) | ||
@test !eq_154(JuliaEnum_154_b, JuliaEnum_154_c) | ||
@test !eq_154(JuliaEnum_154_c, JuliaEnum_154_a) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c582f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register branch=main
c582f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/77551
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: