Skip to content

Commit

Permalink
Add equality operator for all structs. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion authored Jan 11, 2025
1 parent 5109628 commit 17aa935
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/GeoFormatTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ end
Formats representing coordinate reference systems
"""
abstract type CoordinateReferenceSystemFormat <: GeoFormat end
Base.:(==)(x::CoordinateReferenceSystemFormat, y::CoordinateReferenceSystemFormat) = x.val == y.val

"""
GeometryFormat <: GeoFormat
Expand All @@ -146,13 +147,15 @@ Formats representing geometries. These wrappers simply mark string
formats that may optionally be converted to Geoetry objects at a later point.
"""
abstract type GeometryFormat <: GeoFormat end
Base.:(==)(x::GeometryFormat, y::GeometryFormat) = x.val == y.val

"""
MixedFormat <: GeoFormat
Formats that may hold either or both coordinate reference systems and geometries.
"""
abstract type MixedFormat{X} <: GeoFormat end
Base.:(==)(x::MixedFormat, y::MixedFormat) = x.mode == y.mode && x.val == y.val

val(x::GeoFormat) = x.val

Expand Down
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ end
@test GeoFormatTypes.val(EPSG(4326, 3855)) == (4326, 3855)
end

@testset "Equality" begin
@test ProjString("+proj=test") == ProjString("+proj=test")
@test ProjJSON(Dict("type" => "GeographicCRS")) == ProjJSON(Dict("type" => "GeographicCRS"))
@test ProjJSON("type: GeographicCRS") == ProjJSON("type: GeographicCRS")
@test EPSG(4326) == EPSG(4326)
@test EPSG(4326) != EPSG(3855)
@test EPSG(4326) != EPSG(4326, 3855)
@test EPSG(4326) != EPSG(3855, 4326)
@test EPSG(4326, 3855) == EPSG(4326, 3855)
@test WellKnownText("test") == WellKnownText("test")
@test WellKnownBinary([1, 2, 3, 4]) == WellKnownBinary([1, 2, 3, 4])
@test WellKnownText2("test") == WellKnownText2("test")
@test ESRIWellKnownText("test") == ESRIWellKnownText("test")
@test WellKnownText(Extended(), "test") == WellKnownText(Extended(), "test")
@test WellKnownBinary(Extended(), [1, 2, 3, 4]) == WellKnownBinary(Extended(), [1, 2, 3, 4])
@test WellKnownText2(CRS(), "test") == WellKnownText2(CRS(), "test")
@test ESRIWellKnownText(Geom(), "test") == ESRIWellKnownText(Geom(), "test")
@test GML("test") == GML("test")
@test GML(Geom(), "test") == GML(Geom(), "test")
@test GML(CRS(), "test") == GML(CRS(), "test")
@test KML("test") == KML("test")
@test GeoJSON("test") == GeoJSON("test")
end

# `convert` placeholder methods
Base.convert(target::Type{<:GeoFormat}, mode::Union{Geom,Type{Geom}}, source::GeoFormat; kwargs...) =
(:geom, kwargs...)
Expand Down

0 comments on commit 17aa935

Please sign in to comment.