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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use reflection;
use std::fmt;
use Predicate;
use normalize_line_endings::normalized;
use std::iter::FromIterator;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NormalizedPredicate<P>
where
P: Predicate<str>,
{
pub(crate) p: P,
}
impl<P> reflection::PredicateReflection for NormalizedPredicate<P>
where
P: Predicate<str>,
{
fn children<'a>(&'a self) -> Box<Iterator<Item = reflection::Child<'a>> + 'a> {
let params = vec![reflection::Child::new("predicate", &self.p)];
Box::new(params.into_iter())
}
}
impl<P> Predicate<str> for NormalizedPredicate<P>
where
P: Predicate<str>,
{
fn eval(&self, variable: &str) -> bool {
self.p
.eval(&String::from_iter(normalized(variable.chars())))
}
fn find_case<'a>(&'a self, expected: bool, variable: &str) -> Option<reflection::Case<'a>> {
let variable = String::from_iter(normalized(variable.chars()));
self.p.find_case(expected, &variable)
}
}
impl<P> fmt::Display for NormalizedPredicate<P>
where
P: Predicate<str>,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.p)
}
}