souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7b8e07d3baacaa57e1cf7d0d5370f534af72cecb
parent a54f903326c13b49131f647d7f35512188604a13
Author: Daniel Barlow <dan@telent.net>
Date:   Thu, 24 Oct 2024 17:59:59 +0100

check we read all <trkseg> not just the first

.. it turns out that elm-xml-decode does this already

Diffstat:
Msrc/Track.elm | 2+-
Mtests/Fixtures.elm | 12+++++++++++-
Mtests/TrackTest.elm | 24+++++++++++++-----------
3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/Track.elm b/src/Track.elm @@ -2,7 +2,7 @@ module Track exposing (Track, Point, parse) import Result import Xml.Decode as XD exposing (path, list, single, floatAttr, stringAttr) -import Time -- exposing (utc, toHour, toMinute, toSecond) +import Time import Iso8601 type alias Point = diff --git a/tests/Fixtures.elm b/tests/Fixtures.elm @@ -1,4 +1,7 @@ -module Fixtures exposing (threepoints) +module Fixtures exposing (threepoints, threepoints_expected) +import Track exposing (Track, Point) +import Time + threepoints = """ <?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> </gpxtpx:TrackPointExtension></extensions> </trkpt> +<!-- insert-segment --> <trkpt lat="51.600697" lon="-0.018064"> <ele>66.2</ele> <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> </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)) + ] diff --git a/tests/TrackTest.elm b/tests/TrackTest.elm @@ -4,23 +4,25 @@ import Fixtures import Track exposing (Track, Point) import Test exposing (..) import Expect exposing (Expectation) -import Time specs: Test specs = 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 - r = Track.parse Fixtures.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)) - ] - + xml = String.replace + "<!-- insert-segment -->" + "</trkseg><trkseg>" + Fixtures.threepoints in - case r of - (Ok trk) -> Expect.equalLists expected trk + case Track.parse xml of + (Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk _ -> Expect.fail "not ok" + ]