// Copyright (c) 2018 The predicates-rs Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use crate::reflection; use crate::Predicate; use std::fmt; use normalize_line_endings::normalized; #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// Predicate adapter that normalizes the newlines contained in the variable being tested. /// /// This is created by `pred.normalize()`. pub struct NormalizedPredicate

where P: Predicate, { pub(crate) p: P, } impl

reflection::PredicateReflection for NormalizedPredicate

where P: Predicate, { fn children<'a>(&'a self) -> Box> + 'a> { let params = vec![reflection::Child::new("predicate", &self.p)]; Box::new(params.into_iter()) } } impl

Predicate for NormalizedPredicate

where P: Predicate, { fn eval(&self, variable: &str) -> bool { let variable = normalized(variable.chars()).collect::(); self.p.eval(&variable) } fn find_case<'a>(&'a self, expected: bool, variable: &str) -> Option> { let variable = normalized(variable.chars()).collect::(); self.p.find_case(expected, &variable) } } impl

fmt::Display for NormalizedPredicate

where P: Predicate, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.p.fmt(f) } }