1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
use super::Spec; pub trait StrSpec { fn starts_with(self, expected: &str); fn ends_with(self, expected: &str); fn contains(self, expected: &str); } impl<'s> StrSpec for Spec<'s, &'s str> { fn starts_with(self, expected: &str) { let subject = self.subject; if !subject.starts_with(expected) { self.with_expected(format!("string starting with <{:?}>", expected)) .with_actual(format!("<{:?}>", subject)) .fail(); } } fn ends_with(self, expected: &str) { let subject = self.subject; if !subject.ends_with(expected) { self.with_expected(format!("string ending with <{:?}>", expected)) .with_actual(format!("<{:?}>", subject)) .fail(); } } fn contains(self, expected: &str) { let subject = self.subject; if !subject.contains(expected) { self.with_expected(format!("string containing <{:?}>", expected)) .with_actual(format!("<{:?}>", subject)) .fail(); } } }