use std::collections::BTreeMap;
use std::error::Error;
use std::fmt;
use std::result::Result as RResult;
use std::str::FromStr;
use condition;
use error;
use state;
#[derive(PartialEq, Eq, Debug)]
pub struct TestCond {
name: String,
}
impl From<&'static str> for TestCond {
fn from(s: &str) -> Self {
Self {name: s.to_owned()}
}
}
impl condition::Condition for TestCond {
type Issue = BTreeMap<&'static str, bool>;
fn satisfied_by(&self, issue: &Self::Issue) -> bool {
issue.get(self.name.as_str()).cloned().unwrap_or(false)
}
}
impl FromStr for TestCond {
type Err = TestCondParseError;
fn from_str(s: &str) -> RResult<Self, Self::Err> {
Ok(Self {name: s.to_owned()})
}
}
#[derive(Default)]
pub struct TestCondFactory {}
impl condition::ConditionFactory<TestCond> for TestCondFactory {
type Error = TestCondParseError;
fn make_condition(
&self,
name: &str,
neg: bool,
val_op: Option<(condition::MatchOp, &str)>
) -> RResult<TestCond, TestCondParseError> {
Ok(TestCond { name: name.to_owned() })
}
}
#[derive(Debug, Default)]
pub struct TestCondParseError {
inner: Option<error::Error>,
}
impl fmt::Display for TestCondParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> RResult<(), fmt::Error> {
self.inner
.as_ref()
.map(|e| e.fmt(f))
.unwrap_or(Ok(()))
}
}
impl Error for TestCondParseError {}
impl From<error::Error> for TestCondParseError {
fn from(e: error::Error) -> Self {
Self { inner: Some(e) }
}
}
pub type TestState = state::IssueState<TestCond>;