mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-19 17:36:50 +00:00
Add a test to CFG, to see if it panics on clearly invalid garbage data
This commit is contained in:
parent
74940c0436
commit
170c61b556
2 changed files with 17 additions and 1 deletions
BIN
resources/tests/random
Normal file
BIN
resources/tests/random
Normal file
Binary file not shown.
18
src/cfg.rs
18
src/cfg.rs
|
@ -33,7 +33,7 @@ impl ConfigFile {
|
|||
let reader = BufReader::new(cursor);
|
||||
|
||||
let mut current_category: Option<String> = None;
|
||||
|
||||
|
||||
for line in reader.lines().flatten() {
|
||||
if !line.is_empty() && line != "\0" {
|
||||
if line.contains('<') || line.contains('>') {
|
||||
|
@ -131,6 +131,14 @@ mod tests {
|
|||
read(d).unwrap()
|
||||
}
|
||||
|
||||
fn common_setup_invalid() -> ByteBuffer {
|
||||
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
d.push("resources/tests");
|
||||
d.push("random");
|
||||
|
||||
read(d).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_parsing() {
|
||||
let cfg = common_setup();
|
||||
|
@ -150,4 +158,12 @@ mod tests {
|
|||
|
||||
assert_eq!(modified_cfg, cfg_buffer);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid() {
|
||||
let cfg = common_setup_invalid();
|
||||
|
||||
// Feeding it invalid data should not panic
|
||||
ConfigFile::from_existing(&cfg);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue