From c9b481cab5038e9801e60f6bfb935f983218d8f6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 2 Oct 2023 14:46:28 -0500 Subject: [PATCH] test(toml): Ensure tables are used for validation --- crates/toml/tests/decoder.rs | 5 +++-- crates/toml/tests/encoder.rs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/toml/tests/decoder.rs b/crates/toml/tests/decoder.rs index fe6db3f5..5af906f3 100644 --- a/crates/toml/tests/decoder.rs +++ b/crates/toml/tests/decoder.rs @@ -11,9 +11,10 @@ impl toml_test_harness::Decoder for Decoder { fn decode(&self, data: &[u8]) -> Result { let data = std::str::from_utf8(data).map_err(toml_test_harness::Error::new)?; let document = data - .parse::() + .parse::() .map_err(toml_test_harness::Error::new)?; - value_to_decoded(&document) + let value = toml::Value::Table(document); + value_to_decoded(&value) } } diff --git a/crates/toml/tests/encoder.rs b/crates/toml/tests/encoder.rs index eda62963..e76a74a2 100644 --- a/crates/toml/tests/encoder.rs +++ b/crates/toml/tests/encoder.rs @@ -10,7 +10,10 @@ impl toml_test_harness::Encoder for Encoder { fn encode(&self, data: toml_test_harness::Decoded) -> Result { let value = from_decoded(&data)?; - let s = toml::to_string(&value).map_err(toml_test_harness::Error::new)?; + let toml::Value::Table(document) = value else { + return Err(toml_test_harness::Error::new("no root table")); + }; + let s = toml::to_string(&document).map_err(toml_test_harness::Error::new)?; Ok(s) } }