Skip to content

Commit

Permalink
fix(toml)!: toml! now generates a Table
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 23, 2023
1 parent 2ca6a82 commit 226639c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions crates/toml/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ pub use serde::de::{Deserialize, IntoDeserializer};

use crate::value::{Array, Table, Value};

/// Construct a [`toml::Value`] from TOML syntax.
///
/// [`toml::Value`]: value/enum.Value.html
/// Construct a [`Table`] from TOML syntax.
///
/// ```rust
/// let cargo_toml = toml::toml! {
Expand Down Expand Up @@ -32,7 +30,10 @@ macro_rules! toml {
let table = $crate::value::Table::new();
let mut root = $crate::Value::Table(table);
$crate::toml_internal!(@toplevel root [] $($toml)+);
root
match root {
$crate::Value::Table(table) => table,
_ => unreachable!(),
}
}};
}

Expand Down
14 changes: 7 additions & 7 deletions crates/toml/tests/testsuite/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn test_cargo_toml() {
},
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

#[test]
Expand Down Expand Up @@ -137,7 +137,7 @@ fn test_array() {
},
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

#[test]
Expand Down Expand Up @@ -188,7 +188,7 @@ fn test_number() {
"bin" => 214,
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

#[test]
Expand Down Expand Up @@ -278,7 +278,7 @@ fn test_datetime() {
},
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

// This test requires rustc >= 1.20.
Expand Down Expand Up @@ -306,7 +306,7 @@ fn test_quoted_key() {
},
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

#[test]
Expand All @@ -329,7 +329,7 @@ fn test_empty() {
},
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

#[test]
Expand Down Expand Up @@ -364,5 +364,5 @@ fn test_dotted_keys() {
},
};

assert_eq!(actual, expected);
assert_eq!(toml::Value::Table(actual), expected);
}

0 comments on commit 226639c

Please sign in to comment.