diff options
author | John-John Tedro <udoprog@tedro.se> | 2018-05-07 03:47:09 +0200 |
---|---|---|
committer | John-John Tedro <udoprog@tedro.se> | 2018-05-07 04:28:00 +0200 |
commit | 6ff5c445f37083c785111c904426c94b7a01f4b4 (patch) | |
tree | c77129d6c74c34e9c043566142dc6ab26644090a /test-suite/tests | |
parent | fd87ce35d563ecdac1f909d4540328365a16661f (diff) | |
download | milf-rs-6ff5c445f37083c785111c904426c94b7a01f4b4.tar.gz milf-rs-6ff5c445f37083c785111c904426c94b7a01f4b4.zip |
Use custom struct/field naming to deserialize spans
Diffstat (limited to 'test-suite/tests')
-rw-r--r-- | test-suite/tests/spanned.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test-suite/tests/spanned.rs b/test-suite/tests/spanned.rs new file mode 100644 index 0000000..fec9ea8 --- /dev/null +++ b/test-suite/tests/spanned.rs @@ -0,0 +1,30 @@ +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<T> { + foo: Spanned<T>, + } + + fn good<'de, T>(s: &'de str, expected: &str) where T: serde::Deserialize<'de> { + let foo: Foo<T> = 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::<String>("foo = \"foo\"", "\"foo\""); + good::<u32>("foo = 42", "42"); + good::<HashMap<String, u32>>( + "foo = {\"foo\" = 42, \"bar\" = 42}", + "{\"foo\" = 42, \"bar\" = 42}" + ); +} |