Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(toml): Demonstrate issues were fixed #471

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions crates/toml/tests/testsuite/tables_last.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use serde::Deserialize;
use serde::Serialize;

#[test]
Expand Down Expand Up @@ -28,3 +29,134 @@ fn always_works() {

toml::to_string(&a).unwrap();
}

#[test]
fn vec_of_vec_issue_387() {
#[derive(Deserialize, Serialize, Debug)]
struct Glyph {
components: Vec<Component>,
contours: Vec<Contour>,
}

#[derive(Deserialize, Serialize, Debug)]
struct Point {
x: f64,
y: f64,
pt_type: String,
}

type Contour = Vec<Point>;

#[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();
}

#[test]
fn vec_order_issue_356() {
#[derive(Serialize, Deserialize)]
struct Outer {
v1: Vec<Inner>,
v2: Vec<Inner>,
}

#[derive(Serialize, Deserialize)]
struct Inner {}

let outer = Outer {
v1: vec![Inner {}],
v2: vec![],
};
let s = toml::to_string_pretty(&outer).unwrap();
let _o: Outer = toml::from_str(&s).unwrap();
}

#[test]
fn values_before_tables_issue_403() {
#[derive(Serialize, Deserialize)]
struct A {
a: String,
b: String,
}

#[derive(Serialize, Deserialize)]
struct B {
a: String,
b: Vec<String>,
}

#[derive(Serialize, Deserialize)]
struct C {
a: A,
b: Vec<String>,
c: Vec<B>,
}
toml::to_string(&C {
a: A {
a: "aa".to_string(),
b: "ab".to_string(),
},
b: vec!["b".to_string()],
c: vec![B {
a: "cba".to_string(),
b: vec!["cbb".to_string()],
}],
})
.unwrap();
}