Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraint's aren't applied when mutating #2

Open
sadeli413 opened this issue May 13, 2024 · 0 comments
Open

Constraint's aren't applied when mutating #2

sadeli413 opened this issue May 13, 2024 · 0 comments

Comments

@sadeli413
Copy link

Making a separate issue because #1 is an issue in initialization.
When mutating, the constraints aren't applied. An issue and PR in the og repo addresses this for the ignore constraint.
landaire#2
landaire#3

use lain::prelude::*;
use lain::rand;

#[derive(Debug, Mutatable, NewFuzzed, BinarySerialize)]
struct MyStruct {
    #[lain(min = 5, max = 7)]
    field_1: u32,

    #[lain(min = 5, max = 7)]
    field_2: Vec<u8>,

    #[lain(ignore)]
    ignored_field: u32,
}

fn main() {
    let mut mutator = Mutator::new(rand::thread_rng());
    let mut instance = MyStruct::new_fuzzed(&mut mutator, None);

    for _ in 0..1000 {
        instance.mutate(&mut mutator, None);
        assert!((5..7).contains(&instance.field_1), "Got invalid field_1 value {}", instance.field_1);
        assert!((5..7).contains(&instance.field_2.len()), "Got invalid field_2 length {}", instance.field_2.len());
        assert_eq!(instance.ignored_field, u32::default(), "Got invalid ignored_field value {}", instance.ignored_field);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant