blob: e780e96378cc6157c7eafb40bcd4bb1749412311 (
plain)
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
|
use crate::syntax::ast::Regex;
pub mod compile;
pub mod instr;
pub mod vm;
pub fn is_match(re: Regex, s: &str) -> bool {
let instrs = compile::compile(&re);
vm::run(&instrs, s.as_bytes())
}
#[cfg(test)]
mod tests {
use super::*;
fn re(p: &str) -> Regex {
use crate::syntax::parse::parse;
parse(p).unwrap()
}
#[test]
fn matches() {
assert!(is_match(re("a"), "a"));
assert!(is_match(re("a*"), ""));
assert!(is_match(re("a*"), "a"));
assert!(is_match(re("a|b*"), "a"));
assert!(is_match(re("a|b*"), "bb"));
assert!(is_match(re("(a|b)*"), "abababaa"));
assert!(is_match(re("a*b*"), "abb"));
}
#[test]
fn does_not_match() {
assert!(!is_match(re("a"), "b"));
}
}
|