Skip to content

Commit 17aa935

Browse files
authored
Add equality operator for all structs. (#41)
1 parent 5109628 commit 17aa935

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/GeoFormatTypes.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ end
138138
Formats representing coordinate reference systems
139139
"""
140140
abstract type CoordinateReferenceSystemFormat <: GeoFormat end
141+
Base.:(==)(x::CoordinateReferenceSystemFormat, y::CoordinateReferenceSystemFormat) = x.val == y.val
141142

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

150152
"""
151153
MixedFormat <: GeoFormat
152154
153155
Formats that may hold either or both coordinate reference systems and geometries.
154156
"""
155157
abstract type MixedFormat{X} <: GeoFormat end
158+
Base.:(==)(x::MixedFormat, y::MixedFormat) = x.mode == y.mode && x.val == y.val
156159

157160
val(x::GeoFormat) = x.val
158161

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ end
5252
@test GeoFormatTypes.val(EPSG(4326, 3855)) == (4326, 3855)
5353
end
5454

55+
@testset "Equality" begin
56+
@test ProjString("+proj=test") == ProjString("+proj=test")
57+
@test ProjJSON(Dict("type" => "GeographicCRS")) == ProjJSON(Dict("type" => "GeographicCRS"))
58+
@test ProjJSON("type: GeographicCRS") == ProjJSON("type: GeographicCRS")
59+
@test EPSG(4326) == EPSG(4326)
60+
@test EPSG(4326) != EPSG(3855)
61+
@test EPSG(4326) != EPSG(4326, 3855)
62+
@test EPSG(4326) != EPSG(3855, 4326)
63+
@test EPSG(4326, 3855) == EPSG(4326, 3855)
64+
@test WellKnownText("test") == WellKnownText("test")
65+
@test WellKnownBinary([1, 2, 3, 4]) == WellKnownBinary([1, 2, 3, 4])
66+
@test WellKnownText2("test") == WellKnownText2("test")
67+
@test ESRIWellKnownText("test") == ESRIWellKnownText("test")
68+
@test WellKnownText(Extended(), "test") == WellKnownText(Extended(), "test")
69+
@test WellKnownBinary(Extended(), [1, 2, 3, 4]) == WellKnownBinary(Extended(), [1, 2, 3, 4])
70+
@test WellKnownText2(CRS(), "test") == WellKnownText2(CRS(), "test")
71+
@test ESRIWellKnownText(Geom(), "test") == ESRIWellKnownText(Geom(), "test")
72+
@test GML("test") == GML("test")
73+
@test GML(Geom(), "test") == GML(Geom(), "test")
74+
@test GML(CRS(), "test") == GML(CRS(), "test")
75+
@test KML("test") == KML("test")
76+
@test GeoJSON("test") == GeoJSON("test")
77+
end
78+
5579
# `convert` placeholder methods
5680
Base.convert(target::Type{<:GeoFormat}, mode::Union{Geom,Type{Geom}}, source::GeoFormat; kwargs...) =
5781
(:geom, kwargs...)

0 commit comments

Comments
 (0)