aboutsummaryrefslogtreecommitdiff
path: root/test-suite/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test-suite/tests')
-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\"
+ ",
+ );
+}