Skip to content

Commit

Permalink
test(encode): Add property-based tests for keys/strings
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 17, 2024
1 parent 0b268f2 commit fbb0ac2
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 3 deletions.
193 changes: 190 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/toml_edit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ toml-test-harness = "0.4.8"
toml-test-data = "1.11.0"
libtest-mimic = "0.7.2"
snapbox = "0.6.0"
proptest = "1.5.0"

[[test]]
name = "testsuite"
Expand Down
42 changes: 42 additions & 0 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,45 @@ impl ValueRepr for Datetime {
Repr::new_unchecked(self.to_string())
}
}

#[cfg(test)]
mod test {
use super::*;
use proptest::prelude::*;

proptest! {
#[test]
#[cfg(feature = "parse")]
fn parseable_string(string in "\\PC*") {
let string = Value::from(string);
let encoded = string.to_string();
let _: Value = encoded.parse().unwrap_or_else(|err| {
panic!("error: {err}
string:
```
{string}
```
")
});
}
}

proptest! {
#[test]
#[cfg(feature = "parse")]
fn parseable_key(string in "\\PC*") {
let string = Key::new(string);
let encoded = string.to_string();
let _: Key = encoded.parse().unwrap_or_else(|err| {
panic!("error: {err}
string:
```
{string}
```
")
});
}
}
}

0 comments on commit fbb0ac2

Please sign in to comment.