2017-04-03 14:51:39 -04:00
|
|
|
/* types/bool.rs
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
use std::any::Any;
|
2017-04-03 16:40:23 -04:00
|
|
|
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)]
|
2017-04-03 16:40:23 -04:00
|
|
|
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 }
|
|
|
|
}
|
2017-04-03 16:40:23 -04:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::Bool;
|
2017-04-08 16:35:11 -07:00
|
|
|
use value::*;
|
2017-04-03 16:40:23 -04:00
|
|
|
|
|
|
|
#[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() {
|
2017-04-03 16:40:23 -04:00
|
|
|
assert_eq!(Bool(false).is_bool(), true);
|
2017-04-08 16:35:11 -07:00
|
|
|
assert_eq!(Bool(false).is_char(), false);
|
2017-04-03 16:40:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bools_are_not_chars() {
|
|
|
|
assert_eq!(Bool(false).is_char(), false);
|
|
|
|
}
|
|
|
|
}
|