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 e5a1a4a
Show file tree
Hide file tree
Showing 3 changed files with 231 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
40 changes: 40 additions & 0 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,43 @@ impl ValueRepr for Datetime {
Repr::new_unchecked(self.to_string())
}
}

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

proptest! {
#[test]
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]
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 e5a1a4a

Please sign in to comment.