From 3024efe65ec7d7c636aa159cdb4670d6839d915d Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 25 Aug 2018 08:18:32 -0700 Subject: [PATCH] [types] Add some unit tests for Sym --- types/src/sym.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/types/src/sym.rs b/types/src/sym.rs index eedeacd..96be432 100644 --- a/types/src/sym.rs +++ b/types/src/sym.rs @@ -7,12 +7,19 @@ use std::fmt; use object::Object; use super::*; +#[derive(Debug, PartialEq)] pub struct Sym(String); impl Sym { + /// Creates a Sym with the given String. pub fn new(value: String) -> Sym { 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 { @@ -27,8 +34,21 @@ impl fmt::Display for Sym { } } -impl fmt::Debug for Sym { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self) +#[cfg(test)] +mod tests { + 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); } }