boolean tests
This commit is contained in:
parent
8d74cd6f3f
commit
77846511b2
@ -11,7 +11,7 @@ impl Serializable for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum BooleanParseError {
|
pub enum BooleanParseError {
|
||||||
OutOfBounds(u8),
|
OutOfBounds(u8),
|
||||||
Eof,
|
Eof,
|
||||||
@ -63,3 +63,34 @@ impl Atomic for bool {
|
|||||||
impl ConstSizeAtomic for bool {
|
impl ConstSizeAtomic for bool {
|
||||||
const SIZE: usize = 1;
|
const SIZE: usize = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_parse_false() {
|
||||||
|
assert_eq!(bool::parse_slice(&[0]).unwrap(), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_parse_true() {
|
||||||
|
assert_eq!(bool::parse_slice(&[1]).unwrap(), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cannot_parse_out_of_bound_value() {
|
||||||
|
assert_eq!(bool::parse_slice(&[2]).unwrap_err(), BooleanParseError::OutOfBounds(2));
|
||||||
|
assert_eq!(bool::parse_slice(&[2, 0]).unwrap_err(), BooleanParseError::OutOfBounds(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cannot_parse_empty_slice() {
|
||||||
|
assert_eq!(bool::parse_slice(&[]).unwrap_err(), BooleanParseError::Eof);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cannot_parse_extra_tail() {
|
||||||
|
assert_eq!(bool::parse_slice(&[0, 10, 20, 30]).unwrap_err(), BooleanParseError::ExtraData(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -61,7 +61,7 @@ mod tests {
|
|||||||
use crate::std::*;
|
use crate::std::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plain() -> Result<(), PlainParseError> {
|
fn can_parse_plain_slice() -> Result<(), PlainParseError> {
|
||||||
let plain = Plain::parse_slice(b"slice")?;
|
let plain = Plain::parse_slice(b"slice")?;
|
||||||
assert_eq!(plain.bytes().as_slice(), b"slice");
|
assert_eq!(plain.bytes().as_slice(), b"slice");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user