aboutsummaryrefslogtreecommitdiff
path: root/test-suite
diff options
context:
space:
mode:
authorest31 <est31@users.noreply.github.com>2019-10-28 15:01:23 +0100
committerAlex Crichton <alex@alexcrichton.com>2019-10-28 09:01:23 -0500
commitec21d604f892a06999a9d38d38c903e083ad1f08 (patch)
tree28d5e177d3a8eeb8e7e2195363a4c1b823c11ea2 /test-suite
parente9f5290926dd7a5660f4f86bfc44591710079fe0 (diff)
downloadmilf-rs-ec21d604f892a06999a9d38d38c903e083ad1f08.tar.gz
milf-rs-ec21d604f892a06999a9d38d38c903e083ad1f08.zip
Support for dotted table spans (#340)
* "Support" spans for maps In toml you can declare maps via {} and via [name]. We can't obtain spans for [] maps but at least we can emit fake spans to make SpannedValue work. We also add a regression test. * Don't regress the inline table case * Also support arrays
Diffstat (limited to 'test-suite')
-rw-r--r--test-suite/tests/spanned.rs91
1 files changed, 90 insertions, 1 deletions
diff --git a/test-suite/tests/spanned.rs b/test-suite/tests/spanned.rs
index 1186645..d8f7a12 100644
--- a/test-suite/tests/spanned.rs
+++ b/test-suite/tests/spanned.rs
@@ -87,7 +87,54 @@ fn test_spanned_field() {
}
#[test]
-fn test_spanned_table() {
+fn test_inner_spanned_table() {
+ #[derive(Deserialize)]
+ struct Foo {
+ foo: Spanned<HashMap<Spanned<String>, Spanned<String>>>,
+ }
+
+ fn good(s: &str, zero: bool) {
+ let foo: Foo = toml::from_str(s).unwrap();
+
+ if zero {
+ assert_eq!(foo.foo.start(), 0);
+ // We'd actually have to assert equality with s.len() here,
+ // but the current implementation doesn't support that,
+ // and it's not possible with toml's data format to support it
+ // in the general case as spans aren't always well-defined.
+ // So this check mainly serves as a reminder that this test should
+ // be updated *if* one day there is support for emitting the actual span.
+ assert_eq!(foo.foo.end(), 0);
+ } else {
+ assert_eq!(foo.foo.start(), s.find("{").unwrap());
+ assert_eq!(foo.foo.end(), s.find("}").unwrap() + 1);
+ }
+ for (k, v) in foo.foo.get_ref().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\"
+ ",
+ true,
+ );
+
+ good(
+ "
+ foo = { a = 'b', bar = 'baz', c = 'd', e = \"f\" }",
+ false,
+ );
+}
+
+#[test]
+fn test_outer_spanned_table() {
#[derive(Deserialize)]
struct Foo {
foo: HashMap<Spanned<String>, Spanned<String>>,
@@ -158,3 +205,45 @@ fn test_spanned_nested() {
",
);
}
+
+#[test]
+fn test_spanned_array() {
+ #[derive(Deserialize)]
+ struct Foo {
+ foo: Vec<Spanned<HashMap<Spanned<String>, Spanned<String>>>>,
+ }
+
+ fn good(s: &str) {
+ let foo_list: Foo = toml::from_str(s).unwrap();
+
+ for foo in foo_list.foo.iter() {
+ assert_eq!(foo.start(), 0);
+ // We'd actually have to assert equality with s.len() here,
+ // but the current implementation doesn't support that,
+ // and it's not possible with toml's data format to support it
+ // in the general case as spans aren't always well-defined.
+ // So this check mainly serves as a reminder that this test should
+ // be updated *if* one day there is support for emitting the actual span.
+ assert_eq!(foo.end(), 0);
+ for (k, v) in foo.get_ref().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\"
+ [[foo]]
+ a = 'c'
+ bar = 'baz'
+ c = 'g'
+ e = \"h\"
+ ",
+ );
+}