Implement IsBool and IsChar for Char and Bool

This commit is contained in:
Eryn Wells 2017-04-03 16:40:23 -04:00
parent 704c342a6f
commit 3cb1824a1b
2 changed files with 51 additions and 4 deletions

View file

@ -3,10 +3,10 @@
*/
use std::any::Any;
use super::value::{Value, ValueEq};
use super::value::*;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Bool(bool);
pub struct Bool(pub bool);
impl Bool {
pub fn new(v: bool) -> Bool { Bool(v) }
@ -23,3 +23,27 @@ impl ValueEq for Bool {
fn as_any(&self) -> &Any { self }
}
impl IsBool for Bool {
fn is_bool(&self) -> bool { true }
}
impl IsChar for Bool {
fn is_char(&self) -> bool { false }
}
#[cfg(test)]
mod tests {
use super::Bool;
use types::value::{IsBool, IsChar};
#[test]
fn chars_are_bools() {
assert_eq!(Bool(false).is_bool(), true);
}
#[test]
fn bools_are_not_chars() {
assert_eq!(Bool(false).is_char(), false);
}
}

View file

@ -3,10 +3,10 @@
*/
use std::any::Any;
use super::value::{Value, ValueEq};
use super::value::*;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Char(char);
pub struct Char(pub char);
impl Char {
pub fn new(v: char) -> Char { Char(v) }
@ -24,3 +24,26 @@ impl ValueEq for Char {
fn as_any(&self) -> &Any { self }
}
impl IsBool for Char {
fn is_bool(&self) -> bool { false }
}
impl IsChar for Char {
fn is_char(&self) -> bool { true }
}
#[cfg(test)]
mod tests {
use super::Char;
use types::value::{IsBool, IsChar};
#[test]
fn chars_are_chars() {
assert_eq!(Char('a').is_char(), true);
}
#[test]
fn chars_are_not_bools() {
assert_eq!(Char('a').is_bool(), false);
}
}