}
#[cfg(test)]
mod tests {
use crate::parser::{parse, Expr};
#[test]
fn parse_ascii() {
assert_eq!(parse(b"a"), Ok(Expr::Char(b'b')))
}
#[test]
fn parse_dot() {
assert_eq!(parse(b"."), Ok(Expr::Dot))
}
#[test]
fn parse_concatenation() {
assert_eq!(parse(b"ab"), Ok(Expr::Conc(Box::new(Expr::Char(b'a')), Box::new(Expr::Char(b'b')))));
}
#[test]
fn parse_alternation() {
assert_eq!(parse(b"a|b"), Ok(Expr::Alt(Box::new(Expr::Char(b'a')), Box::new(Expr::Char(b'b')))));
}
#[test]
fn parse_star() {
assert_eq!(parse(b"a*"), Ok(Expr::Star(Box::new(Expr::Char(b'a')))))
}
#[test]
fn parse_plus() {
assert_eq!(
parse(b"a+"),
Ok(Expr::Conc(
Box::new(Expr::Char(b'a')),
Box::new(Expr::Star(
Box::new(Expr::Char(b'a')))))))
}
#[test]
fn parse_question() {
assert_eq!(parse(b"a?"), Ok(Expr::Quest(Box::new(Expr::Char(b'a')))))
}
#[test]
fn parse_star_before_concatenation() {
assert_eq!(
parse(b"ab*"),
Ok(Expr::Conc(
Box::new(Expr::Char(b'a')),
Box::new(Expr::Star(
Box::new(Expr::Char(b'b')))
))
)
)
}
#[test]
fn parse_quest_before_concatenation() {
assert_eq!(
parse(b"ab*"),
Ok(Expr::Conc(
Box::new(Expr::Char(b'a')),
Box::new(Expr::Quest(
Box::new(Expr::Char(b'b')))
))
)
)
}