extern crate serde; extern crate toml; #[macro_use] extern crate serde_derive; use toml::Spanned; use std::collections::HashMap; #[test] fn test_spanned_field() { #[derive(Deserialize)] struct Foo { foo: Spanned, } fn good<'de, T>(s: &'de str, expected: &str) where T: serde::Deserialize<'de> { let foo: Foo = toml::from_str(s).unwrap(); assert_eq!(6, foo.foo.start); assert_eq!(s.len(), foo.foo.end); assert_eq!(expected, &s[foo.foo.start..foo.foo.end]); } good::("foo = \"foo\"", "\"foo\""); good::("foo = 42", "42"); // leading plus good::("foo = +42", "+42"); // table good::>( "foo = {\"foo\" = 42, \"bar\" = 42}", "{\"foo\" = 42, \"bar\" = 42}" ); // array good::>( "foo = [0, 1, 2, 3, 4]", "[0, 1, 2, 3, 4]" ); // datetime good::( "foo = \"1997-09-09T09:09:09Z\"", "\"1997-09-09T09:09:09Z\"" ); }