Files
@ 1e7b35645ea4
Branch filter:
Location: Regular-Expresso/tests/test_regexp.rs - annotation
1e7b35645ea4
4.5 KiB
application/rls-services+xml
renamed the package to regular-expresso
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 1e7b35645ea4 e93b264ec5cc e93b264ec5cc 9ddf4beb947b 08f1519c859e 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b ac6c57072747 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 08f1519c859e 08f1519c859e 08f1519c859e 08f1519c859e 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b ac6c57072747 ac6c57072747 ac6c57072747 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 08f1519c859e 9ddf4beb947b e93b264ec5cc 9ddf4beb947b 9ddf4beb947b e93b264ec5cc 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b ac6c57072747 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b 9ddf4beb947b e9496b21cf64 08f1519c859e e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 ac6c57072747 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 68c16b6d84f3 08f1519c859e 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 08f1519c859e 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 ac6c57072747 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 ac6c57072747 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 68c16b6d84f3 7e640b0cffa7 08f1519c859e 7e640b0cffa7 ac6c57072747 ac6c57072747 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 08f1519c859e 7e640b0cffa7 ac6c57072747 ac6c57072747 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 08f1519c859e 7e640b0cffa7 ac6c57072747 ac6c57072747 7e640b0cffa7 e9496b21cf64 e9496b21cf64 e9496b21cf64 08f1519c859e e9496b21cf64 ac6c57072747 ac6c57072747 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 08f1519c859e e9496b21cf64 ac6c57072747 ac6c57072747 e9496b21cf64 e9496b21cf64 e9496b21cf64 e9496b21cf64 08f1519c859e e9496b21cf64 ac6c57072747 ac6c57072747 e9496b21cf64 | use regular_expresso::{RegexpNFA, RegexpDFA, ParsingError};
#[test]
fn test_eval_basic_nfa() {
let r = RegexpNFA::new(&String::from("abc")).unwrap();
assert!(r.eval(String::from("abc")));
assert!(!r.eval(String::from("ab")));
assert!(!r.eval(String::from("abcd")));
}
#[test]
fn test_eval_basic_dfa() {
let r = RegexpDFA::new(&String::from("abc")).unwrap();
assert!(r.eval(String::from("abc")));
assert!(!r.eval(String::from("ab")));
assert!(!r.eval(String::from("abcd")));
}
#[test]
fn test_eval_empty_nfa() {
assert!(RegexpNFA::new(&String::from("a*")).unwrap().eval(String::from("")));
assert!(RegexpNFA::new(&String::from("")).unwrap().eval(String::from("")));
assert!(!RegexpNFA::new(&String::from("")).unwrap().eval(String::from("a")));
assert!(!RegexpNFA::new(&String::from("a")).unwrap().eval(String::from("")));
}
#[test]
fn test_eval_empty_dfa() {
assert!(RegexpDFA::new(&String::from("a*")).unwrap().eval(String::from("")));
assert!(RegexpDFA::new(&String::from("")).unwrap().eval(String::from("")));
assert!(!RegexpDFA::new(&String::from("")).unwrap().eval(String::from("a")));
}
#[test]
fn test_eval_asterisk_nfa() {
let r = RegexpNFA::new(&String::from("a*b*")).unwrap();
assert!(r.eval(String::from("a")));
assert!(r.eval(String::from("ab")));
assert!(r.eval(String::from("aabb")));
assert!(!r.eval(String::from("abab")));
}
#[test]
fn test_eval_asterisk_dfa() {
let r = RegexpDFA::new(&String::from("a*b*")).unwrap();
assert!(r.eval(String::from("a")));
assert!(r.eval(String::from("ab")));
assert!(r.eval(String::from("aabb")));
assert!(!r.eval(String::from("abab")));
}
#[test]
fn test_eval_alternative_nfa() {
let r = RegexpNFA::new(&String::from("a|b|c")).unwrap();
assert!(r.eval(String::from("a")));
assert!(r.eval(String::from("b")));
assert!(r.eval(String::from("c")));
assert!(!r.eval(String::from("")));
assert!(!r.eval(String::from("ab")));
}
#[test]
fn test_eval_alternative_dfa() {
let r = RegexpDFA::new(&String::from("a|b|c")).unwrap();
assert!(r.eval(String::from("a")));
assert!(r.eval(String::from("b")));
assert!(r.eval(String::from("c")));
assert!(!r.eval(String::from("")));
assert!(!r.eval(String::from("ab")));
}
#[test]
fn test_eval_lambda_nfa() {
let r = RegexpNFA::new(&String::from("a_")).unwrap();
assert!(r.eval(String::from("a")));
assert!(!r.eval(String::from("")));
assert!(!r.eval(String::from("ab")));
let r = RegexpNFA::new(&String::from("a|_")).unwrap();
assert!(r.eval(String::from("a")));
assert!(r.eval(String::from("")));
assert!(!r.eval(String::from("b")));
}
#[test]
fn test_eval_lambda_dfa() {
let r = RegexpDFA::new(&String::from("a_")).unwrap();
assert!(r.eval(String::from("a")));
assert!(!r.eval(String::from("")));
assert!(!r.eval(String::from("ab")));
let r = RegexpDFA::new(&String::from("a|_")).unwrap();
assert!(r.eval(String::from("a")));
assert!(r.eval(String::from("")));
assert!(!r.eval(String::from("b")));
}
#[test]
fn test_invalid_asterisk() {
let x = RegexpNFA::new(&String::from("*"));
assert!(matches!(x, Err(ParsingError::Asterisk{s: _, pos: 0})));
let x = RegexpDFA::new(&String::from("*"));
assert!(matches!(x, Err(ParsingError::Asterisk{s: _, pos: 0})));
}
#[test]
fn test_invalid_closing_parenthesis() {
let x = RegexpNFA::new(&String::from("(a"));
assert!(matches!(x, Err(ParsingError::ClosingParenthesis{s: _, pos: 0})));
let x = RegexpDFA::new(&String::from("(a"));
assert!(matches!(x, Err(ParsingError::ClosingParenthesis{s: _, pos: 0})));
}
#[test]
fn test_invalid_opening_parenthesis() {
let x = RegexpNFA::new(&String::from("a)"));
assert!(matches!(x, Err(ParsingError::OpeningParenthesis{s: _, pos: 1})));
let x = RegexpDFA::new(&String::from("a)"));
assert!(matches!(x, Err(ParsingError::OpeningParenthesis{s: _, pos: 1})));
}
#[test]
fn test_invalid_empty_variant_start() {
let x = RegexpNFA::new(&String::from("a(|b)"));
assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant)));
let x = RegexpDFA::new(&String::from("a(|b)"));
assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant)));
}
#[test]
fn test_invalid_empty_variant_end() {
let x = RegexpNFA::new(&String::from("a|"));
assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant)));
let x = RegexpDFA::new(&String::from("a|"));
assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant)));
}
#[test]
fn test_invalid_empty_variant_middle() {
let x = RegexpNFA::new(&String::from("a||b"));
assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant)));
let x = RegexpDFA::new(&String::from("a||b"));
assert!(matches!(x, Err(ParsingError::EmptyAlternativeVariant)));
}
|