aboutsummaryrefslogtreecommitdiff
path: root/test-suite
diff options
context:
space:
mode:
authorest31 <est31@users.noreply.github.com>2019-09-16 23:32:45 +0200
committerAlex Crichton <alex@alexcrichton.com>2019-09-16 16:32:45 -0500
commit7c9b0a39db0c4c235db372f88d725fae6e82889f (patch)
tree84ca2de46f064f98a92712e4011417f76a2f5352 /test-suite
parent029908cfa6507ca7db0f74fe46854cc0043fe806 (diff)
downloadmilf-rs-7c9b0a39db0c4c235db372f88d725fae6e82889f.tar.gz
milf-rs-7c9b0a39db0c4c235db372f88d725fae6e82889f.zip
Support deserializing spanned keys (#333)
* Store key spans in the deserializer * Support deserializing spanned keys * Store key spans of the table header as well * Support nested table key spans as well
Diffstat (limited to 'test-suite')
-rw-r--r--test-suite/tests/spanned.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/test-suite/tests/spanned.rs b/test-suite/tests/spanned.rs
index 5130a72..1186645 100644
--- a/test-suite/tests/spanned.rs
+++ b/test-suite/tests/spanned.rs
@@ -85,3 +85,76 @@ fn test_spanned_field() {
// ending at something other than the absolute end
good::<u32>("foo = 42\nnoise = true", "42", Some(8));
}
+
+#[test]
+fn test_spanned_table() {
+ #[derive(Deserialize)]
+ struct Foo {
+ foo: HashMap<Spanned<String>, Spanned<String>>,
+ }
+
+ fn good(s: &str) {
+ let foo: Foo = toml::from_str(s).unwrap();
+
+ for (k, v) in foo.foo.iter() {
+ assert_eq!(&s[k.start()..k.end()], k.get_ref());
+ assert_eq!(&s[(v.start() + 1)..(v.end() - 1)], v.get_ref());
+ }
+ }
+
+ good(
+ "
+ [foo]
+ a = 'b'
+ bar = 'baz'
+ c = 'd'
+ e = \"f\"
+ ",
+ );
+
+ good(
+ "
+ foo = { a = 'b', bar = 'baz', c = 'd', e = \"f\" }
+ ",
+ );
+}
+
+#[test]
+fn test_spanned_nested() {
+ #[derive(Deserialize)]
+ struct Foo {
+ foo: HashMap<Spanned<String>, HashMap<Spanned<String>, Spanned<String>>>,
+ }
+
+ fn good(s: &str) {
+ let foo: Foo = toml::from_str(s).unwrap();
+
+ for (k, v) in foo.foo.iter() {
+ assert_eq!(&s[k.start()..k.end()], k.get_ref());
+ for (n_k, n_v) in v.iter() {
+ assert_eq!(&s[n_k.start()..n_k.end()], n_k.get_ref());
+ assert_eq!(&s[(n_v.start() + 1)..(n_v.end() - 1)], n_v.get_ref());
+ }
+ }
+ }
+
+ good(
+ "
+ [foo.a]
+ a = 'b'
+ c = 'd'
+ e = \"f\"
+ [foo.bar]
+ baz = 'true'
+ ",
+ );
+
+ good(
+ "
+ [foo]
+ foo = { a = 'b', bar = 'baz', c = 'd', e = \"f\" }
+ bazz = {}
+ g = { h = 'i' }
+ ",
+ );
+}