184d16b4a3
This commit fixes #279 where a case of duplicate table headers slipped through the cracks. This also adds an option to disable this new validation to allow Cargo to preserve backwards compatibility.
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
extern crate toml;
|
|
extern crate serde;
|
|
|
|
use serde::de::Deserialize;
|
|
|
|
#[test]
|
|
fn newlines_after_tables() {
|
|
let s = "
|
|
[a] foo = 1
|
|
[[b]] foo = 1
|
|
";
|
|
assert!(s.parse::<toml::Value>().is_err());
|
|
|
|
let mut d = toml::de::Deserializer::new(s);
|
|
d.set_require_newline_after_table(false);
|
|
let value = toml::Value::deserialize(&mut d).unwrap();
|
|
assert_eq!(value["a"]["foo"].as_integer(), Some(1));
|
|
assert_eq!(value["b"][0]["foo"].as_integer(), Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn allow_duplicate_after_longer() {
|
|
let s = "
|
|
[dependencies.openssl-sys]
|
|
version = 1
|
|
|
|
[dependencies]
|
|
libc = 1
|
|
|
|
[dependencies]
|
|
bitflags = 1
|
|
";
|
|
assert!(s.parse::<toml::Value>().is_err());
|
|
|
|
let mut d = toml::de::Deserializer::new(s);
|
|
d.set_allow_duplicate_after_longer_table(true);
|
|
let value = toml::Value::deserialize(&mut d).unwrap();
|
|
assert_eq!(value["dependencies"]["openssl-sys"]["version"].as_integer(), Some(1));
|
|
assert_eq!(value["dependencies"]["libc"].as_integer(), Some(1));
|
|
assert_eq!(value["dependencies"]["bitflags"].as_integer(), Some(1));
|
|
}
|