diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 11:21:55 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 11:21:55 +0200 |
| commit | bef31e1d35fe88f2698cf0e3191f26a79623f66f (patch) | |
| tree | 8d8e10b2a58fc4ca557f0312cfda60adfc308c30 /ride/parser_test.go | |
| parent | 69f317d8cb51b911732712a9fcc8ac49563326c6 (diff) | |
feat: Add web ride library with Strava sync
Diffstat (limited to 'ride/parser_test.go')
| -rw-r--r-- | ride/parser_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ride/parser_test.go b/ride/parser_test.go new file mode 100644 index 0000000..db4907d --- /dev/null +++ b/ride/parser_test.go @@ -0,0 +1,46 @@ +package ride_test + +import ( + "strings" + "testing" + + "github.com/martinlehoux/biking_home/ride" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const parserTestGPXPrefix = `<?xml version="1.0"?><gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1"><trk><trkseg>` +const parserTestGPXSuffix = `</trkseg></trk></gpx>` + +func TestGPXRideParserSkipsStationaryPoints(t *testing.T) { + data := parserTestGPXPrefix + + `<trkpt lat="43.0" lon="5.0"><ele>100</ele></trkpt>` + + `<trkpt lat="43.0" lon="5.0"><ele>101</ele></trkpt>` + + `<trkpt lat="43.0" lon="5.0"><ele>102</ele></trkpt>` + + `<trkpt lat="43.001" lon="5.001"><ele>103</ele></trkpt>` + + parserTestGPXSuffix + + parsed, err := (ride.GPXRideParser{}).Parse(strings.NewReader(data)) + require.NoError(t, err) + assert.Len(t, parsed.Points(), 2) + assert.Greater(t, parsed.Points()[1].DistanceM, 0.0) +} + +func TestGPXRideParserRejectsStationaryRide(t *testing.T) { + data := parserTestGPXPrefix + + `<trkpt lat="43.0" lon="5.0"><ele>100</ele></trkpt>` + + `<trkpt lat="43.0" lon="5.0"><ele>101</ele></trkpt>` + + parserTestGPXSuffix + + _, err := (ride.GPXRideParser{}).Parse(strings.NewReader(data)) + require.Error(t, err) + assert.Equal(t, "zero distance", err.Error()) +} + +func TestGPXRideParserRejectsEmptyTrack(t *testing.T) { + data := parserTestGPXPrefix + parserTestGPXSuffix + + _, err := (ride.GPXRideParser{}).Parse(strings.NewReader(data)) + require.Error(t, err) + assert.Equal(t, "ride has no track points", err.Error()) +} |