Files @ f62bf5223dbf
Branch filter:

Location: Regular-Expresso/tests/test_regexp.rs - annotation

f62bf5223dbf 4.5 KiB application/rls-services+xml Show Source Show as Raw Download as Raw
Laman
added examples to the README
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)));
}