[types] Move tests to tests/ directory; implement a bunch of Display tests
This commit is contained in:
parent
d10c72711b
commit
31081ba5a9
4 changed files with 66 additions and 15 deletions
|
@ -54,7 +54,7 @@ impl Obj {
|
||||||
impl fmt::Display for Obj {
|
impl fmt::Display for Obj {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Obj::Null => write!(f, "null"),
|
Obj::Null => write!(f, "()"),
|
||||||
Obj::Ptr(obj) => write!(f, "{}", obj)
|
Obj::Ptr(obj) => write!(f, "{}", obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@ pub struct Pair {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pair {
|
impl Pair {
|
||||||
|
pub fn new(car: Obj, cdr: Obj) -> Pair {
|
||||||
|
Pair { car, cdr }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn empty() -> Pair {
|
pub fn empty() -> Pair {
|
||||||
Pair { car: Obj::Null, cdr: Obj::Null }
|
Pair { car: Obj::Null, cdr: Obj::Null }
|
||||||
}
|
}
|
||||||
|
@ -52,11 +56,4 @@ impl fmt::Display for Pair {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Pair;
|
use super::Pair;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn display_empty_pair() {
|
|
||||||
let empty = Pair::empty();
|
|
||||||
let disp = format!("{}", empty);
|
|
||||||
assert_eq!(disp, "(())");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,13 +38,6 @@ impl fmt::Display for Sym {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Sym;
|
use super::Sym;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn syms_display_as_strings() {
|
|
||||||
let sym = Sym::with_str("abc");
|
|
||||||
let disp = format!("{}", sym);
|
|
||||||
assert_eq!(disp, "abc");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn syms_with_the_same_name_are_equal() {
|
fn syms_with_the_same_name_are_equal() {
|
||||||
let a = Sym::with_str("abc");
|
let a = Sym::with_str("abc");
|
||||||
|
|
61
types/tests/display.rs
Normal file
61
types/tests/display.rs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/* types/tests/display.rs
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! Tests of how various types implement Display.
|
||||||
|
|
||||||
|
extern crate sibiltypes;
|
||||||
|
|
||||||
|
use sibiltypes::{Obj, Pair, Sym};
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_pairs_display_correctly() {
|
||||||
|
let empty = Pair::empty();
|
||||||
|
let disp = format!("{}", empty);
|
||||||
|
assert_eq!(disp, "(())");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pair_with_only_car_is_single_element_list() {
|
||||||
|
let sym = Obj::new(Sym::with_str("ab"));
|
||||||
|
let pair = Pair::with_car(sym);
|
||||||
|
let disp = format!("{}", pair);
|
||||||
|
assert_eq!(disp, "(ab)");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pair_with_car_and_cdr_is_dotted_pair() {
|
||||||
|
let ab = Obj::new(Sym::with_str("ab"));
|
||||||
|
let cd = Obj::new(Sym::with_str("cd"));
|
||||||
|
let pair = Pair::new(ab, cd);
|
||||||
|
let disp = format!("{}", pair);
|
||||||
|
assert_eq!(disp, "(ab . cd)");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_pair_list_displays_as_list() {
|
||||||
|
let ab = Obj::new(Sym::with_str("ab"));
|
||||||
|
let cd = Obj::new(Sym::with_str("cd"));
|
||||||
|
let pair = Pair::new(ab, Obj::new(Pair::with_car(cd)));
|
||||||
|
let disp = format!("{}", pair);
|
||||||
|
assert_eq!(disp, "(ab cd)");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn three_element_list_with_full_second_pair() {
|
||||||
|
let ab = Obj::new(Sym::with_str("ab"));
|
||||||
|
let cd = Obj::new(Sym::with_str("cd"));
|
||||||
|
let ef = Obj::new(Sym::with_str("ef"));
|
||||||
|
let pair = Pair::new(ab, Obj::new(Pair::new(cd, ef)));
|
||||||
|
let disp = format!("{}", pair);
|
||||||
|
assert_eq!(disp, "(ab cd . ef)");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn syms_display_as_strings() {
|
||||||
|
let sym = Sym::with_str("abc");
|
||||||
|
let disp = format!("{}", sym);
|
||||||
|
assert_eq!(disp, "abc");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue