Skip to content

Commit

Permalink
feat(prop-strategies): add Integer strategy (need to fix tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestTvarynka committed Dec 8, 2023
1 parent 4036045 commit fb6253b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/asn1-parser/src/string/utf8_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
assert_eq!(
utf8_string.asn1(),
&Asn1Type::Utf8String(Utf8String {
id: 0,
id: 1,
string: Cow::Borrowed("thebesttvarynka"),
})
);
Expand Down
3 changes: 2 additions & 1 deletion crates/prop-strategies/src/constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use proptest::collection::vec;
use proptest::prop_oneof;
use proptest::strategy::{Just, Strategy};

use crate::{any_bit_string, any_bmp_string, any_bool, any_null, any_octet_string, any_utf8_string};
use crate::{any_bit_string, any_bmp_string, any_bool, any_integer, any_null, any_octet_string, any_utf8_string};

fn any_leaf_asn1_type() -> impl Strategy<Value = OwnedAsn1Type> {
prop_oneof![
Expand All @@ -13,6 +13,7 @@ fn any_leaf_asn1_type() -> impl Strategy<Value = OwnedAsn1Type> {
any_bmp_string().prop_map(Asn1Type::BmpString),
any_bool().prop_map(Asn1Type::Bool),
any_null().prop_map(Asn1Type::Null),
any_integer().prop_map(Asn1Type::Integer),
]
.no_shrink()
}
Expand Down
8 changes: 7 additions & 1 deletion crates/prop-strategies/src/generic_types.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use asn1_parser::{Bool, Null};
use asn1_parser::{Bool, Null, OwnedInteger};
use proptest::prelude::any;
use proptest::strategy::{Just, Strategy};

use crate::bytes;

pub fn any_bool() -> impl Strategy<Value = Bool> {
any::<bool>().prop_map(|flag| Bool::new(0, flag))
}

pub fn any_null() -> impl Strategy<Value = Null> {
Just(Null::default())
}

pub fn any_integer() -> impl Strategy<Value = OwnedInteger> {
bytes(1024).prop_map(|bytes| bytes.into())
}
1 change: 1 addition & 0 deletions crates/prop-strategies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn any_asn1_type() -> impl Strategy<Value = OwnedAsn1Type> {
any_bmp_string().prop_map(Asn1Type::BmpString),
any_bool().prop_map(Asn1Type::Bool),
any_null().prop_map(Asn1Type::Null),
any_integer().prop_map(Asn1Type::Integer),
recursive_empty_asn1_type(),
]
.no_shrink()
Expand Down

0 comments on commit fb6253b

Please sign in to comment.