-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exercises the parser beyond what we currently do in unit tests
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Seeds for failure cases proptest has generated in the past. It is | ||
# automatically read and these particular cases re-run before any | ||
# novel cases are generated. | ||
# | ||
# It is recommended to check this file in to source control so that | ||
# everyone who runs the test benefits from these saved cases. | ||
cc 1663923d2fb0c804c5b850d10dd0ded1cbfc06dddf3f88faa4abf149b8430831 # shrinks to s = "" | ||
cc 829ba8833ee42816bc33d308b7a186452e36617f0fa0e771edea08fd07d78718 # shrinks to s = "0.40" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! `proptest`-powered property-based tests. | ||
|
||
use const_oid::{Error, ObjectIdentifier}; | ||
use proptest::prelude::*; | ||
use regex::Regex; | ||
|
||
prop_compose! { | ||
/// Produce a string of digits and dots, i.e. the component parts of OIDs. | ||
/// | ||
/// Note that this can be any permutation of digits-and-dots and does not necessarily | ||
/// represent a valid OID. | ||
fn oid_like_string()(bytes in any::<Vec<u8>>()) -> String { | ||
// Create a digit or dot from a byte input | ||
fn byte_to_char(byte: u8) -> char { | ||
match byte % 11 { | ||
n @ 0..=9 => (b'0' + n) as char, | ||
10 => '.', | ||
_ => unreachable!() | ||
} | ||
} | ||
|
||
|
||
let mut ret = String::with_capacity(bytes.len()); | ||
for byte in bytes { | ||
ret.push(byte_to_char(byte)); | ||
} | ||
ret | ||
} | ||
} | ||
|
||
proptest! { | ||
#[test] | ||
fn round_trip(s in oid_like_string()) { | ||
match ObjectIdentifier::new(&s) { | ||
Ok(oid) => { | ||
let oid_string = oid.to_string(); | ||
prop_assert_eq!(s, oid_string); | ||
}, | ||
Err(Error::ArcInvalid { .. }) | Err(Error::ArcTooBig) => (), | ||
Err(e) => { | ||
let re = Regex::new("^([0-2])((\\.0)|(\\.[1-9][0-9]*))*$").unwrap(); | ||
prop_assert!( | ||
!re.find(&s).is_some(), | ||
"regex asserts OID is valid, but `const-oid`failed: {}", | ||
&e | ||
); | ||
} | ||
} | ||
} | ||
} |