check we read all <trkseg> not just the first

.. it turns out that elm-xml-decode does this already
This commit is contained in:
Daniel Barlow 2024-10-24 17:59:59 +01:00
parent a54f903326
commit 7b8e07d3ba
3 changed files with 25 additions and 13 deletions

View File

@ -2,7 +2,7 @@ module Track exposing (Track, Point, parse)
import Result import Result
import Xml.Decode as XD exposing (path, list, single, floatAttr, stringAttr) import Xml.Decode as XD exposing (path, list, single, floatAttr, stringAttr)
import Time -- exposing (utc, toHour, toMinute, toSecond) import Time
import Iso8601 import Iso8601
type alias Point = type alias Point =

View File

@ -1,4 +1,7 @@
module Fixtures exposing (threepoints) module Fixtures exposing (threepoints, threepoints_expected)
import Track exposing (Track, Point)
import Time
threepoints = """ threepoints = """
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
@ -43,6 +46,7 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/
<cluetrust:distance>1,485.96</cluetrust:distance> <cluetrust:distance>1,485.96</cluetrust:distance>
</gpxtpx:TrackPointExtension></extensions> </gpxtpx:TrackPointExtension></extensions>
</trkpt> </trkpt>
<!-- insert-segment -->
<trkpt lat="51.600697" lon="-0.018064"> <trkpt lat="51.600697" lon="-0.018064">
<ele>66.2</ele> <ele>66.2</ele>
<time>2024-10-23T08:40:56.231+01:00</time> <time>2024-10-23T08:40:56.231+01:00</time>
@ -58,3 +62,9 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/
</trk> </trk>
</gpx> </gpx>
""" """
threepoints_expected =
[ (Point 51.600643 -0.01856 64.8 (Time.millisToPosix 1729669252256))
, (Point 51.600679 -0.018179 65.5 (Time.millisToPosix 1729669255259))
, (Point 51.600697 -0.018064 66.2 (Time.millisToPosix 1729669256231))
]

View File

@ -4,23 +4,25 @@ import Fixtures
import Track exposing (Track, Point) import Track exposing (Track, Point)
import Test exposing (..) import Test exposing (..)
import Expect exposing (Expectation) import Expect exposing (Expectation)
import Time
specs: Test specs: Test
specs = specs =
describe "XML Parsing" describe "XML Parsing"
[ test "it runs" <| [ test "it parses points" <|
\_ ->
case Track.parse Fixtures.threepoints of
(Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk
_ -> Expect.fail "not ok"
, test "multiple trksegs are coalesced" <|
\_ -> \_ ->
let let
r = Track.parse Fixtures.threepoints xml = String.replace
expected = "<!-- insert-segment -->"
[ (Point 51.600643 -0.01856 64.8 (Time.millisToPosix 1729669252256)) "</trkseg><trkseg>"
, (Point 51.600679 -0.018179 65.5 (Time.millisToPosix 1729669255259)) Fixtures.threepoints
, (Point 51.600697 -0.018064 66.2 (Time.millisToPosix 1729669256231))
]
in in
case r of case Track.parse xml of
(Ok trk) -> Expect.equalLists expected trk (Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk
_ -> Expect.fail "not ok" _ -> Expect.fail "not ok"
] ]