sibil/types/src/bool.rs

51 lines
1.1 KiB
Rust
Raw Normal View History

2017-04-03 14:51:39 -04:00
/* types/bool.rs
* Eryn Wells <eryn@erynwells.me>
*/
use std::any::Any;
use super::value::*;
2017-04-03 14:51:39 -04:00
2017-04-08 16:35:11 -07:00
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Bool(pub bool);
2017-04-03 14:51:39 -04:00
impl Value for Bool {
fn as_value(&self) -> &Value { self }
2017-04-08 16:35:11 -07:00
fn is_bool(&self) -> bool { true }
2017-04-03 14:51:39 -04:00
}
impl ValueEq for Bool {
fn eq(&self, other: &Value) -> bool {
other.as_any().downcast_ref::<Self>().map_or(false, |x| x == self)
}
fn as_any(&self) -> &Any { self }
}
#[cfg(test)]
mod tests {
use super::Bool;
2017-04-08 16:35:11 -07:00
use value::*;
#[test]
2017-04-03 16:44:04 -04:00
fn equal_bools_are_equal() {
assert_eq!(Bool(true), Bool(true));
assert_eq!(Bool(false), Bool(false));
assert_ne!(Bool(true), Bool(false));
assert_eq!(Bool(true).as_value(), Bool(true).as_value());
assert_ne!(Bool(true).as_value(), Bool(false).as_value());
}
#[test]
fn bools_are_bools() {
assert_eq!(Bool(false).is_bool(), true);
2017-04-08 16:35:11 -07:00
assert_eq!(Bool(false).is_char(), false);
}
#[test]
fn bools_are_not_chars() {
assert_eq!(Bool(false).is_char(), false);
}
}