Clean up tests for bool, char, and the lib
This commit is contained in:
parent
25c24852cd
commit
c3a2247fdd
3 changed files with 31 additions and 53 deletions
|
|
@ -16,23 +16,19 @@ impl IsBool for Object {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Bool;
|
use object::Object;
|
||||||
use value::*;
|
use predicates::{IsBool, IsChar};
|
||||||
|
|
||||||
#[test]
|
|
||||||
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]
|
#[test]
|
||||||
fn bools_are_bools() {
|
fn bools_are_bools() {
|
||||||
assert_eq!(Bool(false).is_bool(), true);
|
assert_eq!(Object::Bool(false).is_bool(), true);
|
||||||
assert_eq!(Bool(false).is_char(), false);
|
assert_eq!(Object::Bool(false).is_char(), false);
|
||||||
assert_eq!(Bool(false).is_number(), false);
|
}
|
||||||
|
|
||||||
|
#[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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,47 +2,31 @@
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::any::Any;
|
use object::Object;
|
||||||
use super::value::*;
|
use predicates::IsChar;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
impl IsChar for Object {
|
||||||
pub struct Char(pub char);
|
fn is_char(&self) -> bool {
|
||||||
|
match *self {
|
||||||
impl Value for Char {
|
Object::Char(_) => true,
|
||||||
fn as_value(&self) -> &Value { self }
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IsChar for Char {
|
|
||||||
fn is_char(&self) -> bool { true }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IsBool for Char { }
|
|
||||||
impl IsNumber for Char { }
|
|
||||||
|
|
||||||
impl ValueEq for Char {
|
|
||||||
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Char;
|
use object::Object;
|
||||||
use value::*;
|
use predicates::{IsBool, IsChar};
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn equal_chars_are_equal() {
|
|
||||||
assert_eq!(Char('a'), Char('a'));
|
|
||||||
assert_eq!(Char('a').as_value(), Char('a').as_value());
|
|
||||||
assert_ne!(Char('a').as_value(), Char('b').as_value());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chars_are_chars() {
|
fn chars_are_chars() {
|
||||||
assert_eq!(Char('a').is_char(), true);
|
assert_eq!(Object::Char('a').is_char(), true);
|
||||||
assert_eq!(Char('a').is_bool(), false);
|
assert_eq!(Object::Char('a').is_bool(), false);
|
||||||
assert_eq!(Char('a').is_number(), false);
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn equal_chars_are_equal() {
|
||||||
|
assert_eq!(Object::Char('a'), Object::Char('a'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//pub mod number;
|
//pub mod number;
|
||||||
mod bool;
|
mod bool;
|
||||||
//mod char;
|
mod char;
|
||||||
mod number;
|
mod number;
|
||||||
mod object;
|
mod object;
|
||||||
mod predicates;
|
mod predicates;
|
||||||
|
|
@ -10,12 +10,10 @@ pub use predicates::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bool::Bool;
|
use super::Object;
|
||||||
use char::Char;
|
|
||||||
use value::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn booleans_and_chars_are_not_equal() {
|
fn booleans_and_chars_are_not_equal() {
|
||||||
assert_ne!(Bool(true).as_value(), Char('a').as_value());
|
assert_ne!(Object::Bool(true), Object::Char('a'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue