5 stable releases

2.0.1 Apr 29, 2023
1.0.2 Jul 24, 2021

#867 in Parser implementations

Download history 287/week @ 2024-07-22 280/week @ 2024-07-29 316/week @ 2024-08-05 306/week @ 2024-08-12 324/week @ 2024-08-19 458/week @ 2024-08-26 508/week @ 2024-09-02 677/week @ 2024-09-09 627/week @ 2024-09-16 695/week @ 2024-09-23 591/week @ 2024-09-30 674/week @ 2024-10-07 487/week @ 2024-10-14 702/week @ 2024-10-21 667/week @ 2024-10-28 620/week @ 2024-11-04

2,476 downloads per month
Used in 2 crates

MIT/Apache

18KB
231 lines

heckcheck

A heckin small test case generator

Installation

$ cargo add heckcheck

Examples

This is a basic roundtrip test for an RGB serializer and parser, which ensures that the output matches the original input.

use heckcheck::prelude::*;

/// A color value encoded as Red-Green-Blue
#[derive(Clone, Debug, Arbitrary, PartialEq)]
pub struct Rgb {
    pub r: u8,
    pub g: u8,
    pub b: u8,
}

impl Rgb {
    /// Convert from RGB to Hexadecimal.
    pub fn to_hex(&self) -> String {
        format!("#{:02X}{:02X}{:02X}", self.r, self.g, self.b)
    }

    /// Convert from Hexadecimal to RGB.
    pub fn from_hex(s: String) -> Self {
        let s = s.strip_prefix('#').unwrap();
        Rgb {
            r: u8::from_str_radix(&s[0..2], 16).unwrap(),
            g: u8::from_str_radix(&s[2..4], 16).unwrap(),
            b: u8::from_str_radix(&s[4..6], 16).unwrap(),
        }
    }
}

// Validate values can be converted from RGB to Hex and back.
heckcheck::check(|rgb: Rgb| {
    let hex = rgb.to_hex();
    let res = Rgb::from_hex(hex);
    assert_eq!(rgb, res);
    Ok(())
});

Safety

This crate uses #![deny(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~665KB
~12K SLoC