From 6906cd267df73018df7600e63086073dee057e85 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 19 Jan 2023 14:34:04 -0600 Subject: [PATCH] test(toml): Show trailing comma is fixed With #470, we more reliably generate valid output. Fixes #387 --- crates/toml/tests/testsuite/tables_last.rs | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/crates/toml/tests/testsuite/tables_last.rs b/crates/toml/tests/testsuite/tables_last.rs index 3339e0a0..fadadd1c 100644 --- a/crates/toml/tests/testsuite/tables_last.rs +++ b/crates/toml/tests/testsuite/tables_last.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use serde::Deserialize; use serde::Serialize; #[test] @@ -28,3 +29,81 @@ fn always_works() { toml::to_string(&a).unwrap(); } + +#[test] +fn vec_of_vec_issue_387() { + #[derive(Deserialize, Serialize, Debug)] + struct Glyph { + components: Vec, + contours: Vec, + } + + #[derive(Deserialize, Serialize, Debug)] + struct Point { + x: f64, + y: f64, + pt_type: String, + } + + type Contour = Vec; + + #[derive(Deserialize, Serialize, Debug)] + struct Component { + base: String, + transform: (f64, f64, f64, f64, f64, f64), + } + + let comp1 = Component { + base: "b".to_string(), + transform: (1.0, 0.0, 0.0, 1.0, 0.0, 0.0), + }; + let comp2 = Component { + base: "c".to_string(), + transform: (1.0, 0.0, 0.0, 1.0, 0.0, 0.0), + }; + let components = vec![comp1, comp2]; + + let contours = vec![ + vec![ + Point { + x: 3.0, + y: 4.0, + pt_type: "line".to_string(), + }, + Point { + x: 5.0, + y: 6.0, + pt_type: "line".to_string(), + }, + ], + vec![ + Point { + x: 0.0, + y: 0.0, + pt_type: "move".to_string(), + }, + Point { + x: 7.0, + y: 9.0, + pt_type: "offcurve".to_string(), + }, + Point { + x: 8.0, + y: 10.0, + pt_type: "offcurve".to_string(), + }, + Point { + x: 11.0, + y: 12.0, + pt_type: "curve".to_string(), + }, + ], + ]; + let g1 = Glyph { + contours, + components, + }; + + let s = toml::to_string_pretty(&g1).unwrap(); + let _g2: Glyph = toml::from_str(&s).unwrap(); +}