-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(srid): Lift CRS/SRS/SRID code to own file - add test
- Loading branch information
1 parent
0243987
commit 2bb4144
Showing
2 changed files
with
51 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package domain | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetOrDefault(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
srid SRID | ||
expected int | ||
}{ | ||
{"Positive SRID", SRID(28992), 28992}, | ||
{"Zero SRID", SRID(0), WGS84SRID}, | ||
{"Negative SRID", SRID(-1), WGS84SRID}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.expected, tt.srid.GetOrDefault()) | ||
}) | ||
} | ||
} | ||
|
||
func TestEpsgToSrid(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
srs string | ||
expected SRID | ||
expectError bool | ||
}{ | ||
{"Valid EPSG", "EPSG:28992", SRID(28992), false}, | ||
{"Invalid prefix", "INVALID:28992", SRID(-1), true}, | ||
{"Non-numeric EPSG code", "EPSG:ABC", SRID(-1), true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := EpsgToSrid(tt.srs) | ||
if tt.expectError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.expected, result) | ||
} | ||
}) | ||
} | ||
} |
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