sibil/types/src/bool.rs

45 lines
986 B
Rust
Raw Normal View History

2017-04-22 09:30:28 -07:00
/* types/src/bool.rs
2017-04-03 14:51:39 -04:00
* Eryn Wells <eryn@erynwells.me>
*/
use std::fmt;
use object::Obj;
use preds;
/// The Scheme boolean type. It can be `True` or `False`.
pub enum Bool { True, False }
impl Obj for Bool { }
impl fmt::Display for Bool {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Bool::True => write!(f, "#t"),
Bool::False => write!(f, "#f")
2017-04-22 09:30:28 -07:00
}
2017-04-03 14:51:39 -04:00
}
}
impl preds::IsBool for Bool {
fn is_bool(&self) -> bool { true }
}
#[cfg(test)]
mod tests {
use object::Object;
use predicates::{IsBool, IsChar};
#[test]
fn bools_are_bools() {
assert_eq!(Object::Bool(false).is_bool(), true);
assert_eq!(Object::Bool(false).is_char(), false);
2017-04-03 16:44:04 -04:00
}
#[test]
fn equal_bools_are_equal() {
assert_eq!(Object::Bool(true), Object::Bool(true));
assert_eq!(Object::Bool(false), Object::Bool(false));
assert_ne!(Object::Bool(true), Object::Bool(false));
}
}