[types] Add some unit tests for Sym

This commit is contained in:
Eryn Wells 2018-08-25 08:18:32 -07:00
parent cd7ea8f543
commit 3024efe65e

View file

@ -7,12 +7,19 @@ use std::fmt;
use object::Object; use object::Object;
use super::*; use super::*;
#[derive(Debug, PartialEq)]
pub struct Sym(String); pub struct Sym(String);
impl Sym { impl Sym {
/// Creates a Sym with the given String.
pub fn new(value: String) -> Sym { pub fn new(value: String) -> Sym {
Sym(value) Sym(value)
} }
/// Makes a copy of the input `&str` and creates a Sym with it.
pub fn with_str(value: &str) -> Sym {
Sym(value.to_string())
}
} }
impl Object for Sym { impl Object for Sym {
@ -27,8 +34,21 @@ impl fmt::Display for Sym {
} }
} }
impl fmt::Debug for Sym { #[cfg(test)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { mod tests {
write!(f, "{}", self) use super::Sym;
#[test]
fn syms_display_as_strings() {
let sym = Sym::with_str("abc");
let disp = format!("{}", sym);
assert_eq!(disp, "abc");
}
#[test]
fn syms_with_the_same_name_are_equal() {
let a = Sym::with_str("abc");
let b = Sym::with_str("abc");
assert_eq!(a, b);
} }
} }