[types] Add some unit tests for Sym
This commit is contained in:
parent
cd7ea8f543
commit
3024efe65e
1 changed files with 23 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue