use crate::{
MatchType::{self, ToHave},
Matcher, TypedMatcher,
};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};
pub fn length(value: usize) -> Length {
Length(value)
}
pub fn len(value: usize) -> Length {
length(value)
}
pub struct Length(usize);
impl<T> Matcher<Vec<T>> for Length {
fn matches(&self, value: &Vec<T>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<T> TypedMatcher<Vec<T>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}
impl<T> Matcher<VecDeque<T>> for Length {
fn matches(&self, value: &VecDeque<T>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<T> TypedMatcher<VecDeque<T>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}
impl<T> Matcher<LinkedList<T>> for Length {
fn matches(&self, value: &LinkedList<T>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<T> TypedMatcher<LinkedList<T>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}
impl<K, V> Matcher<HashMap<K, V>> for Length {
fn matches(&self, value: &HashMap<K, V>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<K, V> TypedMatcher<HashMap<K, V>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}
impl<K, V> Matcher<BTreeMap<K, V>> for Length {
fn matches(&self, value: &BTreeMap<K, V>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<K, V> TypedMatcher<BTreeMap<K, V>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}
impl<K, V> Matcher<HashSet<K, V>> for Length {
fn matches(&self, value: &HashSet<K, V>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<K, V> TypedMatcher<HashSet<K, V>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}
impl<T> Matcher<BTreeSet<T>> for Length {
fn matches(&self, value: &BTreeSet<T>) -> bool {
self.0 == value.len()
}
fn description(&self) -> String {
format!("length equals to {}", self.0)
}
}
impl<T> TypedMatcher<BTreeSet<T>> for Length {
fn matcher_type(&self) -> MatchType {
ToHave
}
}