use super::ParseResult;
use libprop_sat_solver::formula::{BinaryOperator, UnaryOperator};
use nom::bytes::complete::tag;
use nom::character::complete::char;
use nom::combinator::value;
pub fn negation_operator(input: &str) -> ParseResult<&str, UnaryOperator> {
value(UnaryOperator::Negation, char('-'))(input)
}
pub fn and_operator(input: &str) -> ParseResult<&str, BinaryOperator> {
value(BinaryOperator::And, char('^'))(input)
}
pub fn or_operator(input: &str) -> ParseResult<&str, BinaryOperator> {
value(BinaryOperator::Or, char('|'))(input)
}
pub fn implication_operator(input: &str) -> ParseResult<&str, BinaryOperator> {
value(BinaryOperator::Implication, tag("->"))(input)
}
pub fn biimplication_operator(input: &str) -> ParseResult<&str, BinaryOperator> {
value(BinaryOperator::Biimplication, tag("<->"))(input)
}
#[cfg(test)]
mod tests {
use super::*;
use assert2::check;
#[test]
fn test_negation() {
check!(("", UnaryOperator::Negation) == negation_operator("-").unwrap());
}
#[test]
fn test_and_operator() {
check!(("", BinaryOperator::And) == and_operator("^").unwrap());
}
#[test]
fn test_or_operator() {
check!(("", BinaryOperator::Or) == or_operator("|").unwrap());
}
#[test]
fn test_implication_operator() {
check!(("", BinaryOperator::Implication) == implication_operator("->").unwrap());
}
#[test]
fn test_biimplication_operator() {
check!(("", BinaryOperator::Biimplication) == biimplication_operator("<->").unwrap());
}
}