Skip to content

Commit

Permalink
proptest utf8-reader
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored and szokeasaurusrex committed Jan 20, 2025
1 parent 946bbf7 commit c81365a
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
115 changes: 115 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ once_cell = "1.17.1"
parking_lot = "0.12.1"
pdb-addr2line = "0.10.4"
proguard = { version = "5.4.0", features = ["uuid"] }
proptest = "1.6.0"
regex = "1.7.1"
rustc-demangle = "0.1.21"
# keep this in sync with whatever version `goblin` uses
Expand Down
1 change: 1 addition & 0 deletions symbolic-debuginfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ zstd = { workspace = true, optional = true }
[dev-dependencies]
criterion = { workspace = true }
insta = { workspace = true }
proptest = {workspace = true }
tempfile = { workspace = true }
similar-asserts = { workspace = true }
symbolic-testutils = { path = "../symbolic-testutils" }
Expand Down
23 changes: 23 additions & 0 deletions symbolic-debuginfo/src/sourcebundle/utf8_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ where
mod tests {
use super::*;

use proptest::prelude::*;

use core::str;
use std::io::Cursor;

#[test]
Expand Down Expand Up @@ -280,4 +283,24 @@ mod tests {
.read_to_end(&mut vec![])
.expect_err("read should have errored");
}

proptest! {
#[test]
fn read_arbitrary_string(s in any::<String>()) {
let mut buf = vec![];
let mut reader = Utf8Reader::new(Cursor::new(&s));

reader.read_to_end(&mut buf).unwrap();
assert_eq!(str::from_utf8(&buf).unwrap(), s);
}

#[test]
fn dont_read_arbitrary_nonstring(s in any::<Vec<u8>>()) {
prop_assume!(str::from_utf8(&s).is_err());
let mut buf = vec![];
let mut reader = Utf8Reader::new(Cursor::new(&s));

reader.read_to_end(&mut buf).unwrap_err();
}
}
}

0 comments on commit c81365a

Please sign in to comment.