require_relative "test_helper" require "maptool/gpx" class GpxTest < Minitest::Test def test_kinds_detects_waypoints_and_tracks assert_equal %w[waypoint track], Maptool::Gpx.kinds(fixture_path("sample.gpx")) end def test_to_geojson_produces_a_waypoint_point_feature geojson = Maptool::Gpx.to_geojson(fixture_path("sample.gpx")) waypoint = geojson["features"].find { |f| f["properties"]["kind"] == "waypoint" } assert_equal "Point", waypoint["geometry"]["type"] assert_equal [17.2, 48.1, 200.0], waypoint["geometry"]["coordinates"] assert_equal "Start", waypoint["properties"]["name"] assert_includes waypoint["properties"]["description"], "example.com" end def test_to_geojson_produces_a_track_multilinestring_with_stats geojson = Maptool::Gpx.to_geojson(fixture_path("sample.gpx")) track = geojson["features"].find { |f| f["properties"]["kind"] == "track" } assert_equal "MultiLineString", track["geometry"]["type"] assert_equal 3, track["geometry"]["coordinates"][0].size assert_equal "Morning Loop", track["properties"]["name"] assert_operator track["properties"]["distance_meters"], :>, 0 assert_equal 50.0, track["properties"]["elevation_gain_meters"], "200->250 is the only gain, 250->230 descent not subtracted" assert_equal 1200, track["properties"]["duration_secs"] end def test_invalid_xml_raises_parse_error path = File.join(Dir.mktmpdir, "bad.gpx") File.write(path, "") assert_raises(Maptool::Gpx::ParseError) { Maptool::Gpx.to_geojson(path) } end def test_non_gpx_root_raises_parse_error path = File.join(Dir.mktmpdir, "notgpx.gpx") File.write(path, "") assert_raises(Maptool::Gpx::ParseError) { Maptool::Gpx.to_geojson(path) } end end