diff --git a/gpx-rs/data/with_power_3.gpx b/gpx-rs/data/with_power_3.gpx new file mode 100644 index 000000000..35f7337c1 --- /dev/null +++ b/gpx-rs/data/with_power_3.gpx @@ -0,0 +1,505 @@ + + + + with_power + + gpx.studio + + + + + with_power + Cycling + + + 109.0 + + 200 + + + + 110.8 + + 200 + + + + 110.3 + + 200 + + + + 110.0 + + 200 + + + + 110.3 + + 200 + + + + 109.3 + + 200 + + + + 107.0 + + 200 + + + + 106.0 + + 200 + + + + 108.5 + + 200 + + + + 109.8 + + 200 + + + + 110.8 + + 200 + + + + 112.0 + + 200 + + + + 112.8 + + 200 + + + + 113.5 + + 200 + + + + 114.3 + + 200 + + + + 115.3 + + 200 + + + + 114.8 + + 200 + + + + 114.3 + + 200 + + + + 114.3 + + 200 + + + + 114.5 + + 200 + + + + 115.0 + + 200 + + + + 115.8 + + 200 + + + + 115.8 + + 200 + + + + 116.0 + + 200 + + + + 115.8 + + 200 + + + + 115.5 + + 200 + + + + 114.5 + + 200 + + + + 112.5 + + 200 + + + + 110.8 + + 200 + + + + 109.0 + + 200 + + + + 106.3 + + 200 + + + + 104.3 + + 200 + + + + 104.0 + + 200 + + + + 103.8 + + 200 + + + + 103.3 + + 200 + + + + 103.5 + + 200 + + + + 103.8 + + 200 + + + + 104.8 + + 200 + + + + 105.8 + + 200 + + + + 106.8 + + 200 + + + + 107.8 + + 200 + + + + 108.5 + + 200 + + + + 109.3 + + 200 + + + + 110.0 + + 200 + + + + 110.5 + + 200 + + + + 110.8 + + 200 + + + + 111.8 + + 200 + + + + 112.8 + + 200 + + + + 113.3 + + 200 + + + + 113.5 + + 200 + + + + 113.5 + + 200 + + + + 113.8 + + 200 + + + + 114.8 + + 200 + + + + 115.8 + + 200 + + + + 118.5 + + 200 + + + + 119.5 + + 200 + + + + 121.3 + + 200 + + + + 122.0 + + 200 + + + + 122.8 + + 200 + + + + 123.5 + + 200 + + + + 126.3 + + 200 + + + + 128.0 + + 200 + + + + 129.0 + + 200 + + + + 130.0 + + 200 + + + + 130.8 + + 200 + + + + 131.8 + + 200 + + + + 132.3 + + 200 + + + + 132.8 + + 200 + + + + 135.8 + + 200 + + + + 135.5 + + 200 + + + + 132.5 + + 200 + + + + 134.0 + + 200 + + + + 136.8 + + 200 + + + + 137.5 + + 200 + + + + 137.3 + + 200 + + + + 137.5 + + 200 + + + + 137.3 + + 200 + + + + 134.8 + + 200 + + + + 132.3 + + 200 + + + + 129.5 + + 210 + + + + + \ No newline at end of file diff --git a/gpx-rs/src/core/io/parse.rs b/gpx-rs/src/core/io/parse.rs index 7cb7351ed..f221f40eb 100644 --- a/gpx-rs/src/core/io/parse.rs +++ b/gpx-rs/src/core/io/parse.rs @@ -1222,6 +1222,19 @@ mod tests { assert!(trkpt.power.is_some_and(|p| p == 200)); } + #[test] + fn test_parse_trackpoint_power_3() { + let gpx = parse_data("with_power_3"); + + assert_eq!(gpx.trk.len(), 1); + let trk = &gpx.trk[0]; + assert_eq!(trk.trkseg.len(), 1); + let trkseg = &trk.trkseg[0]; + assert!(!trkseg.is_empty()); + let trkpt = &trkseg[0]; + assert!(trkpt.power.is_some_and(|p| p == 200)); + } + #[test] fn test_parse_trackpoint_atemp() { let gpx = parse_data("with_temp"); diff --git a/gpx-rs/src/core/io/write.rs b/gpx-rs/src/core/io/write.rs index 20cbc93c4..f615d34bd 100644 --- a/gpx-rs/src/core/io/write.rs +++ b/gpx-rs/src/core/io/write.rs @@ -402,9 +402,10 @@ fn write_point( Ok(()) })?; } + // `PowerInWatts` is itself the root element of Garmin's power extension, without a + // wrapper if let Some(power) = power { - w.create_element("gpxpx:PowerExtension") - .write_inner_content(|w| number(w, "gpxpx:PowerInWatts", power))?; + number(w, "gpxpx:PowerInWatts", power)?; } if !path.is_empty() { w.create_element("gpxx:RoutePointExtension") @@ -511,6 +512,7 @@ mod tests { "with_temp", "with_power_1", "with_power_2", + "with_power_3", "with_surface", "with_highway", "with_style", @@ -578,6 +580,16 @@ mod tests { assert_eq!(again.trk[0].info.name.as_deref(), Some("a & c")); } + #[test] + fn test_power_is_written_without_a_wrapper() { + let (file, categories) = read("with_power_2"); + let text: String = written_text(&file, &categories, ExportOptions::ALL) + .split_whitespace() + .collect(); + assert!(text.contains("200")); + assert!(!text.contains("")); + } + #[test] fn test_exportable_data() { let (file, _) = read("with_time");