|
1 | 1 | using GeoFormatTypes, Test |
2 | 2 | using GeoFormatTypes: Geom, CRS, Mixed |
3 | 3 |
|
4 | | -@test_throws ArgumentError ProjString("+lat_ts=56.5 +ellps=GRS80") |
5 | | -convert(String, ProjString("+proj=merc +lat_ts=56.5 +ellps=GRS80")) == "+proj=merc +lat_ts=56.5 +ellps=GRS80" |
| 4 | +@testset "Test construcors" begin |
| 5 | + @test_throws ArgumentError ProjString("+lat_ts=56.5 +ellps=GRS80") |
| 6 | + @test_throws ArgumentError EPSG("ERROR:4326") |
| 7 | + @test EPSG("EPSG:4326") == EPSG(4326) |
| 8 | +end |
6 | 9 |
|
7 | | -@test_throws ArgumentError EPSG("ERROR:4326") |
8 | | -@test convert(String, EPSG("EPSG:4326")) == "EPSG:4326" |
9 | | -@test convert(String, EPSG(4326)) == "EPSG:4326" |
10 | | -@test convert(Int, EPSG("EPSG:4326")) == 4326 |
| 10 | +@testset "Test conversion to string or int" begin |
| 11 | + @test convert(String, ProjString("+proj=test")) == "+proj=test" |
| 12 | + @test convert(String, EPSG(4326)) == "EPSG:4326" |
| 13 | + @test convert(Int, EPSG(4326)) == 4326 |
| 14 | + @test convert(String, WellKnownText("test")) == "test" |
| 15 | + @test convert(String, WellKnownText2("test")) == "test" |
| 16 | + @test convert(String, GML("test")) == "test" |
| 17 | + @test convert(String, KML("test")) == "test" |
| 18 | + @test convert(String, GeoJSON("test")) == "test" |
| 19 | +end |
11 | 20 |
|
12 | | -@test convert(String, WellKnownText(Geom(), "test")) == "test" |
13 | | -@test convert(String, WellKnownText2(CRS(), "test")) == "test" |
14 | | -@test convert(String, ESRIWellKnownText(Geom(), "test")) == "test" |
15 | | -@test convert(String, GML(Mixed(), "test")) == "test" |
16 | | -@test convert(String, KML("test")) == "test" |
17 | | -@test convert(String, GeoJSON("test")) == "test" |
18 | 21 |
|
19 | | -@test_throws ArgumentError convert(KML, ProjString("+proj=test")) |
| 22 | +# `convert` placeholder methods |
| 23 | +Base.convert(target::Type{<:GeoFormat}, mode::Union{Geom,Type{Geom}}, source::GeoFormat) = |
| 24 | + :geom |
| 25 | +Base.convert(target::Type{<:GeoFormat}, mode::Union{CRS,Type{CRS}}, source::GeoFormat) = |
| 26 | + :crs |
| 27 | + |
| 28 | +@testset "Test convert mode allocation" begin |
| 29 | + @testset "Test identical type is passed through unchanged" begin |
| 30 | + @test convert(WellKnownText, WellKnownText(Mixed(), "test")) == WellKnownText(Mixed(), "test") |
| 31 | + @test convert(ProjString, ProjString("+proj=test")) == ProjString("+proj=test") |
| 32 | + end |
| 33 | + @testset "Test conversions are assigned to crs or geom correctly" begin |
| 34 | + @test convert(WellKnownText, WellKnownText2(CRS(), "test")) == :crs |
| 35 | + @test convert(WellKnownText2, WellKnownText(CRS(), "test")) == :crs |
| 36 | + @test convert(WellKnownBinary, WellKnownText(CRS(), "test")) == :crs |
| 37 | + @test convert(ProjString, WellKnownText(CRS(), "test")) == :crs |
| 38 | + @test convert(EPSG, ProjString("+proj=test")) == :crs |
| 39 | + @test convert(CoordSys, ProjString("+proj=test")) == :crs |
| 40 | + |
| 41 | + @test convert(GeoJSON, WellKnownText(Geom(), "test")) == :geom |
| 42 | + @test convert(KML, WellKnownText(Geom(), "test")) == :geom |
| 43 | + @test convert(GML, WellKnownText(Geom(), "test")) == :geom |
| 44 | + @test convert(ESRIWellKnownText, WellKnownText(Geom(), "test")) == :geom |
| 45 | + @test convert(WellKnownBinary, WellKnownText(Geom(), "test")) == :geom |
| 46 | + @test convert(WellKnownText2, WellKnownText(Geom(), "test")) == :geom |
| 47 | + @test convert(WellKnownText2, WellKnownText(Geom(), "test")) == :geom |
| 48 | + @test convert(WellKnownText, WellKnownText2(Geom(), "test")) == :geom |
| 49 | + |
| 50 | + @test convert(GeoJSON, WellKnownText(Mixed(), "test")) == :geom |
| 51 | + @test convert(KML, WellKnownText(Mixed(), "test")) == :geom |
| 52 | + @test convert(GML, WellKnownText(Mixed(), "test")) == :geom |
| 53 | + @test convert(ESRIWellKnownText, WellKnownText(Mixed(), "test")) == :geom |
| 54 | + @test convert(WellKnownBinary, WellKnownText(Mixed(), "test")) == :geom |
| 55 | + @test convert(WellKnownText2, WellKnownText(Mixed(), "test")) == :geom |
| 56 | + @test convert(WellKnownText2, WellKnownText(Mixed(), "test")) == :geom |
| 57 | + @test convert(WellKnownText, WellKnownText2(Mixed(), "test")) == :geom |
| 58 | + end |
| 59 | + @testset "Test conversions that are not possible throw an error" begin |
| 60 | + @test_throws ArgumentError convert(KML, ProjString("+proj=test")) |
| 61 | + @test_throws ArgumentError convert(GeoJSON, ProjString("+proj=test")) |
| 62 | + @test_throws ArgumentError convert(ProjString, WellKnownText(Geom(), "test")) |
| 63 | + @test_throws ArgumentError convert(CoordSys, WellKnownText(Geom(), "test")) |
| 64 | + @test_throws ArgumentError convert(EPSG, WellKnownText(Geom(), "test")) |
| 65 | + end |
| 66 | +end |
0 commit comments