Skip to content

Commit

Permalink
test(toml): Ensure tables are used for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 2, 2023
1 parent 43d7f29 commit c9b481c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crates/toml/tests/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ impl toml_test_harness::Decoder for Decoder {
fn decode(&self, data: &[u8]) -> Result<toml_test_harness::Decoded, toml_test_harness::Error> {
let data = std::str::from_utf8(data).map_err(toml_test_harness::Error::new)?;
let document = data
.parse::<toml::Value>()
.parse::<toml::Table>()
.map_err(toml_test_harness::Error::new)?;
value_to_decoded(&document)
let value = toml::Value::Table(document);
value_to_decoded(&value)
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/toml/tests/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ impl toml_test_harness::Encoder for Encoder {

fn encode(&self, data: toml_test_harness::Decoded) -> Result<String, toml_test_harness::Error> {
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)
}
}
Expand Down

0 comments on commit c9b481c

Please sign in to comment.