Crates.io | heckcheck |
lib.rs | heckcheck |
version | 2.0.1 |
source | src |
created_at | 2021-07-24 19:04:51.125684 |
updated_at | 2023-04-29 17:09:06.619714 |
description | A heckin small test case generator |
homepage | |
repository | https://github.com/yoshuawuyts/heckcheck |
max_upload_size | |
id | 426889 |
size | 38,283 |
$ cargo add heckcheck
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(())
});
This crate uses #![deny(unsafe_code)]
to ensure everything is implemented in
100% Safe Rust.
Want to join us? Check out our "Contributing" guide and take a look at some of these issues: