Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Interoperate with Match.jl v2 (#33)
Browse files Browse the repository at this point in the history
* Also removes support for interoperation with `Rematch.jl` and `Rematch2.jl`.
* Remove `Manifest.toml` from the repository.
  • Loading branch information
Neal Gafter authored Aug 4, 2023
1 parent 70d7832 commit 4af0a63
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 199 deletions.
151 changes: 0 additions & 151 deletions Manifest.toml

This file was deleted.

9 changes: 4 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name = "AutoHashEqualsCached"
uuid = "887ad303-ad3a-4bc5-965e-507c643d6945"
authors = ["Neal Gafter <neal@gafter.com> and contributors"]
version = "0.2.2"
version = "0.3.0"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Rematch2 = "351a7294-9038-49b6-b9cf-e076b05af63f"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"

[compat]
Rematch = "0.3"
Match = "2"
julia = "1.6"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Rematch = "bfecab0d-fd4d-5014-a23f-56c5fae6447a"
Rematch2 = "351a7294-9038-49b6-b9cf-e076b05af63f"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
Expand Down
13 changes: 4 additions & 9 deletions src/AutoHashEqualsCached.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,11 @@ function auto_hash_equals_cached_impl(__source__::LineNumberNode, alt_hash_name,
$_show_default_auto_hash_equals_cached(io, x)
end)))

# Add functions to interoperate with Rematch and Rematch2 if they are loaded
# Add functions to interoperate with Match if loaded
# at the time the macro is expanded.
if_has_package("Rematch", Base.UUID("bfecab0d-fd4d-5014-a23f-56c5fae6447a"), v"0.3.3") do pkg
push!(result.args, esc(:(function $pkg.evaluated_fieldcount(::Type{$type_name})
$(length(member_names))
end)))
end
if_has_package("Rematch2", Base.UUID("351a7294-9038-49b6-b9cf-e076b05af63f"), v"0.2.6") do pkg
if :fieldnames in names(pkg; all=true)
push!(result.args, esc(:(function $pkg.fieldnames(::Type{$type_name})
if_has_package("Match", Base.UUID("7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"), v"2") do pkg
if :match_fieldnames in names(pkg; all=true)
push!(result.args, esc(:(function $pkg.match_fieldnames(::Type{$type_name})
$((member_names...,))
end)))
end
Expand Down
3 changes: 1 addition & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Rematch = "bfecab0d-fd4d-5014-a23f-56c5fae6447a"
Rematch2 = "351a7294-9038-49b6-b9cf-e076b05af63f"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
33 changes: 1 addition & 32 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using AutoHashEqualsCached: @auto_hash_equals, @auto_hash_equals_cached
using Markdown: plain
using Serialization
using Test
using Rematch: Rematch, @match, MatchFailure
using Match: Match, @match, MatchFailure
using Random

function serialize_and_deserialize(x)
Expand Down Expand Up @@ -235,37 +235,6 @@ myhash(o) = myhash(o, UInt(0x0))
end
end

@testset "test interoperation with Rematch" begin

@testset "test simple Rematch usage" begin
struct R157; x; y; end
@test (Rematch.@match R157(z,2) = R157(1,2)) == R157(1,2) && z == 1
@test_throws Rematch.MatchFailure Rematch.@match R157(x, 3) = R157(1,2)
@test (Rematch.@match R157(1,2) begin
R157(x=x1,y=y1) => (x1,y1)
end) == (1,2)
end

@testset "make sure Rematch works for types with cached hash code" begin
@auto_hash_equals_cached struct R158; x; y::Int; end
@test (Rematch.@match R158(x,2) = R158(1,2)) == R158(1,2) && x == 1
@test_throws Rematch.MatchFailure Rematch.@match R158(x, 3) = R158(1,2)
@test (Rematch.@match R158(1,2) begin
R158(x=x1,y=y1) => (x1,y1)
end) == (1,2)
end

@testset "make sure Rematch works for generic types with cached hash code" begin
@auto_hash_equals_cached struct R159{T}; x; y::T; end
@test (Rematch.@match R159(x,2) = R159(1,2)) == R159(1,2) && x == 1
@test_throws Rematch.MatchFailure Rematch.@match R159(x, 3) = R159(1,2)
@test (Rematch.@match R159(1,2) begin
R159(x=x1,y=y1) => (x1,y1)
end) == (1,2)
end

end

@testset "give an error if the struct contains internal constructors 4" begin
@test_throws internal_constructor_error begin
@macroexpand @auto_hash_equals_cached struct T156
Expand Down

0 comments on commit 4af0a63

Please sign in to comment.