#![allow(non_snake_case)]
use ferroni::oniguruma::*;
use ferroni::regcomp::onig_new;
use ferroni::regexec::onig_search;
use ferroni::regsyntax::OnigSyntaxOniguruma;
fn x2(pattern: &[u8], input: &[u8], from: i32, to: i32) {
let reg = onig_new(
pattern,
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap_or_else(|e| {
panic!(
"compile failed for {:?}: error {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
e
)
});
let (result, region) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert!(
result >= 0,
"x2: expected match for {:?} against {:?}, got {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
result
);
let region = region.unwrap();
assert_eq!(
region.beg[0],
from,
"x2: wrong start for {:?} against {:?}: expected {}, got {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
from,
region.beg[0]
);
assert_eq!(
region.end[0],
to,
"x2: wrong end for {:?} against {:?}: expected {}, got {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
to,
region.end[0]
);
}
fn x3(pattern: &[u8], input: &[u8], from: i32, to: i32, mem: usize) {
let reg = onig_new(
pattern,
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap_or_else(|e| {
panic!(
"compile failed for {:?}: error {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
e
)
});
let (result, region) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert!(
result >= 0,
"x3: expected match for {:?} against {:?}, got {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
result
);
let region = region.unwrap();
assert!(
mem < region.num_regs as usize,
"x3: group {} not captured for {:?} (num_regs={})",
mem,
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
region.num_regs
);
assert_eq!(
region.beg[mem],
from,
"x3: wrong start for group {} of {:?}: expected {}, got {}",
mem,
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
from,
region.beg[mem]
);
assert_eq!(
region.end[mem],
to,
"x3: wrong end for group {} of {:?}: expected {}, got {}",
mem,
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
to,
region.end[mem]
);
}
fn n(pattern: &[u8], input: &[u8]) {
let reg = onig_new(
pattern,
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap_or_else(|e| {
panic!(
"compile failed for {:?}: error {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
e
)
});
let (result, _) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(
result,
ONIG_MISMATCH,
"n: expected no match for {:?} against {:?}, got {}",
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
result
);
}
#[test]
fn empty_pattern_empty_string() {
x2(b"", b"", 0, 0);
}
#[test]
fn literal_a() {
x2(b"a", b"a", 0, 1);
}
#[test]
fn literal_aa() {
x2(b"aa", b"aa", 0, 2);
}
#[test]
fn literal_aaa() {
x2(b"aaa", b"aaa", 0, 3);
}
#[test]
fn literal_ab() {
x2(b"ab", b"ab", 0, 2);
}
#[test]
fn literal_b_in_ab() {
x2(b"b", b"ab", 1, 2);
}
#[test]
fn literal_bc_in_abc() {
x2(b"bc", b"abc", 1, 3);
}
#[test]
fn hex_escape_x61() {
x2(b"\\x61", b"a", 0, 1);
}
#[test]
fn octal_escape_017() {
x2(b"\\17", b"\x0f", 0, 1);
}
#[test]
fn hex_escape_x1f() {
x2(b"\\x1f", b"\x1f", 0, 1);
}
#[test]
fn anchor_caret_empty() {
x2(b"^", b"", 0, 0);
}
#[test]
fn anchor_dollar_empty() {
x2(b"$", b"", 0, 0);
}
#[test]
fn anchor_caret_dollar_empty() {
x2(b"^$", b"", 0, 0);
}
#[test]
fn anchor_begin_buf() {
x2(b"\\A", b"", 0, 0);
}
#[test]
fn anchor_end_buf() {
x2(b"\\z", b"", 0, 0);
}
#[test]
fn anchor_semi_end_buf() {
x2(b"\\Z", b"", 0, 0);
}
#[test]
fn anchor_begin_position() {
x2(b"\\G", b"", 0, 0);
}
#[test]
fn anchor_caret_a_newline() {
x2(b"^a", b"\na", 1, 2);
}
#[test]
fn dot_a() {
x2(b".", b"a", 0, 1);
}
#[test]
fn dot_no_newline() {
n(b".", b"\n");
}
#[test]
fn dot_dot() {
x2(b"..", b"ab", 0, 2);
}
#[test]
fn word_char() {
x2(b"\\w", b"e", 0, 1);
}
#[test]
fn not_word_char() {
n(b"\\W", b"e");
}
#[test]
fn space_char() {
x2(b"\\s", b" ", 0, 1);
}
#[test]
fn not_space_char() {
x2(b"\\S", b"b", 0, 1);
}
#[test]
fn digit_char() {
x2(b"\\d", b"4", 0, 1);
}
#[test]
fn not_digit_char() {
n(b"\\D", b"4");
}
#[test]
fn word_boundary_at_start() {
x2(b"\\b", b"z ", 0, 0);
}
#[test]
fn word_boundary_before_word() {
x2(b"\\b", b" z", 1, 1);
}
#[test]
fn word_boundary_in_middle() {
x2(b"\\b", b" z ", 2, 2);
}
#[test]
fn not_word_boundary() {
x2(b"\\B", b"zz ", 1, 1);
}
#[test]
fn not_word_boundary_after_space() {
x2(b"\\B", b"z ", 2, 2);
}
#[test]
fn not_word_boundary_before_word() {
x2(b"\\B", b" z", 0, 0);
}
#[test]
fn char_class_ab() {
x2(b"[ab]", b"b", 0, 1);
}
#[test]
fn char_class_no_match() {
n(b"[ab]", b"c");
}
#[test]
fn char_class_range() {
x2(b"[a-z]", b"t", 0, 1);
}
#[test]
fn char_class_negated() {
n(b"[^a]", b"a");
}
#[test]
fn char_class_negated_newline() {
x2(b"[^a]", b"\n", 0, 1);
}
#[test]
fn char_class_bracket() {
x2(b"[]]", b"]", 0, 1);
}
#[test]
fn char_class_caret_plus() {
x2(b"[\\^]+", b"0^^1", 1, 3);
}
#[test]
fn char_class_b_dash() {
x2(b"[b-]", b"b", 0, 1);
}
#[test]
fn char_class_dash() {
x2(b"[b-]", b"-", 0, 1);
}
#[test]
fn char_class_w_meta() {
x2(b"[\\w]", b"z", 0, 1);
}
#[test]
fn char_class_w_no_space() {
n(b"[\\w]", b" ");
}
#[test]
fn char_class_W_meta() {
x2(b"[\\W]", b"b$", 1, 2);
}
#[test]
fn char_class_d_meta() {
x2(b"[\\d]", b"5", 0, 1);
}
#[test]
fn char_class_d_no_letter() {
n(b"[\\d]", b"e");
}
#[test]
fn char_class_D_meta() {
x2(b"[\\D]", b"t", 0, 1);
}
#[test]
fn char_class_D_no_digit() {
n(b"[\\D]", b"3");
}
#[test]
fn char_class_s_meta() {
x2(b"[\\s]", b" ", 0, 1);
}
#[test]
fn char_class_s_no_letter() {
n(b"[\\s]", b"a");
}
#[test]
fn char_class_S_meta() {
x2(b"[\\S]", b"b", 0, 1);
}
#[test]
fn char_class_S_no_space() {
n(b"[\\S]", b" ");
}
#[test]
fn char_class_combined() {
x2(b"[\\w\\d]", b"2", 0, 1);
}
#[test]
fn char_class_combined_no_space() {
n(b"[\\w\\d]", b" ");
}
#[test]
fn question_empty() {
x2(b"a?", b"", 0, 0);
}
#[test]
fn question_no_match() {
x2(b"a?", b"b", 0, 0);
}
#[test]
fn question_match() {
x2(b"a?", b"a", 0, 1);
}
#[test]
fn star_empty() {
x2(b"a*", b"", 0, 0);
}
#[test]
fn star_one() {
x2(b"a*", b"a", 0, 1);
}
#[test]
fn star_three() {
x2(b"a*", b"aaa", 0, 3);
}
#[test]
fn star_prefix_no_match() {
x2(b"a*", b"baaaa", 0, 0);
}
#[test]
fn plus_empty() {
n(b"a+", b"");
}
#[test]
fn plus_one() {
x2(b"a+", b"a", 0, 1);
}
#[test]
fn plus_four() {
x2(b"a+", b"aaaa", 0, 4);
}
#[test]
fn plus_partial() {
x2(b"a+", b"aabbb", 0, 2);
}
#[test]
fn plus_search() {
x2(b"a+", b"baaaa", 1, 5);
}
#[test]
fn dot_question_empty() {
x2(b".?", b"", 0, 0);
}
#[test]
fn dot_question_char() {
x2(b".?", b"f", 0, 1);
}
#[test]
fn dot_question_newline() {
x2(b".?", b"\n", 0, 0);
}
#[test]
fn dot_star_empty() {
x2(b".*", b"", 0, 0);
}
#[test]
fn dot_star_string() {
x2(b".*", b"abcde", 0, 5);
}
#[test]
fn dot_plus_char() {
x2(b".+", b"z", 0, 1);
}
#[test]
fn dot_plus_with_newline() {
x2(b".+", b"zdswer\n", 0, 6);
}
#[test]
fn alt_a_or_b_match_a() {
x2(b"a|b", b"a", 0, 1);
}
#[test]
fn alt_a_or_b_match_b() {
x2(b"a|b", b"b", 0, 1);
}
#[test]
fn alt_empty_or_a() {
x2(b"|a", b"a", 0, 0);
}
#[test]
fn alt_ab_or_bc_match_ab() {
x2(b"ab|bc", b"ab", 0, 2);
}
#[test]
fn alt_ab_or_bc_match_bc() {
x2(b"ab|bc", b"bc", 0, 2);
}
#[test]
fn alt_in_group() {
x2(b"z(?:ab|bc)", b"zbc", 0, 3);
}
#[test]
fn capture_a() {
x3(b"(a)", b"a", 0, 1, 1);
}
#[test]
fn capture_ab() {
x3(b"(ab)", b"ab", 0, 2, 1);
}
#[test]
fn capture_nested_outer() {
x2(b"((ab))", b"ab", 0, 2);
}
#[test]
fn capture_nested_group1() {
x3(b"((ab))", b"ab", 0, 2, 1);
}
#[test]
fn capture_nested_group2() {
x3(b"((ab))", b"ab", 0, 2, 2);
}
#[test]
fn capture_two_groups_first() {
x3(b"(ab)(cd)", b"abcd", 0, 2, 1);
}
#[test]
fn capture_two_groups_second() {
x3(b"(ab)(cd)", b"abcd", 2, 4, 2);
}
#[test]
fn capture_empty_group() {
x3(b"()(a)bc(def)ghijk", b"abcdefghijk", 3, 6, 3);
}
#[test]
fn backref_repeat() {
x3(b"(a*)\\1", b"aaaaa", 0, 2, 1);
}
#[test]
fn backref_ab() {
x2(b"a(b*)\\1", b"abbbb", 0, 5);
}
#[test]
fn backref_empty_match() {
x2(b"a(b*)\\1", b"ab", 0, 1);
}
#[test]
fn backref_two_groups() {
x2(b"(a*)(b*)\\1\\2", b"aaabbaaabb", 0, 10);
}
#[test]
fn backref_group2() {
x2(b"(a*)(b*)\\2", b"aaabbbb", 0, 7);
}
#[test]
fn backref_multi_group() {
x2(b"(a)(b)(c)\\2\\1\\3", b"abcbac", 0, 6);
}
#[test]
fn backref_char_class() {
x2(b"([a-d])\\1", b"cc", 0, 2);
}
#[test]
fn lookahead_positive() {
x2(b"(?=z)z", b"z", 0, 1);
}
#[test]
fn lookahead_positive_no_match() {
n(b"(?=z).", b"a");
}
#[test]
fn lookahead_negative() {
x2(b"(?!z)a", b"a", 0, 1);
}
#[test]
fn lookahead_negative_no_match() {
n(b"(?!z)a", b"z");
}
#[test]
fn non_capturing_basic() {
x2(b"(?:ab)", b"ab", 0, 2);
}
#[test]
fn non_capturing_alt() {
x2(b"z(?:ab|bc)", b"zbc", 0, 3);
}
#[test]
fn group_question_empty() {
x2(b"(?:x?)?", b"", 0, 0);
}
#[test]
fn group_question_x() {
x2(b"(?:x?)?", b"x", 0, 1);
}
#[test]
fn group_star_empty() {
x2(b"(?:x?)*", b"", 0, 0);
}
#[test]
fn group_star_xx() {
x2(b"(?:x?)*", b"xx", 0, 2);
}
#[test]
fn group_plus_empty() {
x2(b"(?:x?)+", b"", 0, 0);
}
#[test]
fn group_plus_xx() {
x2(b"(?:x?)+", b"xx", 0, 2);
}
#[test]
fn lazy_question_empty() {
x2(b"(?:x?)??", b"", 0, 0);
}
#[test]
fn lazy_question_x() {
x2(b"(?:x?)??", b"x", 0, 0);
}
#[test]
fn lazy_question_xx() {
x2(b"(?:x?)??", b"xx", 0, 0);
}
#[test]
fn lazy_star_empty() {
x2(b"(?:x?)*?", b"", 0, 0);
}
#[test]
fn lazy_star_x() {
x2(b"(?:x?)*?", b"x", 0, 0);
}
#[test]
fn lazy_plus_empty() {
x2(b"(?:x?)+?", b"", 0, 0);
}
#[test]
fn lazy_plus_x() {
x2(b"(?:x?)+?", b"x", 0, 1);
}
#[test]
fn multi_line_search() {
x2(b".*abc", b"dddabdd\nddabc", 8, 13);
}
#[test]
fn multi_line_search_plus() {
x2(b".+abc", b"dddabdd\nddabcaa\naaaabc", 8, 13);
}
#[test]
fn comment_in_pattern() {
x2(b"a(?#....\\\\JJJJ)b", b"ab", 0, 2);
}
#[test]
fn interval_exact() {
x2(b"a{3}", b"aaa", 0, 3);
}
#[test]
fn interval_range() {
x2(b"a{2,4}", b"aaa", 0, 3);
}
#[test]
fn interval_lower_bound() {
n(b"a{3}", b"aa");
}
#[test]
fn utf8_single_char() {
x2("あ".as_bytes(), "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_no_match() {
n("い".as_bytes(), "あ".as_bytes());
}
#[test]
fn utf8_double() {
x2("うう".as_bytes(), "うう".as_bytes(), 0, 6);
}
#[test]
fn utf8_triple() {
x2("あいう".as_bytes(), "あいう".as_bytes(), 0, 9);
}
#[test]
fn utf8_dot() {
x2(b".", "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_dot_dot() {
x2(b"..", "かき".as_bytes(), 0, 6);
}
#[test]
fn utf8_word_char() {
x2(b"\\w", "お".as_bytes(), 0, 3);
}
#[test]
fn utf8_not_word() {
n(b"\\W", "あ".as_bytes());
}
#[test]
fn utf8_char_class() {
let pattern = "[たち]".as_bytes();
let input = "ち".as_bytes();
x2(pattern, input, 0, 3);
}
#[test]
fn utf8_char_class_no_match() {
let pattern = "[なに]".as_bytes();
let input = "ぬ".as_bytes();
n(pattern, input);
}
#[test]
fn utf8_star() {
let pattern = "量*".as_bytes();
x2(pattern, b"", 0, 0);
}
#[test]
fn utf8_star_three() {
let pattern = "子*".as_bytes();
let input = "子子子".as_bytes();
x2(pattern, input, 0, 9);
}
#[test]
fn utf8_plus() {
let pattern = "河+".as_bytes();
let input = "河".as_bytes();
x2(pattern, input, 0, 3);
}
#[test]
fn utf8_plus_four() {
let pattern = "時+".as_bytes();
let input = "時時時時".as_bytes();
x2(pattern, input, 0, 12);
}
#[test]
fn utf8_alt() {
let pat_a = "あ".as_bytes();
let pat_i = "い".as_bytes();
let pattern = [pat_a, b"|", pat_i].concat();
x2(&pattern, pat_a, 0, 3);
x2(&pattern, pat_i, 0, 3);
}
#[test]
fn utf8_capture() {
let pattern = "(火)".as_bytes();
let input = "火".as_bytes();
x3(pattern, input, 0, 3, 1);
}
#[test]
fn utf8_capture_pair() {
let pattern = "(火水)".as_bytes();
let input = "火水".as_bytes();
x3(pattern, input, 0, 6, 1);
}
#[test]
fn utf8_anchor_begin() {
let pattern = "^あ".as_bytes();
let input = "あ".as_bytes();
x2(pattern, input, 0, 3);
}
#[test]
fn utf8_anchor_end() {
let _pattern = "む$".as_bytes();
let input = "む".as_bytes();
x2(b"^", input, 0, 0);
}
#[test]
fn utf8_question() {
let pattern = "あ?".as_bytes();
x2(pattern, b"", 0, 0);
x2(pattern, "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_lookahead() {
let pattern_bytes = [b"(?=", "せ".as_bytes(), b")", "せ".as_bytes()].concat();
let input = "せ".as_bytes();
x2(&pattern_bytes, input, 0, 3);
}
#[test]
fn utf8_neg_lookahead() {
let pattern_bytes = [b"(?!", "う".as_bytes(), b")", "か".as_bytes()].concat();
let input = "か".as_bytes();
x2(&pattern_bytes, input, 0, 3);
}
#[test]
fn utf8_neg_lookahead_no_match() {
let pattern_bytes = [b"(?!", "と".as_bytes(), b")", "あ".as_bytes()].concat();
let input = "と".as_bytes();
n(&pattern_bytes, input);
}
#[test]
fn posix_upper() {
x2(b"[[:upper:]]", b"B", 0, 1);
}
#[test]
fn posix_xdigit_plus() {
x2(b"[*[:xdigit:]+]", b"+", 0, 1);
}
#[test]
fn posix_xdigit_search1() {
x2(b"[*[:xdigit:]+]", b"GHIKK-9+*", 6, 7);
}
#[test]
fn posix_xdigit_search2() {
x2(b"[*[:xdigit:]+]", b"-@^+", 3, 4);
}
#[test]
fn posix_not_a_bracket() {
n(b"[[:upper]]", b"A");
}
#[test]
fn posix_not_a_bracket_colon() {
x2(b"[[:upper]]", b":", 0, 1);
}
#[test]
fn posix_upper_no_lower() {
n(b"[[:upper:]]", b"a");
}
#[test]
fn posix_neg_upper() {
x2(b"[[:^upper:]]", b"a", 0, 1);
}
#[test]
fn posix_lower_no_upper() {
n(b"[[:lower:]]", b"A");
}
#[test]
fn posix_neg_lower() {
x2(b"[[:^lower:]]", b"A", 0, 1);
}
#[test]
fn cc_negated_bracket() {
n(b"[^]]", b"]");
}
#[test]
fn cc_octal_range() {
x2(b"[\\044-\\047]", b"\x26", 0, 1);
}
#[test]
fn cc_hex_range_5a_5c() {
x2(b"[\\x5a-\\x5c]", b"\x5b", 0, 1);
}
#[test]
fn cc_hex_range_6a_6d() {
x2(b"[\\x6A-\\x6D]", b"\x6c", 0, 1);
}
#[test]
fn cc_hex_range_6a_6d_no_match() {
n(b"[\\x6A-\\x6D]", b"\x6E");
}
#[test]
fn cc_complex_no_match() {
n(
b"^[0-9A-F]+ 0+ UNDEF ",
b"75F 00000000 SECT14A notype () External | _rb_apply",
);
}
#[test]
fn cc_escaped_open_bracket() {
x2(b"[\\[]", b"[", 0, 1);
}
#[test]
fn cc_escaped_close_bracket() {
x2(b"[\\]]", b"]", 0, 1);
}
#[test]
fn cc_ampersand() {
x2(b"[&]", b"&", 0, 1);
}
#[test]
fn cc_nested_ab() {
x2(b"[[ab]]", b"b", 0, 1);
}
#[test]
fn cc_nested_ab_c() {
x2(b"[[ab]c]", b"c", 0, 1);
}
#[test]
fn cc_nested_neg() {
n(b"[[^a]]", b"a");
}
#[test]
fn cc_neg_nested() {
n(b"[^[a]]", b"a");
}
#[test]
fn cc_intersect_ab_bc() {
x2(b"[[ab]&&bc]", b"b", 0, 1);
}
#[test]
fn cc_intersect_ab_bc_no_a() {
n(b"[[ab]&&bc]", b"a");
}
#[test]
fn cc_intersect_ab_bc_no_c() {
n(b"[[ab]&&bc]", b"c");
}
#[test]
fn cc_intersect_range() {
x2(b"[a-z&&b-y&&c-x]", b"w", 0, 1);
}
#[test]
fn cc_neg_intersect_range() {
n(b"[^a-z&&b-y&&c-x]", b"w");
}
#[test]
fn cc_intersect_neg_and_range() {
x2(b"[[^a&&a]&&a-z]", b"b", 0, 1);
}
#[test]
fn cc_intersect_neg_and_range_no_a() {
n(b"[[^a&&a]&&a-z]", b"a");
}
#[test]
fn cc_intersect_complex1() {
x2(b"[[^a-z&&bcdef]&&[^c-g]]", b"h", 0, 1);
}
#[test]
fn cc_intersect_complex1_no_c() {
n(b"[[^a-z&&bcdef]&&[^c-g]]", b"c");
}
#[test]
fn cc_intersect_complex2_c() {
x2(b"[^[^abc]&&[^cde]]", b"c", 0, 1);
}
#[test]
fn cc_intersect_complex2_e() {
x2(b"[^[^abc]&&[^cde]]", b"e", 0, 1);
}
#[test]
fn cc_intersect_complex2_no_f() {
n(b"[^[^abc]&&[^cde]]", b"f");
}
#[test]
fn cc_intersect_dash() {
x2(b"[a-&&-a]", b"-", 0, 1);
}
#[test]
fn cc_intersect_dash_no_amp() {
n(b"[a\\-&&\\-a]", b"&");
}
#[test]
fn combined_wabc_no_match() {
n(b"\\wabc", b" abc");
}
#[test]
fn combined_a_Wbc() {
x2(b"a\\Wbc", b"a bc", 0, 4);
}
#[test]
fn combined_a_dot_b_dot_c() {
x2(b"a.b.c", b"aabbc", 0, 5);
}
#[test]
fn combined_dot_w_b_W_dot_c() {
x2(b".\\wb\\W..c", b"abb bcc", 0, 7);
}
#[test]
fn combined_s_w_zzz() {
x2(b"\\s\\wzzz", b" zzzz", 0, 5);
}
#[test]
fn combined_aa_dot_b() {
x2(b"aa.b", b"aabb", 0, 4);
}
#[test]
fn combined_dot_a_no_match() {
n(b".a", b"ab");
}
#[test]
fn combined_dot_a_match() {
x2(b".a", b"aa", 0, 2);
}
#[test]
fn combined_caret_a() {
x2(b"^a", b"a", 0, 1);
}
#[test]
fn combined_caret_a_dollar() {
x2(b"^a$", b"a", 0, 1);
}
#[test]
fn combined_caret_w_dollar() {
x2(b"^\\w$", b"a", 0, 1);
}
#[test]
fn combined_caret_w_dollar_no_match() {
n(b"^\\w$", b" ");
}
#[test]
fn combined_caret_wab_dollar() {
x2(b"^\\wab$", b"zab", 0, 3);
}
#[test]
fn combined_caret_wabcdef_dollar() {
x2(b"^\\wabcdef$", b"zabcdef", 0, 7);
}
#[test]
fn combined_caret_w_dots_def_dollar() {
x2(b"^\\w...def$", b"zabcdef", 0, 7);
}
#[test]
fn combined_ww_s_W_aaa_d() {
x2(b"\\w\\w\\s\\Waaa\\d", b"aa aaa4", 0, 8);
}
#[test]
fn combined_A_Z() {
x2(b"\\A\\Z", b"", 0, 0);
}
#[test]
fn combined_A_xyz() {
x2(b"\\Axyz", b"xyz", 0, 3);
}
#[test]
fn combined_xyz_Z() {
x2(b"xyz\\Z", b"xyz", 0, 3);
}
#[test]
fn combined_xyz_z() {
x2(b"xyz\\z", b"xyz", 0, 3);
}
#[test]
fn combined_a_Z() {
x2(b"a\\Z", b"a", 0, 1);
}
#[test]
fn combined_G_az() {
x2(b"\\Gaz", b"az", 0, 2);
}
#[test]
fn combined_G_z_no_match() {
n(b"\\Gz", b"bza");
}
#[test]
fn combined_az_G_no_match() {
n(b"az\\G", b"az");
}
#[test]
fn combined_az_A_no_match() {
n(b"az\\A", b"az");
}
#[test]
fn combined_a_A_z_no_match() {
n(b"a\\Az", b"az");
}
#[test]
fn combined_escaped_caret_dollar() {
x2(b"\\^\\$", b"^$", 0, 2);
}
#[test]
fn combined_caret_opt_y() {
x2(b"^x?y", b"xy", 0, 2);
}
#[test]
fn combined_caret_group_opt_y() {
x2(b"^(x?y)", b"xy", 0, 2);
}
#[test]
fn combined_w_underscore() {
x2(b"\\w", b"_", 0, 1);
}
#[test]
fn combined_W_underscore_no_match() {
n(b"\\W", b"_");
}
#[test]
fn backref_dotstar_1() {
x2(b"(.*)a\\1f", b"babfbac", 0, 4);
}
#[test]
fn backref_dotstar_2() {
x2(b"(.*)a\\1f", b"bacbabf", 3, 7);
}
#[test]
fn backref_dotstar_nested() {
x2(b"((.*)a\\2f)", b"bacbabf", 3, 7);
}
#[test]
fn backref_dotstar_multiline() {
x2(b"(.*)a\\1f", b"baczzzzzz\nbazz\nzzzzbabf", 19, 23);
}
#[test]
fn group_xstar_opt_empty() {
x2(b"(?:x*)?", b"", 0, 0);
}
#[test]
fn group_xstar_opt_x() {
x2(b"(?:x*)?", b"x", 0, 1);
}
#[test]
fn group_xstar_opt_xx() {
x2(b"(?:x*)?", b"xx", 0, 2);
}
#[test]
fn group_xstar_star_empty() {
x2(b"(?:x*)*", b"", 0, 0);
}
#[test]
fn group_xstar_star_x() {
x2(b"(?:x*)*", b"x", 0, 1);
}
#[test]
fn group_xstar_star_xx() {
x2(b"(?:x*)*", b"xx", 0, 2);
}
#[test]
fn group_xstar_plus_empty() {
x2(b"(?:x*)+", b"", 0, 0);
}
#[test]
fn group_xstar_plus_x() {
x2(b"(?:x*)+", b"x", 0, 1);
}
#[test]
fn group_xstar_plus_xx() {
x2(b"(?:x*)+", b"xx", 0, 2);
}
#[test]
fn group_xstar_lazyq_empty() {
x2(b"(?:x*)??", b"", 0, 0);
}
#[test]
fn group_xstar_lazyq_x() {
x2(b"(?:x*)??", b"x", 0, 0);
}
#[test]
fn group_xstar_lazyq_xx() {
x2(b"(?:x*)??", b"xx", 0, 0);
}
#[test]
fn group_xstar_lazystar_empty() {
x2(b"(?:x*)*?", b"", 0, 0);
}
#[test]
fn group_xstar_lazystar_x() {
x2(b"(?:x*)*?", b"x", 0, 0);
}
#[test]
fn group_xstar_lazystar_xx() {
x2(b"(?:x*)*?", b"xx", 0, 0);
}
#[test]
fn group_xstar_lazyplus_empty() {
x2(b"(?:x*)+?", b"", 0, 0);
}
#[test]
fn group_xstar_lazyplus_x() {
x2(b"(?:x*)+?", b"x", 0, 1);
}
#[test]
fn group_xstar_lazyplus_xx() {
x2(b"(?:x*)+?", b"xx", 0, 2);
}
#[test]
fn group_xplus_opt_empty() {
x2(b"(?:x+)?", b"", 0, 0);
}
#[test]
fn group_xplus_opt_x() {
x2(b"(?:x+)?", b"x", 0, 1);
}
#[test]
fn group_xplus_opt_xx() {
x2(b"(?:x+)?", b"xx", 0, 2);
}
#[test]
fn group_xplus_star_empty() {
x2(b"(?:x+)*", b"", 0, 0);
}
#[test]
fn group_xplus_star_x() {
x2(b"(?:x+)*", b"x", 0, 1);
}
#[test]
fn group_xplus_star_xx() {
x2(b"(?:x+)*", b"xx", 0, 2);
}
#[test]
fn group_xplus_plus_no_match() {
n(b"(?:x+)+", b"");
}
#[test]
fn group_xplus_plus_x() {
x2(b"(?:x+)+", b"x", 0, 1);
}
#[test]
fn group_xplus_plus_xx() {
x2(b"(?:x+)+", b"xx", 0, 2);
}
#[test]
fn group_xplus_lazyq_empty() {
x2(b"(?:x+)??", b"", 0, 0);
}
#[test]
fn group_xplus_lazyq_x() {
x2(b"(?:x+)??", b"x", 0, 0);
}
#[test]
fn group_xplus_lazyq_xx() {
x2(b"(?:x+)??", b"xx", 0, 0);
}
#[test]
fn group_xplus_lazystar_empty() {
x2(b"(?:x+)*?", b"", 0, 0);
}
#[test]
fn group_xplus_lazystar_x() {
x2(b"(?:x+)*?", b"x", 0, 0);
}
#[test]
fn group_xplus_lazystar_xx() {
x2(b"(?:x+)*?", b"xx", 0, 0);
}
#[test]
fn group_xplus_lazyplus_no_match() {
n(b"(?:x+)+?", b"");
}
#[test]
fn group_xplus_lazyplus_x() {
x2(b"(?:x+)+?", b"x", 0, 1);
}
#[test]
fn group_xplus_lazyplus_xx() {
x2(b"(?:x+)+?", b"xx", 0, 2);
}
#[test]
fn group_xlq_opt_empty() {
x2(b"(?:x??)?", b"", 0, 0);
}
#[test]
fn group_xlq_opt_x() {
x2(b"(?:x??)?", b"x", 0, 0);
}
#[test]
fn group_xlq_opt_xx() {
x2(b"(?:x??)?", b"xx", 0, 0);
}
#[test]
fn group_xlq_star_empty() {
x2(b"(?:x??)*", b"", 0, 0);
}
#[test]
fn group_xlq_star_x() {
x2(b"(?:x??)*", b"x", 0, 0);
}
#[test]
fn group_xlq_star_xx() {
x2(b"(?:x??)*", b"xx", 0, 0);
}
#[test]
fn group_xlq_plus_empty() {
x2(b"(?:x??)+", b"", 0, 0);
}
#[test]
fn group_xlq_plus_x() {
x2(b"(?:x??)+", b"x", 0, 0);
}
#[test]
fn group_xlq_plus_xx() {
x2(b"(?:x??)+", b"xx", 0, 0);
}
#[test]
fn group_xlq_lazyq_empty() {
x2(b"(?:x??)??", b"", 0, 0);
}
#[test]
fn group_xlq_lazyq_x() {
x2(b"(?:x??)??", b"x", 0, 0);
}
#[test]
fn group_xlq_lazyq_xx() {
x2(b"(?:x??)??", b"xx", 0, 0);
}
#[test]
fn group_xlq_lazystar_empty() {
x2(b"(?:x??)*?", b"", 0, 0);
}
#[test]
fn group_xlq_lazystar_x() {
x2(b"(?:x??)*?", b"x", 0, 0);
}
#[test]
fn group_xlq_lazystar_xx() {
x2(b"(?:x??)*?", b"xx", 0, 0);
}
#[test]
fn group_xlq_lazyplus_empty() {
x2(b"(?:x??)+?", b"", 0, 0);
}
#[test]
fn group_xlq_lazyplus_x() {
x2(b"(?:x??)+?", b"x", 0, 0);
}
#[test]
fn group_xlq_lazyplus_xx() {
x2(b"(?:x??)+?", b"xx", 0, 0);
}
#[test]
fn group_xls_opt_empty() {
x2(b"(?:x*?)?", b"", 0, 0);
}
#[test]
fn group_xls_opt_x() {
x2(b"(?:x*?)?", b"x", 0, 0);
}
#[test]
fn group_xls_opt_xx() {
x2(b"(?:x*?)?", b"xx", 0, 0);
}
#[test]
fn group_xls_star_empty() {
x2(b"(?:x*?)*", b"", 0, 0);
}
#[test]
fn group_xls_star_x() {
x2(b"(?:x*?)*", b"x", 0, 0);
}
#[test]
fn group_xls_star_xx() {
x2(b"(?:x*?)*", b"xx", 0, 0);
}
#[test]
fn group_xls_plus_empty() {
x2(b"(?:x*?)+", b"", 0, 0);
}
#[test]
fn group_xls_plus_x() {
x2(b"(?:x*?)+", b"x", 0, 0);
}
#[test]
fn group_xls_plus_xx() {
x2(b"(?:x*?)+", b"xx", 0, 0);
}
#[test]
fn group_xls_lazyq_empty() {
x2(b"(?:x*?)??", b"", 0, 0);
}
#[test]
fn group_xls_lazyq_x() {
x2(b"(?:x*?)??", b"x", 0, 0);
}
#[test]
fn group_xls_lazyq_xx() {
x2(b"(?:x*?)??", b"xx", 0, 0);
}
#[test]
fn group_xls_lazystar_empty() {
x2(b"(?:x*?)*?", b"", 0, 0);
}
#[test]
fn group_xls_lazystar_x() {
x2(b"(?:x*?)*?", b"x", 0, 0);
}
#[test]
fn group_xls_lazystar_xx() {
x2(b"(?:x*?)*?", b"xx", 0, 0);
}
#[test]
fn group_xls_lazyplus_empty() {
x2(b"(?:x*?)+?", b"", 0, 0);
}
#[test]
fn group_xls_lazyplus_x() {
x2(b"(?:x*?)+?", b"x", 0, 0);
}
#[test]
fn group_xls_lazyplus_xx() {
x2(b"(?:x*?)+?", b"xx", 0, 0);
}
#[test]
fn group_xlp_opt_empty() {
x2(b"(?:x+?)?", b"", 0, 0);
}
#[test]
fn group_xlp_opt_x() {
x2(b"(?:x+?)?", b"x", 0, 1);
}
#[test]
fn group_xlp_opt_xx() {
x2(b"(?:x+?)?", b"xx", 0, 1);
}
#[test]
fn group_xlp_star_empty() {
x2(b"(?:x+?)*", b"", 0, 0);
}
#[test]
fn group_xlp_star_x() {
x2(b"(?:x+?)*", b"x", 0, 1);
}
#[test]
fn group_xlp_star_xx() {
x2(b"(?:x+?)*", b"xx", 0, 2);
}
#[test]
fn group_xlp_plus_no_match() {
n(b"(?:x+?)+", b"");
}
#[test]
fn group_xlp_plus_x() {
x2(b"(?:x+?)+", b"x", 0, 1);
}
#[test]
fn group_xlp_plus_xx() {
x2(b"(?:x+?)+", b"xx", 0, 2);
}
#[test]
fn group_xlp_lazyq_empty() {
x2(b"(?:x+?)??", b"", 0, 0);
}
#[test]
fn group_xlp_lazyq_x() {
x2(b"(?:x+?)??", b"x", 0, 0);
}
#[test]
fn group_xlp_lazyq_xx() {
x2(b"(?:x+?)??", b"xx", 0, 0);
}
#[test]
fn group_xlp_lazystar_empty() {
x2(b"(?:x+?)*?", b"", 0, 0);
}
#[test]
fn group_xlp_lazystar_x() {
x2(b"(?:x+?)*?", b"x", 0, 0);
}
#[test]
fn group_xlp_lazystar_xx() {
x2(b"(?:x+?)*?", b"xx", 0, 0);
}
#[test]
fn group_xlp_lazyplus_no_match() {
n(b"(?:x+?)+?", b"");
}
#[test]
fn group_xlp_lazyplus_x() {
x2(b"(?:x+?)+?", b"x", 0, 1);
}
#[test]
fn group_xlp_lazyplus_xx() {
x2(b"(?:x+?)+?", b"xx", 0, 1);
}
#[test]
fn alt_capture_empty_or_a() {
x2(b"(|a)", b"a", 0, 0);
}
#[test]
fn alt_group_abc_or_az() {
x2(b"a(?:ab|bc)c", b"aabc", 0, 4);
}
#[test]
fn alt_ab_or_ac_az() {
x2(b"ab|(?:ac|az)", b"az", 0, 2);
}
#[test]
fn alt_three_way() {
x2(b"a|b|c", b"dc", 1, 2);
}
#[test]
fn alt_many() {
x2(b"a|b|cd|efg|h|ijk|lmn|o|pq|rstuvwx|yz", b"pqr", 0, 2);
}
#[test]
fn alt_many_no_match() {
n(b"a|b|cd|efg|h|ijk|lmn|o|pq|rstuvwx|yz", b"mn");
}
#[test]
fn alt_a_or_caret_z_match_a() {
x2(b"a|^z", b"ba", 1, 2);
}
#[test]
fn alt_a_or_caret_z_match_z() {
x2(b"a|^z", b"za", 0, 1);
}
#[test]
fn alt_a_or_G_z_1() {
x2(b"a|\\Gz", b"bza", 2, 3);
}
#[test]
fn alt_a_or_G_z_2() {
x2(b"a|\\Gz", b"za", 0, 1);
}
#[test]
fn alt_a_or_A_z_1() {
x2(b"a|\\Az", b"bza", 2, 3);
}
#[test]
fn alt_a_or_A_z_2() {
x2(b"a|\\Az", b"za", 0, 1);
}
#[test]
fn alt_a_or_b_Z_1() {
x2(b"a|b\\Z", b"ba", 1, 2);
}
#[test]
fn alt_a_or_b_Z_2() {
x2(b"a|b\\Z", b"b", 0, 1);
}
#[test]
fn alt_a_or_b_z_1() {
x2(b"a|b\\z", b"ba", 1, 2);
}
#[test]
fn alt_a_or_b_z_2() {
x2(b"a|b\\z", b"b", 0, 1);
}
#[test]
fn alt_w_or_s() {
x2(b"\\w|\\s", b" ", 0, 1);
}
#[test]
fn alt_w_or_w_no_match() {
n(b"\\w|\\w", b" ");
}
#[test]
fn alt_w_or_percent() {
x2(b"\\w|%", b"%", 0, 1);
}
#[test]
fn alt_w_or_cc() {
x2(b"\\w|[&$]", b"&", 0, 1);
}
#[test]
fn alt_range_or_neg_range() {
x2(b"[b-d]|[^e-z]", b"a", 0, 1);
}
#[test]
fn alt_group_or_bz_1() {
x2(b"(?:a|[c-f])|bz", b"dz", 0, 1);
}
#[test]
fn alt_group_or_bz_2() {
x2(b"(?:a|[c-f])|bz", b"bz", 0, 2);
}
#[test]
fn alt_abc_or_lookahead_zzf() {
x2(b"abc|(?=zz)..f", b"zzf", 0, 3);
}
#[test]
fn alt_abc_or_neg_lookahead_abf() {
x2(b"abc|(?!zz)..f", b"abf", 0, 3);
}
#[test]
fn alt_lookahead_combo() {
x2(b"(?=za)..a|(?=zz)..a", b"zza", 0, 3);
}
#[test]
fn alt_opt_a_or_b_match_a() {
x2(b"a?|b", b"a", 0, 1);
}
#[test]
fn alt_opt_a_or_b_match_b() {
x2(b"a?|b", b"b", 0, 0);
}
#[test]
fn alt_opt_a_or_b_empty() {
x2(b"a?|b", b"", 0, 0);
}
#[test]
fn alt_star_a_or_b() {
x2(b"a*|b", b"aa", 0, 2);
}
#[test]
fn alt_star_a_or_star_b_1() {
x2(b"a*|b*", b"ba", 0, 0);
}
#[test]
fn alt_star_a_or_star_b_2() {
x2(b"a*|b*", b"ab", 0, 1);
}
#[test]
fn alt_plus_a_or_star_b_1() {
x2(b"a+|b*", b"", 0, 0);
}
#[test]
fn alt_plus_a_or_star_b_2() {
x2(b"a+|b*", b"bbb", 0, 3);
}
#[test]
fn alt_plus_a_or_star_b_3() {
x2(b"a+|b*", b"abbb", 0, 1);
}
#[test]
fn alt_plus_a_or_plus_b_no_match() {
n(b"a+|b+", b"");
}
#[test]
fn alt_capture_opt() {
x2(b"(a|b)?", b"b", 0, 1);
}
#[test]
fn alt_capture_star() {
x2(b"(a|b)*", b"ba", 0, 2);
}
#[test]
fn alt_capture_plus() {
x2(b"(a|b)+", b"bab", 0, 3);
}
#[test]
fn alt_capture_words_1() {
x2(b"(ab|ca)+", b"caabbc", 0, 4);
}
#[test]
fn alt_capture_words_2() {
x2(b"(ab|ca)+", b"aabca", 1, 5);
}
#[test]
fn alt_capture_words_3() {
x2(b"(ab|ca)+", b"abzca", 0, 2);
}
#[test]
fn alt_capture_bab_1() {
x2(b"(a|bab)+", b"ababa", 0, 5);
}
#[test]
fn alt_capture_bab_2() {
x2(b"(a|bab)+", b"ba", 1, 2);
}
#[test]
fn alt_capture_bab_3() {
x2(b"(a|bab)+", b"baaaba", 1, 4);
}
#[test]
fn alt_noncap_pair() {
x2(b"(?:a|b)(?:a|b)", b"ab", 0, 2);
}
#[test]
fn alt_star_star_1() {
x2(b"(?:a*|b*)(?:a*|b*)", b"aaabbb", 0, 3);
}
#[test]
fn alt_star_plus() {
x2(b"(?:a*|b*)(?:a+|b+)", b"aaabbb", 0, 6);
}
#[test]
fn alt_plus_interval() {
x2(b"(?:a+|b+){2}", b"aaabbb", 0, 6);
}
#[test]
fn interval_h_0_inf() {
x2(b"h{0,}", b"hhhh", 0, 4);
}
#[test]
fn alt_plus_interval_1_2() {
x2(b"(?:a+|b+){1,2}", b"aaabbb", 0, 6);
}
#[test]
fn interval_ax2_star_no_match() {
n(b"ax{2}*a", b"0axxxa1");
}
#[test]
fn interval_dot_0_2_no_match() {
n(b"a.{0,2}a", b"0aXXXa0");
}
#[test]
fn interval_dot_0_2_lazy_no_match1() {
n(b"a.{0,2}?a", b"0aXXXa0");
}
#[test]
fn interval_dot_0_2_lazy_no_match2() {
n(b"a.{0,2}?a", b"0aXXXXa0");
}
#[test]
fn interval_a_2_lazy_dollar() {
x2(b"^a{2,}?a$", b"aaa", 0, 3);
}
#[test]
fn interval_az_2_lazy_dollar() {
x2(b"^[a-z]{2,}?$", b"aaa", 0, 3);
}
#[test]
fn alt_plus_or_A_star_cc() {
x2(b"(?:a+|\\Ab*)cc", b"cc", 0, 2);
}
#[test]
fn alt_plus_or_A_star_cc_no_match() {
n(b"(?:a+|\\Ab*)cc", b"abcc");
}
#[test]
fn alt_caret_plus_or_star_c_1() {
x2(b"(?:^a+|b+)*c", b"aabbbabc", 6, 8);
}
#[test]
fn alt_caret_plus_or_star_c_2() {
x2(b"(?:^a+|b+)*c", b"aabbbbc", 0, 7);
}
#[test]
fn cc_abc_opt() {
x2(b"[abc]?", b"abc", 0, 1);
}
#[test]
fn cc_abc_star() {
x2(b"[abc]*", b"abc", 0, 3);
}
#[test]
fn cc_neg_abc_star() {
x2(b"[^abc]*", b"abc", 0, 0);
}
#[test]
fn cc_neg_abc_plus() {
n(b"[^abc]+", b"abc");
}
#[test]
fn lazy_a_opt() {
x2(b"a??", b"aaa", 0, 0);
}
#[test]
fn lazy_ba_opt_b() {
x2(b"ba??b", b"bab", 0, 3);
}
#[test]
fn lazy_a_star() {
x2(b"a*?", b"aaa", 0, 0);
}
#[test]
fn lazy_ba_star() {
x2(b"ba*?", b"baa", 0, 1);
}
#[test]
fn lazy_ba_star_b() {
x2(b"ba*?b", b"baab", 0, 4);
}
#[test]
fn lazy_a_plus() {
x2(b"a+?", b"aaa", 0, 1);
}
#[test]
fn lazy_ba_plus() {
x2(b"ba+?", b"baa", 0, 2);
}
#[test]
fn lazy_ba_plus_b() {
x2(b"ba+?b", b"baab", 0, 4);
}
#[test]
fn lazy_group_a_opt_lazyq() {
x2(b"(?:a?)??", b"a", 0, 0);
}
#[test]
fn lazy_group_a_lazyq_opt() {
x2(b"(?:a??)?", b"a", 0, 0);
}
#[test]
fn lazy_group_a_opt_lazyplus() {
x2(b"(?:a?)+?", b"aaa", 0, 1);
}
#[test]
fn lazy_group_a_plus_lazyq() {
x2(b"(?:a+)??", b"aaa", 0, 0);
}
#[test]
fn lazy_group_a_plus_lazyq_b() {
x2(b"(?:a+)??b", b"aaab", 0, 4);
}
#[test]
fn interval_opt_2() {
x2(b"(?:ab)?{2}", b"", 0, 0);
}
#[test]
fn interval_opt_2_match() {
x2(b"(?:ab)?{2}", b"ababa", 0, 4);
}
#[test]
fn interval_star_0() {
x2(b"(?:ab)*{0}", b"ababa", 0, 0);
}
#[test]
fn interval_3_inf() {
x2(b"(?:ab){3,}", b"abababab", 0, 8);
}
#[test]
fn interval_3_inf_no_match() {
n(b"(?:ab){3,}", b"abab");
}
#[test]
fn interval_2_4() {
x2(b"(?:ab){2,4}", b"ababab", 0, 6);
}
#[test]
fn interval_2_4_max() {
x2(b"(?:ab){2,4}", b"ababababab", 0, 8);
}
#[test]
fn interval_2_4_lazy() {
x2(b"(?:ab){2,4}?", b"ababababab", 0, 4);
}
#[test]
fn interval_comma_literal() {
x2(b"(?:ab){,}", b"ab{,}", 0, 5);
}
#[test]
fn interval_plus_lazy_2() {
x2(b"(?:abc)+?{2}", b"abcabcabc", 0, 6);
}
#[test]
fn capture_d_plus_ncc() {
x2(b"(d+)([^abc]z)", b"dddz", 0, 4);
}
#[test]
fn capture_ncc_star_ncc() {
x2(b"([^abc]*)([^abc]z)", b"dddz", 0, 4);
}
#[test]
fn capture_w_plus_wz() {
x2(b"(\\w+)(\\wz)", b"dddz", 0, 4);
}
#[test]
fn capture_20_nested() {
x3(
b"((((((((((((((((((((ab))))))))))))))))))))",
b"ab",
0,
2,
20,
);
}
#[test]
fn capture_nested_4() {
x3(b"(()(a)bc(def)ghijk)", b"abcdefghijk", 3, 6, 4);
}
#[test]
fn capture_caret_a() {
x2(b"(^a)", b"a", 0, 1);
}
#[test]
fn capture_alt_1() {
x3(b"(a)|(a)", b"ba", 1, 2, 1);
}
#[test]
fn capture_alt_2() {
x3(b"(^a)|(a)", b"ba", 1, 2, 2);
}
#[test]
fn capture_a_opt() {
x3(b"(a?)", b"aaa", 0, 1, 1);
}
#[test]
fn capture_a_star() {
x3(b"(a*)", b"aaa", 0, 3, 1);
}
#[test]
fn capture_a_star_empty() {
x3(b"(a*)", b"", 0, 0, 1);
}
#[test]
fn capture_a_plus() {
x3(b"(a+)", b"aaaaaaa", 0, 7, 1);
}
#[test]
fn capture_alt_plus_star() {
x3(b"(a+|b*)", b"bbbaa", 0, 3, 1);
}
#[test]
fn capture_alt_plus_opt() {
x3(b"(a+|b?)", b"bbbaa", 0, 1, 1);
}
#[test]
fn capture_abc_opt() {
x3(b"(abc)?", b"abc", 0, 3, 1);
}
#[test]
fn capture_abc_star() {
x3(b"(abc)*", b"abc", 0, 3, 1);
}
#[test]
fn capture_abc_plus() {
x3(b"(abc)+", b"abc", 0, 3, 1);
}
#[test]
fn capture_alt_xyz_abc() {
x3(b"(xyz|abc)+", b"abc", 0, 3, 1);
}
#[test]
fn capture_alt_cc_abc() {
x3(b"([xyz][abc]|abc)+", b"abc", 0, 3, 1);
}
#[test]
fn capture_lookahead() {
x3(b"((?=az)a)", b"azb", 0, 1, 1);
}
#[test]
fn capture_abc_or_abd() {
x3(b"abc|(.abd)", b"zabd", 0, 4, 1);
}
#[test]
fn capture_noncap_or_cap() {
x2(b"(?:abc)|(ABC)", b"abc", 0, 3);
}
#[test]
fn capture_star_dot() {
x3(b"a*(.)", b"aaaaz", 4, 5, 1);
}
#[test]
fn capture_lazystar_dot() {
x3(b"a*?(.)", b"aaaaz", 0, 1, 1);
}
#[test]
fn capture_lazystar_c() {
x3(b"a*?(c)", b"aaaac", 4, 5, 1);
}
#[test]
fn capture_cc_star_dot() {
x3(b"[bcd]a*(.)", b"caaaaz", 5, 6, 1);
}
#[test]
fn capture_A_bb() {
x3(b"(\\Abb)cc", b"bbcc", 0, 2, 1);
}
#[test]
fn capture_A_bb_no_match() {
n(b"(\\Abb)cc", b"zbbcc");
}
#[test]
fn capture_caret_bb() {
x3(b"(^bb)cc", b"bbcc", 0, 2, 1);
}
#[test]
fn capture_caret_bb_no_match() {
n(b"(^bb)cc", b"zbbcc");
}
#[test]
fn capture_bb_dollar() {
x3(b"cc(bb$)", b"ccbb", 2, 4, 1);
}
#[test]
fn capture_bb_dollar_no_match() {
n(b"cc(bb$)", b"ccbbb");
}
#[test]
fn backref_self_no_match() {
n(b"(\\1)", b"");
}
#[test]
fn backref_forward_no_match() {
n(b"\\1(a)", b"aa");
}
#[test]
fn backref_nested_no_match() {
n(b"(a(b)\\1)\\2+", b"ababb");
}
#[test]
fn backref_or_z_pattern() {
x2(b"(?:(?:\\1|z)(a))+$", b"zaaa", 0, 4);
}
#[test]
fn backref_or_z_no_match() {
n(b"(?:(?:\\1|z)(a))+$", b"zaa");
}
#[test]
fn backref_lookahead() {
x2(b"(a)(?=\\1)", b"aa", 0, 1);
}
#[test]
fn backref_dollar_or() {
n(b"(a)$|\\1", b"az");
}
#[test]
fn backref_aa() {
x2(b"(a)\\1", b"aa", 0, 2);
}
#[test]
fn backref_ab_no_match() {
n(b"(a)\\1", b"ab");
}
#[test]
fn backref_opt_aa() {
x2(b"(a?)\\1", b"aa", 0, 2);
}
#[test]
fn backref_lazyopt() {
x2(b"(a??)\\1", b"aa", 0, 0);
}
#[test]
fn backref_7_nested() {
x2(b"(((((((a*)b))))))c\\7", b"aaabcaaa", 0, 8);
}
#[test]
fn backref_7_nested_capture() {
x3(b"(((((((a*)b))))))c\\7", b"aaabcaaa", 0, 3, 7);
}
#[test]
fn backref_wds() {
x2(b"(\\w\\d\\s)\\1", b"f5 f5 ", 0, 6);
}
#[test]
fn backref_wds_no_match() {
n(b"(\\w\\d\\s)\\1", b"f5 f5");
}
#[test]
fn backref_who_or_cc() {
x2(b"(who|[a-c]{3})\\1", b"whowho", 0, 6);
}
#[test]
fn backref_who_or_cc_prefix() {
x2(b"...(who|[a-c]{3})\\1", b"abcwhowho", 0, 9);
}
#[test]
fn backref_cbc() {
x2(b"(who|[a-c]{3})\\1", b"cbccbc", 0, 6);
}
#[test]
fn backref_caret_a() {
x2(b"(^a)\\1", b"aa", 0, 2);
}
#[test]
fn backref_caret_a_no_match() {
n(b"(^a)\\1", b"baa");
}
#[test]
fn backref_a_dollar_no_match() {
n(b"(a$)\\1", b"aa");
}
#[test]
fn backref_ab_Z_no_match() {
n(b"(ab\\Z)\\1", b"ab");
}
#[test]
fn backref_astar_Z() {
x2(b"(a*\\Z)\\1", b"a", 1, 1);
}
#[test]
fn backref_dot_astar_Z() {
x2(b".(a*\\Z)\\1", b"ba", 1, 2);
}
#[test]
fn backref_nested_abc() {
x3(b"(.(abc)\\2)", b"zabcabc", 0, 7, 1);
}
#[test]
fn backref_nested_digits() {
x3(b"(.(..\\d.)\\2)", b"z12341234", 0, 9, 1);
}
#[test]
fn empty_capture_star_backref() {
x2(b"()*\\1", b"", 0, 0);
}
#[test]
fn double_empty_capture_star_backref() {
x2(b"(?:()|())*\\1\\2", b"", 0, 0);
}
#[test]
fn alt_star_astar_bstar_c() {
x2(b"(?:a*|b*)*c", b"abadc", 4, 5);
}
#[test]
fn dotstar_2_opt_star() {
x2(b"(.{2,})?", b"abcde", 0, 5);
}
#[test]
fn alt_many_letters_opt() {
x2(b"((a|b|c|d|e|f|g|h|i|j|k|l|m|n)+)?", b"abcde", 0, 5);
}
#[test]
fn alt_many_letters_3_opt() {
x2(b"((a|b|c|d|e|f|g|h|i|j|k|l|m|n){3,})?", b"abcde", 0, 5);
}
#[test]
fn quoted_or_empty_backref() {
x2(b"^(\"|)(.*)\\1$", b"XX", 0, 2);
}
#[test]
fn neg_lookahead_tail() {
x2(b"(?!abc).*\\z", b"abcde", 1, 5);
}
#[test]
fn group_a_opt_plus() {
x2(b"(?:a?)+", b"aa", 0, 2);
}
#[test]
fn group_a_opt_lazystar2() {
x2(b"(?:a?)*?", b"a", 0, 0);
}
#[test]
fn group_astar_lazystar() {
x2(b"(?:a*)*?", b"a", 0, 0);
}
#[test]
fn group_aplus_lazy_star() {
x2(b"(?:a+?)*", b"a", 0, 1);
}
#[test]
fn cc_up_coverage() {
x2(b"[a]*\\W", b"aa@", 0, 3);
}
#[test]
fn cc_up_coverage_2() {
x2(b"[a]*[b]", b"aab", 0, 3);
}
#[test]
fn astar_W_no_match() {
n(b"a*\\W", b"aaa");
}
#[test]
fn interval_10_10_no_match() {
n(b"(a){10}{10}", b"aa");
}
#[test]
fn empty_capture_chain() {
x2(b"()(\\1)(\\2)", b"abc", 0, 0);
}
#[test]
fn group_question_star_x() {
x2(b"(?:x?)*", b"x", 0, 1);
}
#[test]
fn group_question_plus_x() {
x2(b"(?:x?)+", b"x", 0, 1);
}
#[test]
fn group_question_opt_xx() {
x2(b"(?:x?)?", b"xx", 0, 1);
}
#[test]
fn utf8_empty_pattern() {
x2(b"", "あ".as_bytes(), 0, 0);
}
#[test]
fn utf8_long_repeat() {
let pattern =
"こここここここここここここここここここここここここここここここここここ".as_bytes();
let input = "こここここここここここここここここここここここここここここここここここ".as_bytes();
x2(pattern, input, 0, 105);
}
#[test]
fn utf8_search_offset_single() {
x2("あ".as_bytes(), "いあ".as_bytes(), 3, 6);
}
#[test]
fn utf8_search_offset_double() {
x2("いう".as_bytes(), "あいう".as_bytes(), 3, 9);
}
#[test]
fn utf8_raw_bytes() {
x2(b"\\xca\\xb8", b"\xca\xb8", 0, 2);
}
#[test]
fn utf8_bracket_W() {
x2(b"[\\W]", ["う".as_bytes(), b"$"].concat().as_slice(), 3, 4);
}
#[test]
fn utf8_S_katakana() {
x2(b"\\S", "そ".as_bytes(), 0, 3);
}
#[test]
fn utf8_S_kanji() {
x2(b"\\S", "漢".as_bytes(), 0, 3);
}
#[test]
fn utf8_word_boundary_start() {
let input = ["気".as_bytes(), b" "].concat();
x2(b"\\b", &input, 0, 0);
}
#[test]
fn utf8_word_boundary_after_space() {
let input = [b" ", "ほ".as_bytes()].concat();
x2(b"\\b", &input, 1, 1);
}
#[test]
fn utf8_non_boundary_mid() {
let input = ["せそ".as_bytes(), b" "].concat();
x2(b"\\B", &input, 3, 3);
}
#[test]
fn utf8_non_boundary_after_char() {
let input = ["う".as_bytes(), b" "].concat();
x2(b"\\B", &input, 4, 4);
}
#[test]
fn utf8_non_boundary_start_space() {
let input = [b" ", "い".as_bytes()].concat();
x2(b"\\B", &input, 0, 0);
}
#[test]
fn utf8_range_u_o() {
let pattern = "[う-お]".as_bytes();
x2(pattern, "え".as_bytes(), 0, 3);
}
#[test]
fn utf8_neg_class() {
let pattern = "[^け]".as_bytes();
n(pattern, "け".as_bytes());
}
#[test]
fn utf8_bracket_w() {
let pattern = "[\\w]".as_bytes();
x2(pattern, "ね".as_bytes(), 0, 3);
}
#[test]
fn utf8_bracket_d_no_match() {
n(b"[\\d]", "ふ".as_bytes());
}
#[test]
fn utf8_bracket_D() {
x2(b"[\\D]", "は".as_bytes(), 0, 3);
}
#[test]
fn utf8_bracket_s_no_match() {
n(b"[\\s]", "く".as_bytes());
}
#[test]
fn utf8_bracket_S() {
x2(b"[\\S]", "へ".as_bytes(), 0, 3);
}
#[test]
fn utf8_bracket_wd() {
x2(b"[\\w\\d]", "よ".as_bytes(), 0, 3);
}
#[test]
fn utf8_bracket_wd_skip_space() {
let input = [b" ", "よ".as_bytes()].concat();
x2(b"[\\w\\d]", &input, 3, 6);
}
#[test]
fn utf8_w_kanji_no_match() {
let input = [b" ", "鬼車".as_bytes()].concat();
n([b"\\w", "鬼車".as_bytes()].concat().as_slice(), &input);
}
#[test]
fn utf8_kanji_W_kanji() {
let pattern = ["鬼".as_bytes(), b"\\W", "車".as_bytes()].concat();
let input = ["鬼".as_bytes(), b" ", "車".as_bytes()].concat();
x2(&pattern, &input, 0, 7);
}
#[test]
fn utf8_dot_interleave() {
let pattern = "あ.い.う".as_bytes();
x2(pattern, "ああいいう".as_bytes(), 0, 15);
}
#[test]
fn utf8_mixed_classes_dot() {
let pattern = [b".\\w", "う".as_bytes(), b"\\W..", "ぞ".as_bytes()].concat();
let input = "えうう うぞぞ".as_bytes();
x2(&pattern, input, 0, 19);
}
#[test]
fn utf8_s_w_repeat() {
let pattern = [b"\\s\\w", "こここ".as_bytes()].concat();
let input = [b" ", "ここここ".as_bytes()].concat();
x2(&pattern, &input, 0, 13);
}
#[test]
fn utf8_dot_any_kanji() {
let pattern = "ああ.け".as_bytes();
x2(pattern, "ああけけ".as_bytes(), 0, 12);
}
#[test]
fn utf8_dot_prefix_no_match() {
let pattern = ".い".as_bytes();
n(pattern, "いえ".as_bytes());
}
#[test]
fn utf8_dot_prefix_match() {
let pattern = ".お".as_bytes();
x2(pattern, "おお".as_bytes(), 0, 6);
}
#[test]
fn utf8_caret_dollar() {
x2("^む$".as_bytes(), "む".as_bytes(), 0, 3);
}
#[test]
fn utf8_caret_w_dollar() {
x2(b"^\\w$", "に".as_bytes(), 0, 3);
}
#[test]
fn utf8_caret_w_suffix_dollar() {
let pattern = [b"^\\w", "かきくけこ".as_bytes(), b"$"].concat();
let input = [b"z", "かきくけこ".as_bytes()].concat();
x2(&pattern, &input, 0, 16);
}
#[test]
fn utf8_caret_w_dots_suffix() {
let pattern = [b"^\\w...", "うえお".as_bytes(), b"$"].concat();
let input = [b"z", "あいううえお".as_bytes()].concat();
x2(&pattern, &input, 0, 19);
}
#[test]
fn utf8_mixed_w_d_s_W() {
let pattern = [b"\\w\\w\\s\\W", "おおお".as_bytes(), b"\\d"].concat();
let input = [b"a", "お".as_bytes(), b" ", "おおお".as_bytes(), b"4"].concat();
x2(&pattern, &input, 0, 16);
}
#[test]
fn utf8_anchor_A() {
let pattern = [b"\\A", "たちつ".as_bytes()].concat();
x2(&pattern, "たちつ".as_bytes(), 0, 9);
}
#[test]
fn utf8_anchor_Z() {
let pattern = ["むめも".as_bytes(), b"\\Z"].concat();
x2(&pattern, "むめも".as_bytes(), 0, 9);
}
#[test]
fn utf8_anchor_z() {
let pattern = ["かきく".as_bytes(), b"\\z"].concat();
x2(&pattern, "かきく".as_bytes(), 0, 9);
}
#[test]
fn utf8_anchor_Z_newline() {
let pattern = ["かきく".as_bytes(), b"\\Z"].concat();
let input = ["かきく".as_bytes(), b"\n"].concat();
x2(&pattern, &input, 0, 9);
}
#[test]
fn utf8_anchor_G() {
let pattern = [b"\\G", "ぽぴ".as_bytes()].concat();
x2(&pattern, "ぽぴ".as_bytes(), 0, 6);
}
#[test]
fn utf8_anchor_G_no_match() {
let pattern = [b"\\G", "え".as_bytes()].concat();
n(&pattern, "うえお".as_bytes());
}
#[test]
fn utf8_anchor_G_trailing_no_match() {
let pattern = ["とて".as_bytes(), b"\\G"].concat();
n(&pattern, "とて".as_bytes());
}
#[test]
fn utf8_anchor_A_trailing_no_match() {
let pattern = ["まみ".as_bytes(), b"\\A"].concat();
n(&pattern, "まみ".as_bytes());
}
#[test]
fn utf8_anchor_A_mid_no_match() {
let pattern = ["ま".as_bytes(), b"\\A", "み".as_bytes()].concat();
n(&pattern, "まみ".as_bytes());
}
#[test]
fn utf8_case_insensitive_a() {
let pattern = [b"(?i:", "あ".as_bytes(), b")"].concat();
x2(&pattern, "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_case_insensitive_pair() {
let pattern = [b"(?i:", "ぶべ".as_bytes(), b")"].concat();
x2(&pattern, "ぶべ".as_bytes(), 0, 6);
}
#[test]
fn utf8_case_insensitive_no_match() {
let pattern = [b"(?i:", "い".as_bytes(), b")"].concat();
n(&pattern, "う".as_bytes());
}
#[test]
fn utf8_multiline_dot() {
let pattern = [b"(?m:", "よ".as_bytes(), b".)"].concat();
let input = ["よ".as_bytes(), b"\n"].concat();
x2(&pattern, &input, 0, 4);
}
#[test]
fn utf8_multiline_dot_prefix() {
let pattern = [b"(?m:.", "め".as_bytes(), b")"].concat();
let input = ["ま".as_bytes(), b"\n", "め".as_bytes()].concat();
x2(&pattern, &input, 3, 7);
}
#[test]
fn utf8_question_no_match_variant() {
x2("変?".as_bytes(), "化".as_bytes(), 0, 0);
}
#[test]
fn utf8_star_no_match_at_start() {
x2("馬*".as_bytes(), "鹿馬馬馬馬".as_bytes(), 0, 0);
}
#[test]
fn utf8_plus_no_match() {
n("山+".as_bytes(), b"");
}
#[test]
fn utf8_plus_partial() {
x2("え+".as_bytes(), "ええううう".as_bytes(), 0, 6);
}
#[test]
fn utf8_plus_skip_first() {
x2("う+".as_bytes(), "おうううう".as_bytes(), 3, 15);
}
#[test]
fn utf8_dot_question() {
x2(b".?", "た".as_bytes(), 0, 3);
}
#[test]
fn utf8_dot_star_multi() {
x2(b".*", "ぱぴぷぺ".as_bytes(), 0, 12);
}
#[test]
fn utf8_dot_plus_single() {
x2(b".+", "ろ".as_bytes(), 0, 3);
}
#[test]
fn utf8_dot_plus_stops_at_newline() {
let input = ["いうえか".as_bytes(), b"\n"].concat();
x2(b".+", &input, 0, 12);
}
#[test]
fn utf8_alt_pair_first() {
let pattern = ["あい".as_bytes(), b"|", "いう".as_bytes()].concat();
x2(&pattern, "あい".as_bytes(), 0, 6);
}
#[test]
fn utf8_alt_pair_second() {
let pattern = ["あい".as_bytes(), b"|", "いう".as_bytes()].concat();
x2(&pattern, "いう".as_bytes(), 0, 6);
}
#[test]
fn utf8_alt_noncap_first() {
let pattern = [
"を".as_bytes(),
b"(?:",
"かき".as_bytes(),
b"|",
"きく".as_bytes(),
b")",
]
.concat();
x2(&pattern, "をかき".as_bytes(), 0, 9);
}
#[test]
fn utf8_alt_noncap_second() {
let pattern = [
"を".as_bytes(),
b"(?:",
"かき".as_bytes(),
b"|",
"きく".as_bytes(),
b")",
"け".as_bytes(),
]
.concat();
x2(&pattern, "をきくけ".as_bytes(), 0, 12);
}
#[test]
fn utf8_alt_nested() {
let pattern = [
"あい".as_bytes(),
b"|(?:",
"あう".as_bytes(),
b"|",
"あを".as_bytes(),
b")",
]
.concat();
x2(&pattern, "あを".as_bytes(), 0, 6);
}
#[test]
fn utf8_alt_three() {
let pattern = [
"あ".as_bytes(),
b"|",
"い".as_bytes(),
b"|",
"う".as_bytes(),
]
.concat();
x2(&pattern, "えう".as_bytes(), 3, 6);
}
#[test]
fn utf8_alt_many() {
let pattern = [
"あ".as_bytes(),
b"|",
"い".as_bytes(),
b"|",
"うえ".as_bytes(),
b"|",
"おかき".as_bytes(),
b"|",
"く".as_bytes(),
b"|",
"けこさ".as_bytes(),
b"|",
"しすせ".as_bytes(),
b"|",
"そ".as_bytes(),
b"|",
"たち".as_bytes(),
b"|",
"つてとなに".as_bytes(),
b"|",
"ぬね".as_bytes(),
]
.concat();
x2(&pattern, "しすせ".as_bytes(), 0, 9);
}
#[test]
fn utf8_alt_many_no_match() {
let pattern = [
"あ".as_bytes(),
b"|",
"い".as_bytes(),
b"|",
"うえ".as_bytes(),
b"|",
"おかき".as_bytes(),
b"|",
"く".as_bytes(),
b"|",
"けこさ".as_bytes(),
b"|",
"しすせ".as_bytes(),
b"|",
"そ".as_bytes(),
b"|",
"たち".as_bytes(),
b"|",
"つてとなに".as_bytes(),
b"|",
"ぬね".as_bytes(),
]
.concat();
n(&pattern, "すせ".as_bytes());
}
#[test]
fn utf8_alt_caret_search() {
let pattern = ["あ".as_bytes(), b"|^", "わ".as_bytes()].concat();
x2(&pattern, "ぶあ".as_bytes(), 3, 6);
}
#[test]
fn utf8_alt_caret_match() {
let pattern = ["あ".as_bytes(), b"|^", "を".as_bytes()].concat();
x2(&pattern, "をあ".as_bytes(), 0, 3);
}
#[test]
fn utf8_alt_G_search() {
let pattern = ["鬼".as_bytes(), b"|\\G", "車".as_bytes()].concat();
x2(&pattern, "け車鬼".as_bytes(), 6, 9);
}
#[test]
fn utf8_alt_G_match_start() {
let pattern = ["鬼".as_bytes(), b"|\\G", "車".as_bytes()].concat();
x2(&pattern, "車鬼".as_bytes(), 0, 3);
}
#[test]
fn utf8_alt_A_search() {
let pattern = ["鬼".as_bytes(), b"|\\A", "車".as_bytes()].concat();
let input = [b"b", "車鬼".as_bytes()].concat();
x2(&pattern, &input, 4, 7);
}
#[test]
fn utf8_alt_A_match() {
let pattern = ["鬼".as_bytes(), b"|\\A", "車".as_bytes()].concat();
x2(&pattern, "車".as_bytes(), 0, 3);
}
#[test]
fn utf8_alt_Z_search() {
let pattern = ["鬼".as_bytes(), b"|", "車".as_bytes(), b"\\Z"].concat();
x2(&pattern, "車鬼".as_bytes(), 3, 6);
}
#[test]
fn utf8_alt_Z_match() {
let pattern = ["鬼".as_bytes(), b"|", "車".as_bytes(), b"\\Z"].concat();
x2(&pattern, "車".as_bytes(), 0, 3);
}
#[test]
fn utf8_alt_Z_newline() {
let pattern = ["鬼".as_bytes(), b"|", "車".as_bytes(), b"\\Z"].concat();
let input = ["車".as_bytes(), b"\n"].concat();
x2(&pattern, &input, 0, 3);
}
#[test]
fn utf8_alt_z_search() {
let pattern = ["鬼".as_bytes(), b"|", "車".as_bytes(), b"\\z"].concat();
x2(&pattern, "車鬼".as_bytes(), 3, 6);
}
#[test]
fn utf8_alt_z_match() {
let pattern = ["鬼".as_bytes(), b"|", "車".as_bytes(), b"\\z"].concat();
x2(&pattern, "車".as_bytes(), 0, 3);
}
#[test]
fn utf8_alt_w_or_s() {
x2(b"\\w|\\s", "お".as_bytes(), 0, 3);
}
#[test]
fn utf8_alt_w_or_percent() {
let input = [b"%", "お".as_bytes()].concat();
x2(b"\\w|%", &input, 0, 1);
}
#[test]
fn utf8_alt_w_or_special() {
let input = ["う".as_bytes(), b"&"].concat();
x2(b"\\w|[&$]", &input, 0, 3);
}
#[test]
fn utf8_range_i_ke() {
let pattern = "[い-け]".as_bytes();
x2(pattern, "う".as_bytes(), 0, 3);
}
#[test]
fn utf8_range_or_neg_range() {
let pattern = ["[い-け]|[^か-こ]".as_bytes()].concat();
x2(&pattern, "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_range_or_neg_range_2() {
let pattern = ["[い-け]|[^か-こ]".as_bytes()].concat();
x2(&pattern, "か".as_bytes(), 0, 3);
}
#[test]
fn utf8_neg_class_newline() {
let pattern = "[^あ]".as_bytes();
x2(pattern, b"\n", 0, 1);
}
#[test]
fn utf8_noncap_or_range_alt() {
let pattern = ["(?:あ|[う-き])|いを".as_bytes()].concat();
x2(&pattern, "うを".as_bytes(), 0, 3);
}
#[test]
fn utf8_noncap_or_range_alt_2() {
let pattern = ["(?:あ|[う-き])|いを".as_bytes()].concat();
x2(&pattern, "いを".as_bytes(), 0, 6);
}
#[test]
fn utf8_alt_lookahead() {
let pattern = ["あいう|(?=けけ)..ほ".as_bytes()].concat();
x2(&pattern, "けけほ".as_bytes(), 0, 9);
}
#[test]
fn utf8_alt_neg_lookahead() {
let pattern = ["あいう|(?!けけ)..ほ".as_bytes()].concat();
x2(&pattern, "あいほ".as_bytes(), 0, 9);
}
#[test]
fn utf8_dual_lookahead_alt() {
let pattern = ["(?=をあ)..あ|(?=をを)..あ".as_bytes()].concat();
x2(&pattern, "ををあ".as_bytes(), 0, 9);
}
#[test]
fn utf8_lookbehind() {
let pattern = ["(?<=あ|いう)い".as_bytes()].concat();
x2(&pattern, "いうい".as_bytes(), 6, 9);
}
#[test]
fn utf8_atomic_no_match() {
let pattern = ["(?>あ|あいえ)う".as_bytes()].concat();
n(&pattern, "あいえう".as_bytes());
}
#[test]
fn utf8_atomic_match() {
let pattern = ["(?>あいえ|あ)う".as_bytes()].concat();
x2(&pattern, "あいえう".as_bytes(), 0, 12);
}
#[test]
fn utf8_opt_or_char_match() {
let pattern = ["あ?|い".as_bytes()].concat();
x2(&pattern, "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_opt_or_char_empty() {
let pattern = ["あ?|い".as_bytes()].concat();
x2(&pattern, "い".as_bytes(), 0, 0);
}
#[test]
fn utf8_opt_or_char_empty2() {
let pattern = ["あ?|い".as_bytes()].concat();
x2(&pattern, b"", 0, 0);
}
#[test]
fn utf8_star_or_char() {
let pattern = ["あ*|い".as_bytes()].concat();
x2(&pattern, "ああ".as_bytes(), 0, 6);
}
#[test]
fn utf8_star_or_star_empty() {
let pattern = ["あ*|い*".as_bytes()].concat();
x2(&pattern, "いあ".as_bytes(), 0, 0);
}
#[test]
fn utf8_star_or_star_match() {
let pattern = ["あ*|い*".as_bytes()].concat();
x2(&pattern, "あい".as_bytes(), 0, 3);
}
#[test]
fn utf8_mixed_class_star_or_star() {
let pattern = ["[aあ]*|い*".as_bytes()].concat();
let input = [b"a", "あいいい".as_bytes()].concat();
x2(&pattern, &input, 0, 4);
}
#[test]
fn utf8_plus_or_star_empty() {
let pattern = ["あ+|い*".as_bytes()].concat();
x2(&pattern, b"", 0, 0);
}
#[test]
fn utf8_plus_or_star_second() {
let pattern = ["あ+|い*".as_bytes()].concat();
x2(&pattern, "いいい".as_bytes(), 0, 9);
}
#[test]
fn utf8_plus_or_star_first() {
let pattern = ["あ+|い*".as_bytes()].concat();
x2(&pattern, "あいいい".as_bytes(), 0, 3);
}
#[test]
fn utf8_plus_or_star_prefix() {
let pattern = ["あ+|い*".as_bytes()].concat();
let input = [b"a", "あいいい".as_bytes()].concat();
x2(&pattern, &input, 0, 0);
}
#[test]
fn utf8_plus_or_plus_no_match() {
let pattern = ["あ+|い+".as_bytes()].concat();
n(&pattern, b"");
}
#[test]
fn utf8_capture_alt_opt() {
let pattern = "(あ|い)?".as_bytes();
x2(pattern, "い".as_bytes(), 0, 3);
}
#[test]
fn utf8_capture_alt_star() {
let pattern = "(あ|い)*".as_bytes();
x2(pattern, "いあ".as_bytes(), 0, 6);
}
#[test]
fn utf8_capture_alt_plus() {
let pattern = "(あ|い)+".as_bytes();
x2(pattern, "いあい".as_bytes(), 0, 9);
}
#[test]
fn utf8_capture_pair_alt_plus_1() {
let pattern = "(あい|うあ)+".as_bytes();
x2(pattern, "うああいうえ".as_bytes(), 0, 12);
}
#[test]
fn utf8_capture_pair_alt_plus_2() {
let pattern = "(あい|うえ)+".as_bytes();
x2(pattern, "うああいうえ".as_bytes(), 6, 18);
}
#[test]
fn utf8_capture_pair_alt_plus_3() {
let pattern = "(あい|うあ)+".as_bytes();
x2(pattern, "ああいうあ".as_bytes(), 3, 15);
}
#[test]
fn utf8_capture_pair_alt_plus_4() {
let pattern = "(あい|うあ)+".as_bytes();
x2(pattern, "あいをうあ".as_bytes(), 0, 6);
}
#[test]
fn utf8_capture_pair_alt_plus_5() {
let pattern = "(あい|うあ)+".as_bytes();
let input = [b"$$zzzz", "あいをうあ".as_bytes()].concat();
x2(pattern, &input, 6, 12);
}
#[test]
fn utf8_capture_single_or_triple_plus_1() {
let pattern = "(あ|いあい)+".as_bytes();
x2(pattern, "あいあいあ".as_bytes(), 0, 15);
}
#[test]
fn utf8_capture_single_or_triple_plus_2() {
let pattern = "(あ|いあい)+".as_bytes();
x2(pattern, "いあ".as_bytes(), 3, 6);
}
#[test]
fn utf8_capture_single_or_triple_plus_3() {
let pattern = "(あ|いあい)+".as_bytes();
x2(pattern, "いあああいあ".as_bytes(), 3, 12);
}
#[test]
fn utf8_noncap_alt_pair() {
let pattern = "(?:あ|い)(?:あ|い)".as_bytes();
x2(pattern, "あい".as_bytes(), 0, 6);
}
#[test]
fn utf8_noncap_star_star() {
let pattern = "(?:あ*|い*)(?:あ*|い*)".as_bytes();
x2(pattern, "あああいいい".as_bytes(), 0, 9);
}
#[test]
fn utf8_noncap_star_plus() {
let pattern = "(?:あ*|い*)(?:あ+|い+)".as_bytes();
x2(pattern, "あああいいい".as_bytes(), 0, 18);
}
#[test]
fn utf8_noncap_plus_interval_2() {
let pattern = "(?:あ+|い+){2}".as_bytes();
x2(pattern, "あああいいい".as_bytes(), 0, 18);
}
#[test]
fn utf8_noncap_plus_interval_1_2() {
let pattern = "(?:あ+|い+){1,2}".as_bytes();
x2(pattern, "あああいいい".as_bytes(), 0, 18);
}
#[test]
fn utf8_noncap_plus_or_A_star() {
let pattern = ["(?:あ+|\\Aい*)うう".as_bytes()].concat();
x2(&pattern, "うう".as_bytes(), 0, 6);
}
#[test]
fn utf8_noncap_plus_or_A_star_no_match() {
let pattern = ["(?:あ+|\\Aい*)うう".as_bytes()].concat();
n(&pattern, "あいうう".as_bytes());
}
#[test]
fn utf8_noncap_caret_or_star_1() {
let pattern = "(?:^あ+|い+)*う".as_bytes();
x2(pattern, "ああいいいあいう".as_bytes(), 18, 24);
}
#[test]
fn utf8_noncap_caret_or_star_2() {
let pattern = "(?:^あ+|い+)*う".as_bytes();
x2(pattern, "ああいいいいう".as_bytes(), 0, 21);
}
#[test]
fn utf8_interval_0_inf() {
x2("う{0,}".as_bytes(), "うううう".as_bytes(), 0, 12);
}
#[test]
fn utf8_case_insensitive_alt() {
let pattern = ["あ|(?i)c".as_bytes()].concat();
x2(&pattern, b"C", 0, 1);
}
#[test]
fn utf8_case_insensitive_alt_2() {
let pattern = ["(?i)c|あ".as_bytes()].concat();
x2(&pattern, b"C", 0, 1);
}
#[test]
fn utf8_case_insensitive_group_or_a() {
let pattern = [b"(?i:", "あ".as_bytes(), b")|a"].concat();
x2(&pattern, b"a", 0, 1);
}
#[test]
fn utf8_case_insensitive_group_or_a_no() {
let pattern = [b"(?i:", "あ".as_bytes(), b")|a"].concat();
n(&pattern, b"A");
}
#[test]
fn utf8_class_opt() {
x2("[あいう]?".as_bytes(), "あいう".as_bytes(), 0, 3);
}
#[test]
fn utf8_class_star() {
x2("[あいう]*".as_bytes(), "あいう".as_bytes(), 0, 9);
}
#[test]
fn utf8_neg_class_star() {
x2("[^あいう]*".as_bytes(), "あいう".as_bytes(), 0, 0);
}
#[test]
fn utf8_neg_class_plus_no_match() {
n("[^あいう]+".as_bytes(), "あいう".as_bytes());
}
#[test]
fn utf8_lazy_question() {
x2("あ??".as_bytes(), "あああ".as_bytes(), 0, 0);
}
#[test]
fn utf8_lazy_question_sandwiched() {
x2("いあ??い".as_bytes(), "いあい".as_bytes(), 0, 9);
}
#[test]
fn utf8_lazy_star() {
x2("あ*?".as_bytes(), "あああ".as_bytes(), 0, 0);
}
#[test]
fn utf8_lazy_star_prefix() {
x2("いあ*?".as_bytes(), "いああ".as_bytes(), 0, 3);
}
#[test]
fn utf8_lazy_star_sandwiched() {
x2("いあ*?い".as_bytes(), "いああい".as_bytes(), 0, 12);
}
#[test]
fn utf8_lazy_plus() {
x2("あ+?".as_bytes(), "あああ".as_bytes(), 0, 3);
}
#[test]
fn utf8_lazy_plus_prefix() {
x2("いあ+?".as_bytes(), "いああ".as_bytes(), 0, 6);
}
#[test]
fn utf8_lazy_plus_sandwiched() {
x2("いあ+?い".as_bytes(), "いああい".as_bytes(), 0, 12);
}
#[test]
fn utf8_group_opt_lazy_question() {
x2("(?:天?)??".as_bytes(), "天".as_bytes(), 0, 0);
}
#[test]
fn utf8_group_lazy_question_opt() {
x2("(?:天??)?".as_bytes(), "天".as_bytes(), 0, 0);
}
#[test]
fn utf8_group_opt_lazy_plus() {
x2("(?:夢?)+?".as_bytes(), "夢夢夢".as_bytes(), 0, 3);
}
#[test]
fn utf8_group_plus_lazy_question() {
x2("(?:風+)??".as_bytes(), "風風風".as_bytes(), 0, 0);
}
#[test]
fn utf8_group_plus_lazy_question_suffix() {
x2("(?:雪+)??霜".as_bytes(), "雪雪雪霜".as_bytes(), 0, 12);
}
#[test]
fn utf8_group_opt_interval_2_empty() {
x2("(?:あい)?{2}".as_bytes(), b"", 0, 0);
}
#[test]
fn utf8_group_opt_interval_2_match() {
x2("(?:鬼車)?{2}".as_bytes(), "鬼車鬼車鬼".as_bytes(), 0, 12);
}
#[test]
fn utf8_group_star_interval_0() {
x2("(?:鬼車)*{0}".as_bytes(), "鬼車鬼車鬼".as_bytes(), 0, 0);
}
#[test]
fn utf8_group_interval_3_inf() {
x2(
"(?:鬼車){3,}".as_bytes(),
"鬼車鬼車鬼車鬼車".as_bytes(),
0,
24,
);
}
#[test]
fn utf8_group_interval_3_inf_no_match() {
n("(?:鬼車){3,}".as_bytes(), "鬼車鬼車".as_bytes());
}
#[test]
fn utf8_group_interval_2_4() {
x2("(?:鬼車){2,4}".as_bytes(), "鬼車鬼車鬼車".as_bytes(), 0, 18);
}
#[test]
fn utf8_group_interval_2_4_max() {
x2(
"(?:鬼車){2,4}".as_bytes(),
"鬼車鬼車鬼車鬼車鬼車".as_bytes(),
0,
24,
);
}
#[test]
fn utf8_group_interval_2_4_lazy() {
x2(
"(?:鬼車){2,4}?".as_bytes(),
"鬼車鬼車鬼車鬼車鬼車".as_bytes(),
0,
12,
);
}
#[test]
fn utf8_literal_brace_comma() {
let pattern = "(?:鬼車){,}".as_bytes();
let input = "鬼車{,}".as_bytes();
x2(pattern, input, 0, 9);
}
#[test]
fn utf8_group_plus_lazy_interval_2() {
x2(
"(?:かきく)+?{2}".as_bytes(),
"かきくかきくかきく".as_bytes(),
0,
18,
);
}
#[test]
fn utf8_capture_nested_pair() {
x2("((時間))".as_bytes(), "時間".as_bytes(), 0, 6);
}
#[test]
fn utf8_capture_nested_pair_outer() {
x3("((風水))".as_bytes(), "風水".as_bytes(), 0, 6, 1);
}
#[test]
fn utf8_capture_nested_pair_inner() {
x3("((昨日))".as_bytes(), "昨日".as_bytes(), 0, 6, 2);
}
#[test]
fn utf8_capture_deeply_nested() {
let pattern = "((((((((((((((((((((量子))))))))))))))))))))".as_bytes();
x3(pattern, "量子".as_bytes(), 0, 6, 20);
}
#[test]
fn utf8_capture_two_groups_1() {
x3("(あい)(うえ)".as_bytes(), "あいうえ".as_bytes(), 0, 6, 1);
}
#[test]
fn utf8_capture_two_groups_2() {
x3("(あい)(うえ)".as_bytes(), "あいうえ".as_bytes(), 6, 12, 2);
}
#[test]
fn utf8_capture_empty_and_groups() {
let pattern = "()(あ)いう(えおか)きくけこ".as_bytes();
let input = "あいうえおかきくけこ".as_bytes();
x3(pattern, input, 9, 18, 3);
}
#[test]
fn utf8_capture_nested_with_empty() {
let pattern = "(()(あ)いう(えおか)きくけこ)".as_bytes();
let input = "あいうえおかきくけこ".as_bytes();
x3(pattern, input, 9, 18, 4);
}
#[test]
fn utf8_capture_von_manstein() {
let pattern = ".*(フォ)ン・マ(ン()シュタ)イン".as_bytes();
let input = "フォン・マンシュタイン".as_bytes();
x3(pattern, input, 15, 27, 2);
}
#[test]
fn utf8_capture_caret() {
x2("(^あ)".as_bytes(), "あ".as_bytes(), 0, 3);
}
#[test]
fn utf8_capture_alt_first() {
x3("(あ)|(あ)".as_bytes(), "いあ".as_bytes(), 3, 6, 1);
}
#[test]
fn utf8_capture_alt_caret_second() {
x3("(^あ)|(あ)".as_bytes(), "いあ".as_bytes(), 3, 6, 2);
}
#[test]
fn utf8_capture_opt() {
x3("(あ?)".as_bytes(), "あああ".as_bytes(), 0, 3, 1);
}
#[test]
fn utf8_capture_star() {
x3("(ま*)".as_bytes(), "ままま".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_star_empty() {
x3("(と*)".as_bytes(), b"", 0, 0, 1);
}
#[test]
fn utf8_capture_plus() {
x3("(る+)".as_bytes(), "るるるるるるる".as_bytes(), 0, 21, 1);
}
#[test]
fn utf8_capture_alt_plus_star() {
x3("(ふ+|へ*)".as_bytes(), "ふふふへへ".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_alt_plus_opt() {
x3("(あ+|い?)".as_bytes(), "いいいああ".as_bytes(), 0, 3, 1);
}
#[test]
fn utf8_capture_group_opt() {
x3("(あいう)?".as_bytes(), "あいう".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_group_star() {
x3("(あいう)*".as_bytes(), "あいう".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_group_plus() {
x3("(あいう)+".as_bytes(), "あいう".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_alt_group_plus() {
x3("(さしす|あいう)+".as_bytes(), "あいう".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_cc_pair_alt_plus() {
x3(
"([なにぬ][かきく]|かきく)+".as_bytes(),
"かきく".as_bytes(),
0,
9,
1,
);
}
#[test]
fn utf8_capture_case_insensitive() {
x3("((?i:あいう))".as_bytes(), "あいう".as_bytes(), 0, 9, 1);
}
#[test]
fn utf8_capture_multiline() {
let pattern = "((?m:あ.う))".as_bytes();
let input = ["あ".as_bytes(), b"\n", "う".as_bytes()].concat();
x3(pattern, &input, 0, 7, 1);
}
#[test]
fn utf8_capture_lookahead() {
let pattern = "((?=あん)あ)".as_bytes();
x3(pattern, "あんい".as_bytes(), 0, 3, 1);
}
#[test]
fn utf8_capture_alt_prefix() {
let pattern = "あいう|(.あいえ)".as_bytes();
x3(pattern, "んあいえ".as_bytes(), 0, 12, 1);
}
#[test]
fn utf8_greedy_star_capture() {
let pattern = "あ*(.)".as_bytes();
x3(pattern, "ああああん".as_bytes(), 12, 15, 1);
}
#[test]
fn utf8_lazy_star_capture() {
let pattern = "あ*?(.)".as_bytes();
x3(pattern, "ああああん".as_bytes(), 0, 3, 1);
}
#[test]
fn utf8_lazy_star_capture_specific() {
let pattern = "あ*?(ん)".as_bytes();
x3(pattern, "ああああん".as_bytes(), 12, 15, 1);
}
#[test]
fn utf8_class_star_capture() {
let pattern = "[いうえ]あ*(.)".as_bytes();
x3(pattern, "えああああん".as_bytes(), 15, 18, 1);
}
#[test]
fn utf8_capture_anchor_A() {
let pattern = [b"(\\A", "いい".as_bytes(), b")", "うう".as_bytes()].concat();
x3(&pattern, "いいうう".as_bytes(), 0, 6, 1);
}
#[test]
fn utf8_capture_anchor_A_no_match() {
let pattern = [b"(\\A", "いい".as_bytes(), b")", "うう".as_bytes()].concat();
n(&pattern, "んいいうう".as_bytes());
}
#[test]
fn utf8_capture_caret_group() {
x3("(^いい)うう".as_bytes(), "いいうう".as_bytes(), 0, 6, 1);
}
#[test]
fn utf8_capture_caret_group_no_match() {
n("(^いい)うう".as_bytes(), "んいいうう".as_bytes());
}
#[test]
fn utf8_capture_dollar_group() {
x3("ろろ(るる$)".as_bytes(), "ろろるる".as_bytes(), 6, 12, 1);
}
#[test]
fn utf8_capture_dollar_group_no_match() {
n("ろろ(るる$)".as_bytes(), "ろろるるる".as_bytes());
}
#[test]
fn utf8_backref_kanji() {
let pattern = ["(無)".as_bytes(), b"\\1"].concat();
x2(&pattern, "無無".as_bytes(), 0, 6);
}
#[test]
fn utf8_backref_kanji_no_match() {
let pattern = ["(無)".as_bytes(), b"\\1"].concat();
n(&pattern, "無武".as_bytes());
}
#[test]
fn utf8_backref_opt() {
let pattern = ["(空?)".as_bytes(), b"\\1"].concat();
x2(&pattern, "空空".as_bytes(), 0, 6);
}
#[test]
fn utf8_backref_lazy_opt() {
let pattern = ["(空??)".as_bytes(), b"\\1"].concat();
x2(&pattern, "空空".as_bytes(), 0, 0);
}
#[test]
fn utf8_backref_star() {
let pattern = ["(空*)".as_bytes(), b"\\1"].concat();
x2(&pattern, "空空空空空".as_bytes(), 0, 12);
}
#[test]
fn utf8_backref_star_capture() {
let pattern = ["(空*)".as_bytes(), b"\\1"].concat();
x3(&pattern, "空空空空空".as_bytes(), 0, 6, 1);
}
#[test]
fn utf8_backref_prefix_star() {
let pattern = ["あ(い*)".as_bytes(), b"\\1"].concat();
x2(&pattern, "あいいいい".as_bytes(), 0, 15);
}
#[test]
fn utf8_backref_prefix_star_empty() {
let pattern = ["あ(い*)".as_bytes(), b"\\1"].concat();
x2(&pattern, "あい".as_bytes(), 0, 3);
}
#[test]
fn utf8_backref_two_groups() {
let pattern = ["(あ*)(い*)".as_bytes(), b"\\1\\2"].concat();
x2(&pattern, "あああいいあああいい".as_bytes(), 0, 30);
}
#[test]
fn utf8_backref_group2() {
let pattern = ["(あ*)(い*)".as_bytes(), b"\\2"].concat();
x2(&pattern, "あああいいいい".as_bytes(), 0, 21);
}
#[test]
fn utf8_backref_group2_capture() {
let pattern = ["(あ*)(い*)".as_bytes(), b"\\2"].concat();
x3(&pattern, "あああいいいい".as_bytes(), 9, 15, 2);
}
#[test]
fn utf8_backref_7_nested() {
let pattern = ["(((((((ぽ*)ぺ))))))ぴ".as_bytes(), b"\\7"].concat();
x2(&pattern, "ぽぽぽぺぴぽぽぽ".as_bytes(), 0, 24);
}
#[test]
fn utf8_backref_7_nested_capture() {
let pattern = ["(((((((ぽ*)ぺ))))))ぴ".as_bytes(), b"\\7"].concat();
x3(&pattern, "ぽぽぽぺぴぽぽぽ".as_bytes(), 0, 9, 7);
}
#[test]
fn utf8_backref_three_groups() {
let pattern = ["(は)(ひ)(ふ)".as_bytes(), b"\\2\\1\\3"].concat();
x2(&pattern, "はひふひはふ".as_bytes(), 0, 18);
}
#[test]
fn utf8_backref_char_class() {
let pattern = ["([き-け])".as_bytes(), b"\\1"].concat();
x2(&pattern, "くく".as_bytes(), 0, 6);
}
#[test]
fn utf8_backref_wds() {
let input = ["あ".as_bytes(), b"5 ", "あ".as_bytes(), b"5 "].concat();
x2(b"(\\w\\d\\s)\\1", &input, 0, 10);
}
#[test]
fn utf8_backref_wds_no_match() {
let input = ["あ".as_bytes(), b"5 ", "あ".as_bytes(), b"5"].concat();
n(b"(\\w\\d\\s)\\1", &input);
}
#[test]
fn utf8_backref_alt_fullwidth() {
let pattern = ["(誰?|[あ-う]{3})".as_bytes(), b"\\1"].concat();
x2(&pattern, "誰?誰?".as_bytes(), 0, 12);
}
#[test]
fn utf8_backref_alt_prefix() {
let pattern = [b"...", "(誰?|[あ-う]{3})".as_bytes(), b"\\1"].concat();
let input = ["あ".as_bytes(), b"a", "あ誰?誰?".as_bytes()].concat();
x2(&pattern, &input, 0, 19);
}
#[test]
fn utf8_backref_alt_cc() {
let pattern = ["(誰?|[あ-う]{3})".as_bytes(), b"\\1"].concat();
x2(&pattern, "ういうういう".as_bytes(), 0, 18);
}
#[test]
fn utf8_backref_caret() {
let pattern = ["(^こ)".as_bytes(), b"\\1"].concat();
x2(&pattern, "ここ".as_bytes(), 0, 6);
}
#[test]
fn utf8_backref_caret_no_match() {
let pattern = ["(^む)".as_bytes(), b"\\1"].concat();
n(&pattern, "めむむ".as_bytes());
}
#[test]
fn utf8_backref_dollar_no_match() {
let pattern = ["(あ$)".as_bytes(), b"\\1"].concat();
n(&pattern, "ああ".as_bytes());
}
#[test]
fn utf8_backref_Z_no_match() {
let pattern = ["(あい".as_bytes(), b"\\Z)\\1"].concat();
n(&pattern, "あい".as_bytes());
}
#[test]
fn utf8_backref_star_Z() {
let pattern = ["(あ*".as_bytes(), b"\\Z)\\1"].concat();
x2(&pattern, "あ".as_bytes(), 3, 3);
}
#[test]
fn utf8_backref_dot_star_Z() {
let pattern = [b".", "(あ*".as_bytes(), b"\\Z)\\1"].concat();
x2(&pattern, "いあ".as_bytes(), 3, 6);
}
#[test]
fn utf8_backref_nested_kana() {
let pattern = ["(.(やいゆ)".as_bytes(), b"\\2)"].concat();
let input = [b"z", "やいゆやいゆ".as_bytes()].concat();
x3(&pattern, &input, 0, 19, 1);
}
#[test]
fn utf8_backref_nested_digits() {
let pattern = b"(.(..\\d.)\\2)";
let input = ["あ".as_bytes(), b"12341234"].concat();
x3(pattern, &input, 0, 11, 1);
}
#[test]
fn utf8_nested_class_kana() {
x2("[[ひふ]]".as_bytes(), "ふ".as_bytes(), 0, 3);
}
#[test]
fn utf8_nested_class_kana_outer() {
x2("[[いおう]か]".as_bytes(), "か".as_bytes(), 0, 3);
}
#[test]
fn utf8_nested_neg_class_kana() {
n("[[^あ]]".as_bytes(), "あ".as_bytes());
}
#[test]
fn utf8_neg_nested_class_kana() {
n("[^[あ]]".as_bytes(), "あ".as_bytes());
}
#[test]
fn utf8_neg_neg_class_kana() {
x2("[^[^あ]]".as_bytes(), "あ".as_bytes(), 0, 3);
}
#[test]
fn ascii_hex_x40() {
x2(b"\\x40", b"@", 0, 1);
}
#[test]
fn ascii_hex_x1() {
x2(b"\\x1", b"\x01", 0, 1);
}
#[test]
fn ascii_hex_x_brace_1() {
x2(b"\\x{1}", b"\x01", 0, 1);
}
#[test]
fn ascii_hex_x_brace_4E38() {
x2(b"\\x{4E38}", b"\xE4\xB8\xB8", 0, 3);
}
#[test]
fn ascii_unicode_u4E38() {
x2(b"\\u4E38", b"\xE4\xB8\xB8", 0, 3);
}
#[test]
fn ascii_unicode_u0040() {
x2(b"\\u0040", b"@", 0, 1);
}
#[test]
fn ascii_word_boundary_cstar() {
x2(b"c.*\\b", b"abc", 2, 3);
}
#[test]
fn ascii_word_boundary_wrapped() {
x2(b"\\b.*abc.*\\b", b"abc", 0, 3);
}
#[test]
fn ascii_interval_lazy_1_3() {
x2(b"a{1,3}?", b"aaa", 0, 1);
}
#[test]
fn ascii_interval_exact_3() {
x2(b"a{3}", b"aaa", 0, 3);
}
#[test]
fn ascii_interval_exact_3_lazy() {
x2(b"a{3}?", b"aaa", 0, 3);
}
#[test]
fn ascii_interval_exact_3_lazy_short() {
x2(b"a{3}?", b"aa", 0, 0);
}
#[test]
fn ascii_interval_exact_3_3_lazy() {
x2(b"a{3,3}?", b"aaa", 0, 3);
}
#[test]
fn ascii_interval_exact_3_3_lazy_no_match() {
n(b"a{3,3}?", b"aa");
}
#[test]
fn ascii_interval_possessive_1_3() {
x2(b"a{1,3}+", b"aaaaaa", 0, 6);
}
#[test]
fn ascii_interval_possessive_3() {
x2(b"a{3}+", b"aaaaaa", 0, 6);
}
#[test]
fn ascii_interval_possessive_3_3() {
x2(b"a{3,3}+", b"aaaaaa", 0, 6);
}
#[test]
fn ascii_interval_lazy_2_3_no_match() {
n(b"a{2,3}?", b"a");
}
#[test]
fn ascii_interval_reversed_no_match() {
n(b"a{3,2}a", b"aaa");
}
#[test]
fn ascii_interval_reversed_b() {
x2(b"a{3,2}b", b"aaab", 0, 4);
}
#[test]
fn ascii_interval_reversed_b_2() {
x2(b"a{3,2}b", b"aaaab", 1, 5);
}
#[test]
fn ascii_interval_reversed_b_short() {
x2(b"a{3,2}b", b"aab", 0, 3);
}
#[test]
fn ascii_interval_reversed_lazy_empty() {
x2(b"a{3,2}?", b"", 0, 0);
}
#[test]
fn ascii_interval_possessive_2_3_a() {
x2(b"a{2,3}+a", b"aaa", 0, 3);
}
#[test]
fn ascii_wide_range_class() {
x2(b"[\\x{0}-\\x{7fffffff}]", b"a", 0, 1);
}
#[test]
fn ascii_wide_range_class_kanji() {
x2(b"[\\x{7f}-\\x{7fffffff}]", "\u{5BB6}".as_bytes(), 0, 3);
}
#[test]
fn ascii_nested_class_cdef() {
x2(b"[a[cdef]]", b"a", 0, 1);
}
#[test]
fn ascii_nested_class_xyz_range_no_match() {
n(b"[a[xyz]-c]", b"b");
}
#[test]
fn ascii_nested_class_xyz_range_a() {
x2(b"[a[xyz]-c]", b"a", 0, 1);
}
#[test]
fn ascii_nested_class_xyz_range_dash() {
x2(b"[a[xyz]-c]", b"-", 0, 1);
}
#[test]
fn ascii_nested_class_xyz_range_c() {
x2(b"[a[xyz]-c]", b"c", 0, 1);
}
#[test]
fn ctrl_a_escape() {
x2(b"\\ca", b"\x01", 0, 1);
}
#[test]
fn ctrl_b_escape() {
x2(b"\\C-b", b"\x02", 0, 1);
}
#[test]
fn ctrl_backslash_escape() {
x2(b"\\c\\\\", b"\x1c", 0, 1);
}
#[test]
fn ctrl_backslash_in_class() {
x2(b"q[\\c\\\\]", b"q\x1c", 0, 2);
}
#[test]
fn empty_pattern_nonempty_string() {
x2(b"", b"a", 0, 0);
}
#[test]
fn literal_35_a() {
x2(
b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
0,
35,
);
}
#[test]
fn case_insensitive_ret() {
x2(b"(?i:#RET#)", b"#INS##RET#", 5, 10);
}
#[test]
fn extended_mode_whitespace() {
x2(b"(?x) G (o O(?-x)oO) g L", b"GoOoOgLe", 0, 7);
}
#[test]
fn dot_no_match_empty() {
n(b".", b"");
}
#[test]
fn posix_upper_bracket_literal() {
x2(b"[[:upper\\] :]]", b"]", 0, 1);
}
#[test]
fn nested_bracket_double_colon() {
x2(b"[[::]]", b":", 0, 1);
}
#[test]
fn nested_bracket_triple_colon() {
x2(b"[[:::]]", b":", 0, 1);
}
#[test]
fn nested_bracket_backslash_colon_star() {
x2(b"[[:\\]:]]*", b":]", 0, 2);
}
#[test]
fn nested_bracket_open_bracket_star() {
x2(b"[[:\\[:]]*", b":[", 0, 2);
}
#[test]
fn nested_bracket_close_bracket_star() {
x2(b"[[:\\]]]*", b":]", 0, 2);
}
#[test]
fn case_insensitive_a_lower() {
x2(b"(?i:a)", b"a", 0, 1);
}
#[test]
fn case_insensitive_a_upper() {
x2(b"(?i:a)", b"A", 0, 1);
}
#[test]
fn case_insensitive_A_lower() {
x2(b"(?i:A)", b"a", 0, 1);
}
#[test]
fn case_insensitive_i_upper() {
x2(b"(?i:i)", b"I", 0, 1);
}
#[test]
fn case_insensitive_I_lower() {
x2(b"(?i:I)", b"i", 0, 1);
}
#[test]
fn case_insensitive_range_upper() {
x2(b"(?i:[A-Z])", b"i", 0, 1);
}
#[test]
fn case_insensitive_range_lower() {
x2(b"(?i:[a-z])", b"I", 0, 1);
}
#[test]
fn case_insensitive_no_match() {
n(b"(?i:A)", b"b");
}
#[test]
fn case_insensitive_ss_lower() {
x2(b"(?i:ss)", b"ss", 0, 2);
}
#[test]
fn case_insensitive_ss_mixed() {
x2(b"(?i:ss)", b"Ss", 0, 2);
}
#[test]
fn case_insensitive_ss_upper() {
x2(b"(?i:ss)", b"SS", 0, 2);
}
#[test]
fn case_insensitive_ss_long_s_upper() {
x2(b"(?i:ss)", b"\xc5\xbfS", 0, 3);
}
#[test]
fn case_insensitive_ss_s_long_s() {
x2(b"(?i:ss)", b"s\xc5\xbf", 0, 3);
}
#[test]
fn case_insensitive_ss_sharp_s() {
x2(b"(?i:ss)", b"\xc3\x9f", 0, 2);
}
#[test]
fn case_insensitive_ss_capital_sharp_s() {
x2(b"(?i:ss)", b"\xe1\xba\x9e", 0, 3);
}
#[test]
fn case_insensitive_xssy_lower() {
x2(b"(?i:xssy)", b"xssy", 0, 4);
}
#[test]
fn case_insensitive_xssy_mixed() {
x2(b"(?i:xssy)", b"xSsy", 0, 4);
}
#[test]
fn case_insensitive_xssy_upper() {
x2(b"(?i:xssy)", b"xSSy", 0, 4);
}
#[test]
fn case_insensitive_xssy_long_s_upper() {
x2(b"(?i:xssy)", b"x\xc5\xbfSy", 0, 5);
}
#[test]
fn case_insensitive_xssy_s_long_s() {
x2(b"(?i:xssy)", b"xs\xc5\xbfy", 0, 5);
}
#[test]
fn case_insensitive_xssy_sharp_s() {
x2(b"(?i:xssy)", b"x\xc3\x9fy", 0, 4);
}
#[test]
fn case_insensitive_xssy_capital_sharp_s() {
x2(b"(?i:xssy)", b"x\xe1\xba\x9ey", 0, 5);
}
#[test]
fn case_insensitive_sharp_s_pattern_lower() {
x2(b"(?i:x\xc3\x9fy)", b"xssy", 0, 4);
}
#[test]
fn case_insensitive_sharp_s_pattern_upper() {
x2(b"(?i:x\xc3\x9fy)", b"xSSy", 0, 4);
}
#[test]
fn case_insensitive_sharp_s_alone_lower() {
x2(b"(?i:\xc3\x9f)", b"ss", 0, 2);
}
#[test]
fn case_insensitive_sharp_s_alone_upper() {
x2(b"(?i:\xc3\x9f)", b"SS", 0, 2);
}
#[test]
fn case_insensitive_sharp_s_class_lower() {
x2(b"(?i:[\xc3\x9f])", b"ss", 0, 2);
}
#[test]
fn case_insensitive_sharp_s_class_upper() {
x2(b"(?i:[\xc3\x9f])", b"SS", 0, 2);
}
#[test]
fn case_insensitive_lookbehind_ss() {
x2(b"(?i)(?<!ss)z", b"qqz", 2, 3);
}
#[test]
fn case_insensitive_range_upper_matches_lower() {
x2(b"(?i:[A-Z])", b"a", 0, 1);
}
#[test]
fn case_insensitive_range_f_m_upper() {
x2(b"(?i:[f-m])", b"H", 0, 1);
}
#[test]
fn case_insensitive_range_f_m_lower() {
x2(b"(?i:[f-m])", b"h", 0, 1);
}
#[test]
fn case_insensitive_range_f_m_no_match() {
n(b"(?i:[f-m])", b"e");
}
#[test]
fn case_insensitive_range_A_c_upper() {
x2(b"(?i:[A-c])", b"D", 0, 1);
}
#[test]
fn case_insensitive_neg_range_upper() {
n(b"(?i:[^a-z])", b"A");
}
#[test]
fn case_insensitive_neg_range_lower() {
n(b"(?i:[^a-z])", b"a");
}
#[test]
fn case_insensitive_range_bang_k_upper() {
x2(b"(?i:[!-k])", b"Z", 0, 1);
}
#[test]
fn case_insensitive_range_bang_k_digit() {
x2(b"(?i:[!-k])", b"7", 0, 1);
}
#[test]
fn case_insensitive_range_T_brace_lower() {
x2(b"(?i:[T-}])", b"b", 0, 1);
}
#[test]
fn case_insensitive_range_T_brace_brace() {
x2(b"(?i:[T-}])", b"{", 0, 1);
}
#[test]
fn case_insensitive_escaped_question_a() {
x2(b"(?i:\\?a)", b"?A", 0, 2);
}
#[test]
fn case_insensitive_escaped_star_a() {
x2(b"(?i:\\*A)", b"*a", 0, 2);
}
#[test]
fn multiline_dot_newline() {
x2(b"(?m:.)", b"\n", 0, 1);
}
#[test]
fn multiline_a_dot_newline() {
x2(b"(?m:a.)", b"a\n", 0, 2);
}
#[test]
fn multiline_dot_b_across_newline() {
x2(b"(?m:.b)", b"a\nb", 1, 3);
}
#[test]
fn multiline_dotstar_abc() {
x2(b"(?m:.*abc)", b"dddabddabc", 0, 10);
}
#[test]
fn case_insensitive_then_negate() {
n(b"(?i)(?-i)a", b"A");
}
#[test]
fn case_insensitive_then_negate_group() {
n(b"(?i)(?-i:a)", b"A");
}
#[test]
fn japanese_class_intersection_match_ku() {
x2("[[かきく]&&きく]".as_bytes(), "く".as_bytes(), 0, 3);
}
#[test]
fn japanese_class_intersection_no_match_ka() {
n("[[かきく]&&きく]".as_bytes(), "か".as_bytes());
}
#[test]
fn japanese_class_intersection_no_match_ke() {
n("[[かきく]&&きく]".as_bytes(), "け".as_bytes());
}
#[test]
fn japanese_range_triple_intersection() {
x2("[あ-ん&&い-を&&う-ゑ]".as_bytes(), "ゑ".as_bytes(), 0, 3);
}
#[test]
fn japanese_negated_range_triple_intersection() {
n("[^あ-ん&&い-を&&う-ゑ]".as_bytes(), "ゑ".as_bytes());
}
#[test]
fn japanese_negated_inner_class_intersection_match_i() {
x2("[[^あ&&あ]&&あ-ん]".as_bytes(), "い".as_bytes(), 0, 3);
}
#[test]
fn japanese_negated_inner_class_intersection_no_match_a() {
n("[[^あ&&あ]&&あ-ん]".as_bytes(), "あ".as_bytes());
}
#[test]
fn japanese_complex_negated_intersection_match_ki() {
x2(
"[[^あ-ん&&いうえお]&&[^う-か]]".as_bytes(),
"き".as_bytes(),
0,
3,
);
}
#[test]
fn japanese_complex_negated_intersection_no_match_i() {
n("[[^あ-ん&&いうえお]&&[^う-か]]".as_bytes(), "い".as_bytes());
}
#[test]
fn japanese_double_negated_intersection_match_u() {
x2("[^[^あいう]&&[^うえお]]".as_bytes(), "う".as_bytes(), 0, 3);
}
#[test]
fn japanese_double_negated_intersection_match_e() {
x2("[^[^あいう]&&[^うえお]]".as_bytes(), "え".as_bytes(), 0, 3);
}
#[test]
fn japanese_double_negated_intersection_no_match_ka() {
n("[^[^あいう]&&[^うえお]]".as_bytes(), "か".as_bytes());
}
#[test]
fn japanese_range_dash_intersection() {
x2("[あ-&&-あ]".as_bytes(), b"-", 0, 1);
}
#[test]
fn japanese_mixed_ascii_negated_intersection_match_e() {
x2(
"[^[^a-zあいう]&&[^bcdefgうえお]q-w]".as_bytes(),
"え".as_bytes(),
0,
3,
);
}
#[test]
fn japanese_mixed_ascii_negated_intersection_match_f() {
x2("[^[^a-zあいう]&&[^bcdefgうえお]g-w]".as_bytes(), b"f", 0, 1);
}
#[test]
fn japanese_mixed_ascii_negated_intersection_match_g() {
x2("[^[^a-zあいう]&&[^bcdefgうえお]g-w]".as_bytes(), b"g", 0, 1);
}
#[test]
fn japanese_mixed_ascii_negated_intersection_no_match_2() {
n("[^[^a-zあいう]&&[^bcdefgうえお]g-w]".as_bytes(), b"2");
}
#[test]
fn japanese_version_download_literal() {
let pattern = [
b"a<b>" as &[u8],
"バージョンのダウンロード".as_bytes(),
b"<\\/b>",
]
.concat();
let input = [
b"a<b>" as &[u8],
"バージョンのダウンロード".as_bytes(),
b"</b>",
]
.concat();
x2(&pattern, &input, 0, 44);
}
#[test]
fn japanese_version_download_dot() {
let pattern = [
b".<b>" as &[u8],
"バージョンのダウンロード".as_bytes(),
b"<\\/b>",
]
.concat();
let input = [
b"a<b>" as &[u8],
"バージョンのダウンロード".as_bytes(),
b"</b>",
]
.concat();
x2(&pattern, &input, 0, 44);
}
#[test]
fn japanese_optional_newline_end() {
x2(b"\\n?\\z", "こんにちは".as_bytes(), 15, 15);
}
#[test]
fn japanese_multiline_dotstar() {
x2(b"(?m).*", "青赤黄".as_bytes(), 0, 9);
}
#[test]
fn japanese_multiline_dotstar_a() {
let input = ["青赤黄".as_bytes(), b"a"].concat();
x2(b"(?m).*a", &input, 0, 10);
}
#[test]
fn unicode_prop_hiragana_match() {
x2("\\p{Hiragana}".as_bytes(), "ぴ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_not_hiragana_no_match() {
n("\\P{Hiragana}".as_bytes(), "ぴ".as_bytes());
}
#[test]
fn unicode_prop_emoji_match() {
x2(b"\\p{Emoji}", b"\xe2\xad\x90", 0, 3);
}
#[test]
fn unicode_prop_not_emoji_match() {
x2(b"\\p{^Emoji}", b"\xef\xbc\x93", 0, 3);
}
#[test]
fn unicode_prop_extended_pictographic_match() {
x2(b"\\p{Extended_Pictographic}", b"\xe2\x9a\xa1", 0, 3);
}
#[test]
fn unicode_prop_extended_pictographic_no_match() {
n(b"\\p{Extended_Pictographic}", b"\xe3\x81\x82");
}
#[test]
fn unicode_prop_pc_soft_hyphen() {
x2(b"\\pC", b"\xc2\xad", 0, 2);
}
#[test]
fn unicode_prop_pl_ascii() {
x2(b"\\pL", b"U", 0, 1);
}
#[test]
fn unicode_prop_pm_combining_circle() {
x2(b"\\pM", b"\xe2\x83\x9d", 0, 3);
}
#[test]
fn unicode_prop_pn_plus() {
let input = [b"3" as &[u8], "\u{2164}".as_bytes()].concat();
x2(b"\\pN+", &input, 0, 4);
}
#[test]
fn unicode_prop_pp_plus() {
let input = ["\u{2020}".as_bytes(), "\u{2042}".as_bytes()].concat();
x2(b"\\pP+", &input, 0, 6);
}
#[test]
fn unicode_prop_ps_plus() {
let input = ["\u{20AC}".as_bytes(), "\u{20A4}".as_bytes()].concat();
x2(b"\\pS+", &input, 0, 6);
}
#[test]
fn unicode_prop_pz_space() {
x2(b"\\pZ+", b" ", 0, 1);
}
#[test]
fn unicode_prop_pl_no_match_at() {
n(b"\\pL", b"@");
}
#[test]
fn unicode_prop_pl_plus() {
x2(b"\\pL+", b"akZtE", 0, 5);
}
#[test]
fn unicode_prop_not_pl_plus() {
x2(b"\\PL+", b"1@=-%", 0, 5);
}
#[test]
fn unicode_prop_pl_in_class() {
x2(b"[\\pL]", b"s", 0, 1);
}
#[test]
fn unicode_prop_not_pl_in_negated_class() {
n(b"[^\\pL]", b"s");
}
#[test]
fn unicode_prop_not_pl_in_class_plus() {
x2(b"[\\PL]+", b"-3@", 0, 3);
}
#[test]
fn unicode_prop_word_match_ko() {
x2("\\p{Word}".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_not_word_no_match_ko() {
n("\\p{^Word}".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_word_in_class_match_ko() {
x2("[\\p{Word}]".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_not_word_in_class_no_match_ko() {
n("[\\p{^Word}]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_word_negated_class_no_match_ko() {
n("[^\\p{Word}]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_word_negated_class_match_ko() {
x2("[^\\p{^Word}]".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_not_word_and_ascii_negated_match_ko() {
x2(
"[^\\p{^Word}&&\\p{ASCII}]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_not_word_and_ascii_negated_match_a() {
x2("[^\\p{^Word}&&\\p{ASCII}]".as_bytes(), b"a", 0, 1);
}
#[test]
fn unicode_prop_not_word_and_ascii_negated_no_match_hash() {
n("[^\\p{^Word}&&\\p{ASCII}]".as_bytes(), b"#");
}
#[test]
fn unicode_prop_not_word_nested_and_ascii_match_ko() {
x2(
"[^[\\p{^Word}]&&[\\p{ASCII}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_ascii_and_not_word_negated_match_ko() {
x2(
"[^[\\p{ASCII}]&&[^\\p{Word}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_ascii_and_not_word_no_match_ko() {
n("[[\\p{ASCII}]&&[^\\p{Word}]]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_word_and_not_ascii_negated_match_ko() {
x2(
"[^[\\p{^Word}]&&[^\\p{ASCII}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_negated_hex_code_match_ko() {
x2("[^\\x{104a}]".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_not_word_and_not_hex_negated_match_ko() {
x2(
"[^\\p{^Word}&&[^\\x{104a}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_not_word_nested_and_not_hex_negated_match_ko() {
x2(
"[^[\\p{^Word}]&&[^\\x{104a}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_word_or_not_hex_negated_no_match_ko() {
n("[^\\p{Word}||[^\\x{104a}]]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_cntrl_match_ko() {
x2("\\p{^Cntrl}".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_cntrl_no_match_ko() {
n("\\p{Cntrl}".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_cntrl_in_class_match_ko() {
x2("[\\p{^Cntrl}]".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_cntrl_in_class_no_match_ko() {
n("[\\p{Cntrl}]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_cntrl_negated_class_no_match_ko() {
n("[^\\p{^Cntrl}]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_cntrl_negated_class_match_ko() {
x2("[^\\p{Cntrl}]".as_bytes(), "こ".as_bytes(), 0, 3);
}
#[test]
fn unicode_prop_cntrl_and_ascii_negated_match_ko() {
x2(
"[^\\p{Cntrl}&&\\p{ASCII}]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_cntrl_and_ascii_negated_match_a() {
x2("[^\\p{Cntrl}&&\\p{ASCII}]".as_bytes(), b"a", 0, 1);
}
#[test]
fn unicode_prop_not_cntrl_and_ascii_negated_no_match_hash() {
n("[^\\p{^Cntrl}&&\\p{ASCII}]".as_bytes(), b"#");
}
#[test]
fn unicode_prop_not_cntrl_nested_and_ascii_negated_match_ko() {
x2(
"[^[\\p{^Cntrl}]&&[\\p{ASCII}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_ascii_and_not_cntrl_negated_match_ko() {
x2(
"[^[\\p{ASCII}]&&[^\\p{Cntrl}]]".as_bytes(),
"こ".as_bytes(),
0,
3,
);
}
#[test]
fn unicode_prop_ascii_and_not_cntrl_no_match_ko() {
n("[[\\p{ASCII}]&&[^\\p{Cntrl}]]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_cntrl_and_not_ascii_negated_no_match_ko() {
n(
"[^[\\p{^Cntrl}]&&[^\\p{ASCII}]]".as_bytes(),
"こ".as_bytes(),
);
}
#[test]
fn unicode_prop_not_cntrl_and_not_hex_negated_no_match_ko() {
n("[^\\p{^Cntrl}&&[^\\x{104a}]]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_not_cntrl_nested_and_not_hex_negated_no_match_ko() {
n("[^[\\p{^Cntrl}]&&[^\\x{104a}]]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_cntrl_or_not_hex_negated_no_match_ko() {
n("[^\\p{Cntrl}||[^\\x{104a}]]".as_bytes(), "こ".as_bytes());
}
#[test]
fn unicode_prop_in_basic_latin() {
x2(b"\\p{InBasicLatin}", b"\x41", 0, 1);
}
#[test]
fn atomic_group_no_backtrack() {
n(b"(?>a|abd)c", b"abdc");
}
#[test]
fn atomic_group_longest_first() {
x2(b"(?>abd|a)c", b"abdc", 0, 4);
}
#[test]
fn alt_casefold_inline() {
x2(b"a|(?i)c", b"C", 0, 1);
}
#[test]
fn alt_casefold_c_or_a_match_c() {
x2(b"(?i)c|a", b"C", 0, 1);
}
#[test]
fn alt_casefold_c_or_a_match_a() {
x2(b"(?i)c|a", b"A", 0, 1);
}
#[test]
fn alt_casefold_scoped_b_or_c_match_b() {
x2(b"a(?i)b|c", b"aB", 0, 2);
}
#[test]
fn alt_casefold_scoped_b_or_c_match_c() {
x2(b"a(?i)b|c", b"aC", 0, 2);
}
#[test]
fn alt_casefold_scoped_no_match_ac() {
n(b"a(?i)b|c", b"AC");
}
#[test]
fn alt_casefold_group_no_leak() {
n(b"a(?:(?i)b)|c", b"aC");
}
#[test]
fn alt_casefold_modifier_group() {
x2(b"(?i:c)|a", b"C", 0, 1);
}
#[test]
fn alt_casefold_modifier_group_no_leak() {
n(b"(?i:c)|a", b"A");
}
#[test]
fn casefold_xa_after_star() {
x2(b"(?:X*)(?i:xa)", b"XXXa", 0, 4);
}
#[test]
fn capture_casefold_group() {
x3(b"((?i:abc))", b"AbC", 0, 3, 1);
}
#[test]
fn capture_casefold_backref() {
x2(b"(abc)(?i:\\1)", b"abcABC", 0, 6);
}
#[test]
fn capture_multiline_group() {
x3(b"((?m:a.c))", b"a\nc", 0, 3, 1);
}
#[test]
fn capture_casefold_abc_or_zzz() {
x3(b"(?i:(abc))|(zzz)", b"ABC", 0, 3, 1);
}
#[test]
fn backref_casefold_az() {
x2(b"((?i:az))\\1", b"AzAz", 0, 4);
}
#[test]
fn backref_casefold_az_no_match() {
n(b"((?i:az))\\1", b"Azaz");
}
#[test]
fn lookbehind_basic() {
x2(b"(?<=a)b", b"ab", 1, 2);
}
#[test]
fn lookbehind_basic_no_match() {
n(b"(?<=a)b", b"bb");
}
#[test]
fn lookbehind_alt() {
x2(b"(?<=a|b)b", b"bb", 1, 2);
}
#[test]
fn lookbehind_alt_bc_1() {
x2(b"(?<=a|bc)b", b"bcb", 2, 3);
}
#[test]
fn lookbehind_alt_bc_2() {
x2(b"(?<=a|bc)b", b"ab", 1, 2);
}
#[test]
fn lookbehind_alt_many() {
x2(b"(?<=a|bc||defghij|klmnopq|r)z", b"rz", 1, 2);
}
#[test]
fn lookbehind_capture() {
x3(b"(?<=(abc))d", b"abcd", 0, 3, 1);
}
#[test]
fn lookbehind_casefold() {
x2(b"(?<=(?i:abc))d", b"ABCd", 3, 4);
}
#[test]
fn lookbehind_caret_or_b() {
x2(b"(?<=^|b)c", b" cbc", 3, 4);
}
#[test]
fn lookbehind_a_or_caret_or_b() {
x2(b"(?<=a|^|b)c", b" cbc", 3, 4);
}
#[test]
fn lookbehind_a_or_caret_cap_or_b() {
x2(b"(?<=a|(^)|b)c", b" cbc", 3, 4);
}
#[test]
fn lookbehind_a_or_caret_cap_or_b_start() {
x2(b"(?<=a|(^)|b)c", b"cbc", 0, 1);
}
#[test]
fn neg_lookbehind_basic() {
x2(b"(?<!a)b", b"cb", 1, 2);
}
#[test]
fn neg_lookbehind_basic_no_match() {
n(b"(?<!a)b", b"ab");
}
#[test]
fn neg_lookbehind_alt() {
x2(b"(?<!a|bc)b", b"bbb", 0, 1);
}
#[test]
fn neg_lookbehind_alt_no_match() {
n(b"(?<!a|bc)z", b"bcz");
}
#[test]
fn neg_lookbehind_caret_or_b_no_match() {
n(b"(?<!^|b)c", b"cbc");
}
#[test]
fn neg_lookbehind_a_or_caret_or_b_no_match() {
n(b"(?<!a|^|b)c", b"cbc");
}
#[test]
fn neg_lookbehind_a_or_noncap_caret_or_b_no_match() {
n(b"(?<!a|(?:^)|b)c", b"cbc");
}
#[test]
fn neg_lookbehind_a_or_noncap_caret_or_b_match() {
x2(b"(?<!a|(?:^)|b)c", b" cbc", 1, 2);
}
#[test]
fn named_group_basic() {
x2(b"(?<name1>a)", b"a", 0, 1);
}
#[test]
fn named_group_backref() {
x2(b"(?<name_2>ab)\\g<name_2>", b"abab", 0, 4);
}
#[test]
fn named_group_backref_k() {
x2(b"(?<name_3>.zv.)\\k<name_3>", b"azvbazvb", 0, 8);
}
#[test]
fn recursive_g1() {
x2(b"(a)\\g<1>", b"aa", 0, 2);
}
#[test]
fn recursive_lookbehind_named() {
x2(b"(?<=\\g<ab>)|-\\zEND (?<ab>XyZ)", b"XyZ", 3, 3);
}
#[test]
fn recursive_named_empty_or_a() {
x2(b"(?<n>|a\\g<n>)+", b"", 0, 0);
}
#[test]
fn recursive_parens() {
x2(b"(?<n>|\\(\\g<n>\\))+$", b"()(())", 0, 6);
}
#[test]
fn recursive_g_n_dot_zero() {
x3(b"\\g<n>(?<n>.){0}", b"X", 0, 1, 1);
}
#[test]
fn recursive_g_n_alt_df() {
x2(b"\\g<n>(abc|df(?<n>.YZ){2,8}){0}", b"XYZ", 0, 3);
}
#[test]
fn recursive_A_n_a_or_empty() {
x2(b"\\A(?<n>(a\\g<n>)|)\\z", b"aaaa", 0, 4);
}
#[test]
fn recursive_mutual() {
x2(
b"(?<n>|\\g<m>\\g<n>)\\z|\\zEND (?<m>a|(b)\\g<m>)",
b"bbbbabba",
0,
8,
);
}
#[test]
fn named_group_long_name() {
x2(
b"(?<name1240>\\w+\\sx)a+\\k<name1240>",
b" fg xaaaaaaaafg x",
2,
18,
);
}
#[test]
fn named_group_underscore_9() {
x3(b"(z)()()(?<_9>a)\\g<_9>", b"zaa", 2, 3, 1);
}
#[test]
fn named_group_underscore_backref() {
x2(b"(.)(((?<_>a)))\\k<_>", b"zaa", 0, 3);
}
#[test]
fn named_group_digit_or_word() {
x2(
b"((?<name1>\\d)|(?<name2>\\w))(\\k<name1>|\\k<name2>)",
b"ff",
0,
2,
);
}
#[test]
fn named_group_dup_empty() {
x2(b"(?:(?<x>)|(?<x>efg))\\k<x>", b"", 0, 0);
}
#[test]
fn named_group_dup_abc_efg() {
x2(b"(?:(?<x>abc)|(?<x>efg))\\k<x>", b"abcefgefg", 3, 9);
}
#[test]
fn named_group_dup_no_match() {
n(b"(?:(?<x>abc)|(?<x>efg))\\k<x>", b"abcefg");
}
#[test]
fn named_group_dup_x_xx() {
x2(b"(?<x>x)(?<x>xx)\\k<x>", b"xxxx", 0, 4);
}
#[test]
fn named_group_dup_x_xx_z() {
x2(b"(?<x>x)(?<x>xx)\\k<x>", b"xxxxz", 0, 4);
}
#[test]
fn named_group_14_dup_pyumpyum() {
x2(b"(?:(?<n1>.)|(?<n1>..)|(?<n1>...)|(?<n1>....)|(?<n1>.....)|(?<n1>......)|(?<n1>.......)|(?<n1>........)|(?<n1>.........)|(?<n1>..........)|(?<n1>...........)|(?<n1>............)|(?<n1>.............)|(?<n1>..............))\\k<n1>$", b"a-pyumpyum", 2, 10);
}
#[test]
fn named_group_14_dup_capture_14() {
x3(b"(?:(?<n1>.)|(?<n1>..)|(?<n1>...)|(?<n1>....)|(?<n1>.....)|(?<n1>......)|(?<n1>.......)|(?<n1>........)|(?<n1>.........)|(?<n1>..........)|(?<n1>...........)|(?<n1>............)|(?<n1>.............)|(?<n1>..............))\\k<n1>$", b"xxxxabcdefghijklmnabcdefghijklmn", 4, 18, 14);
}
#[test]
fn named_group_16_aaa() {
x3(b"(?<name1>)(?<name2>)(?<name3>)(?<name4>)(?<name5>)(?<name6>)(?<name7>)(?<name8>)(?<name9>)(?<name10>)(?<name11>)(?<name12>)(?<name13>)(?<name14>)(?<name15>)(?<name16>aaa)(?<name17>)$", b"aaa", 0, 3, 16);
}
#[test]
fn recursive_foo_parens() {
x2(b"(?<foo>a|\\(\\g<foo>\\))", b"a", 0, 1);
}
#[test]
fn recursive_foo_nested_parens() {
x2(b"(?<foo>a|\\(\\g<foo>\\))", b"((((((a))))))", 0, 13);
}
#[test]
fn recursive_foo_nested_parens_capture() {
x3(b"(?<foo>a|\\(\\g<foo>\\))", b"((((((((a))))))))", 0, 17, 1);
}
#[test]
fn recursive_bar_abc_dollar() {
x2(b"\\g<bar>|\\zEND(?<bar>.*abc$)", b"abcxxxabc", 0, 9);
}
#[test]
fn recursive_g1_bac() {
x2(b"\\g<1>|\\zEND(.a.)", b"bac", 0, 3);
}
#[test]
fn recursive_g_A_mutual_capture() {
x3(b"\\g<_A>\\g<_A>|\\zEND(.a.)(?<_A>.b.)", b"xbxyby", 3, 6, 1);
}
#[test]
fn recursive_mutual_pan_pon() {
x2(
b"\\A(?:\\g<pon>|\\g<pan>|\\zEND (?<pan>a|c\\g<pon>c)(?<pon>b|d\\g<pan>d))$",
b"cdcbcdc",
0,
7,
);
}
#[test]
fn recursive_A_n_or_a_gm() {
x2(b"\\A(?<n>|a\\g<m>)\\z|\\zEND (?<m>\\g<n>)", b"aaaa", 0, 4);
}
#[test]
fn recursive_n_3_5_interval() {
x2(b"(?<n>(a|b\\g<n>c){3,5})", b"baaaaca", 1, 5);
}
#[test]
fn recursive_n_3_5_interval_long() {
x2(b"(?<n>(a|b\\g<n>c){3,5})", b"baaaacaaaaa", 0, 10);
}
#[test]
fn recursive_possessive_parens() {
x2(b"(?<pare>\\(([^\\(\\)]++|\\g<pare>)*+\\))", b"((a))", 0, 5);
}
#[test]
fn backref_or_empty_capture_star() {
x3(b"(?:\\1a|())*", b"a", 0, 0, 1);
}
#[test]
fn dotstar_star_x() {
x2(b"x((.)*)*x", b"0x1x2x3", 1, 6);
}
#[test]
fn dotstar_star_x_casefold_backref() {
x2(b"x((.)*)*x(?i:\\1)\\Z", b"0x1x2x1X2", 1, 9);
}
#[test]
fn multi_empty_capture_star_backref() {
x2(b"(?:()|()|()|()|()|())*\\2\\5", b"", 0, 0);
}
#[test]
fn multi_empty_capture_star_backref_b() {
x2(b"(?:()|()|()|(x)|()|())*\\2b\\5", b"b", 0, 1);
}
#[test]
fn char_class_0_9_dash_a() {
x2(b"[0-9-a]", b"-", 0, 1);
}
#[test]
fn char_class_0_9_dash_a_no_match() {
n(b"[0-9-a]", b":");
}
#[test]
fn recursive_parens_pr43() {
x3(b"(\\(((?:[^(]|\\g<1>)*)\\))", b"(abc)(abc)", 1, 4, 2);
}
#[test]
fn octal_escape_o101() {
x2(b"\\o{101}", b"A", 0, 1);
}
#[test]
fn recursive_backref_level_k1p3() {
x2(b"\\A(a|b\\g<1>c)\\k<1+3>\\z", b"bbacca", 0, 6);
}
#[test]
fn recursive_backref_level_k1p3_no_match() {
n(b"\\A(a|b\\g<1>c)\\k<1+3>\\z", b"bbaccb");
}
#[test]
fn recursive_casefold_backref_level() {
x2(b"(?i)\\A(a|b\\g<1>c)\\k<1+2>\\z", b"bBACcbac", 0, 8);
}
#[test]
fn casefold_named_dup_backref() {
x2(b"(?i)(?<X>aa)|(?<X>bb)\\k<X>", b"BBbb", 0, 4);
}
#[test]
fn relative_positive_backref() {
x2(b"(?:\\k'+1'B|(A)C)*", b"ACAB", 0, 4);
}
#[test]
fn relative_positive_call() {
x2(b"\\g<+2>(abc)(ABC){0}", b"ABCabc", 0, 6);
}
#[test]
fn recursive_self_call_g0() {
x2(b"A\\g'0'|B()", b"AAAAB", 0, 5);
}
#[test]
fn recursive_self_call_g0_capture() {
x3(b"(A\\g'0')|B", b"AAAAB", 0, 5, 1);
}
#[test]
fn conditional_yes_only() {
x2(b"(a*)(?(1))aa", b"aaaaa", 0, 5);
}
#[test]
fn conditional_negative_ref() {
x2(b"(a*)(?(-1))aa", b"aaaaa", 0, 5);
}
#[test]
fn conditional_named_ref() {
x2(b"(?<name>aaa)(?('name'))aa", b"aaaaa", 0, 5);
}
#[test]
fn conditional_yes_no() {
x2(b"(a)(?(1)aa|bb)a", b"aaaaa", 0, 4);
}
#[test]
fn conditional_named_yes_no() {
x2(b"(?:aa|())(?(<1>)aa|bb)a", b"aabba", 0, 5);
}
#[test]
fn conditional_named_yes_no_cc() {
x2(b"(?:aa|())(?('1')aa|bb|cc)a", b"aacca", 0, 5);
}
#[test]
fn conditional_capture_group() {
x3(b"(a*)(?(1)aa|a)b", b"aaab", 0, 1, 1);
}
#[test]
fn conditional_no_match() {
n(b"(a)(?(1)a|b)c", b"abc");
}
#[test]
fn conditional_empty_yes() {
x2(b"(a)(?(1)|)c", b"ac", 0, 2);
}
#[test]
fn conditional_empty_cond_no_match() {
n(b"(?()aaa|bbb)", b"bbb");
}
#[test]
fn conditional_plus_zero() {
x2(b"(a)(?(1+0)b|c)d", b"abd", 0, 3);
}
#[test]
fn conditional_named_alt_ace() {
x2(b"(?:(?'name'a)|(?'name'b))(?('name')c|d)e", b"ace", 0, 3);
}
#[test]
fn conditional_named_alt_bce() {
x2(b"(?:(?'name'a)|(?'name'b))(?('name')c|d)e", b"bce", 0, 3);
}
#[test]
fn empty_cap_star_backref_1() {
x2(b"(?:()|())*\\1", b"abc", 0, 0);
}
#[test]
fn empty_cap_star_backref_2() {
x2(b"(?:()|())*\\2", b"abc", 0, 0);
}
#[test]
fn triple_empty_cap_star_backref() {
x2(b"(?:()|()|())*\\3\\1", b"abc", 0, 0);
}
#[test]
fn recursive_empty_or_a_g1() {
x2(b"(|(?:a(?:\\g'1')*))b|", b"abc", 0, 2);
}
#[test]
fn multi_alt_lazy_repeat_z() {
x2(b"(abc|def|ghi|jkl|mno|pqr|stu){0,10}?\\z", b"admno", 2, 5);
}
#[test]
fn nested_alt_lazy_repeat_z() {
x2(
b"(abc|(def|ghi|jkl|mno|pqr){0,7}?){5}\\z",
b"adpqrpqrpqr",
2,
11,
);
}
#[test]
fn capture_noncap_a_opt_plus_coverage() {
x2(b"((?:a(?:b|c|d|e|f|g|h|i|j|k|l|m|n))+)?", b"abacadae", 0, 8);
}
#[test]
fn capture_noncap_a_lazyplus_z() {
x2(
b"((?:a(?:b|c|d|e|f|g|h|i|j|k|l|m|n))+?)?z",
b"abacadaez",
0,
9,
);
}
#[test]
fn cap_a_or_b_lazyq_opt_z() {
x2(b"\\A((a|b)??)?z", b"bz", 0, 2);
}
#[test]
fn cap_named_subroutine_zero() {
x2(b"((?<x>abc){0}a\\g<x>d)+", b"aabcd", 0, 5);
}
#[test]
fn conditional_abc_coverage() {
x2(b"((?(abc)true|false))+", b"false", 0, 5);
}
#[test]
fn casefold_group_d_plus() {
x2(b"((?i:abc)d)+", b"abcdABCd", 0, 8);
}
#[test]
fn neg_lookbehind_def_coverage() {
x2(b"((?<!abc)def)+", b"bcdef", 2, 5);
}
#[test]
fn word_boundary_capture_plus() {
x2(b"(\\ba)+", b"aaa", 0, 1);
}
#[test]
fn conditional_named_coverage() {
x2(b"()(?<x>ab)(?(<x>)a|b)", b"aba", 0, 3);
}
#[test]
fn lookbehind_dot_coverage() {
x2(b"(?<=a.b)c", b"azbc", 3, 4);
}
#[test]
fn lookbehind_long_repeat_no_match() {
n(b"(?<=(?:abcde){30})z", b"abc");
}
#[test]
fn lookbehind_conditional_coverage() {
x2(b"(?<=(?(a)a|bb))z", b"aaz", 2, 3);
}
#[test]
fn lookbehind_nested_coverage() {
x2(b"(?<=ab(?<=ab))", b"ab", 2, 2);
}
#[test]
fn named_dup_backref_plus_coverage() {
x2(b"(?<x>a)(?<x>b)(\\k<x>)+", b"abbaab", 0, 6);
}
#[test]
fn conditional_backref_match_coverage() {
x2(b"((?(a)b|c))(\\1)", b"abab", 0, 4);
}
#[test]
fn recursive_dollar_or_b_coverage() {
x2(b"(?<x>$|b\\g<x>)", b"bbb", 0, 3);
}
#[test]
fn recursive_conditional_cccb_coverage() {
x2(b"(?<x>(?(a)a|b)|c\\g<x>)", b"cccb", 0, 4);
}
#[test]
fn conditional_star_plus_coverage() {
x2(b"(a)(?(1)a*|b*)+", b"aaaa", 0, 4);
}
#[test]
fn nested_cc_intersection_coverage() {
x2(b"[[^abc]&&cde]*", b"de", 0, 2);
}
#[test]
fn conditional_lookbehind_Q_no_match() {
n(b"(Q)|(?<=a|(?(1))|b)c", b"czc");
}
#[test]
fn conditional_lookbehind_Q_match() {
x2(b"(Q)(?<=a|(?(1))|b)c", b"cQc", 1, 3);
}
#[test]
fn hex_digit_class() {
x2(b"\\h", b"5", 0, 1);
}
#[test]
fn non_hex_digit_class() {
x2(b"\\H", b"z", 0, 1);
}
#[test]
fn hex_digit_in_cc() {
x2(b"[\\h]", b"5", 0, 1);
}
#[test]
fn non_hex_digit_in_cc() {
x2(b"[\\H]", b"z", 0, 1);
}
#[test]
fn octal_in_cc() {
x2(b"[\\o{101}]", b"A", 0, 1);
}
#[test]
fn unicode_in_cc() {
x2(b"[\\u0041]", b"A", 0, 1);
}
fn e(pattern: &[u8], input: &[u8], expected_error: i32) {
let result = onig_new(
pattern,
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
);
match result {
Err(code) => {
assert_eq!(
code.code(),
expected_error,
"e: expected error {} for {:?} against {:?}, got error {}",
expected_error,
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
code.code()
);
}
Ok(reg) => {
let (result, _) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(
result,
expected_error,
"e: expected error {} for {:?} against {:?}, but got result {}",
expected_error,
std::str::from_utf8(pattern).unwrap_or("<invalid>"),
std::str::from_utf8(input).unwrap_or("<invalid>"),
result
);
}
}
}
#[test]
fn lookbehind_backref_a_dot_c_or_def() {
x2(b"(a.c|def)(.{4})(?<=\\1)", b"abcdabc", 0, 7);
}
#[test]
fn lookbehind_backref_a_dot_c_or_de() {
x2(b"(a.c|de)(.{4})(?<=\\1)", b"abcdabc", 0, 7);
}
#[test]
fn lookbehind_backref_a_dot_c_or_def_with_d_e() {
x2(b"(a.c|def)(.{5})(?<=d\\1e)", b"abcdabce", 0, 8);
}
#[test]
fn lookbehind_named_backref_k1() {
x2(b"(a.c|.)d(?<=\\k<1>d)", b"zzzzzabcdabc", 5, 9);
}
#[test]
fn lookbehind_az_star() {
x2(b"(?<=az*)abc", b"azzzzzzzzzzabcdabcabc", 11, 14);
}
#[test]
fn lookbehind_alt_variable_lengths() {
x2(b"(?<=ab|abc|abcd)ef", b"abcdef", 4, 6);
}
#[test]
fn lookbehind_alt_with_plus() {
x2(b"(?<=ta+|tb+|tc+|td+)zz", b"tcccccccccczz", 11, 13);
}
#[test]
fn lookbehind_alt_dot_quantified_1() {
x2(b"(?<=t.{7}|t.{5}|t.{2}|t.)zz", b"tczz", 2, 4);
}
#[test]
fn lookbehind_alt_dot_quantified_2() {
x2(b"(?<=t.{7}|t.{5}|t.{2})zz", b"tczzzz", 3, 5);
}
#[test]
fn lookbehind_alt_dot_quantified_3() {
x2(b"(?<=t.{7}|t.{5}|t.{3})zz", b"tczzazzbzz", 8, 10);
}
#[test]
fn lookbehind_alt_dot_quantified_nomatch() {
n(b"(?<=t.{7}|t.{5}|t.{3})zz", b"tczzazzbczz");
}
#[test]
fn lookbehind_capture_alt_lengths() {
x2(b"(?<=(ab|abc|abcd))ef", b"abcdef", 4, 6);
}
#[test]
fn lookbehind_capture_alt_plus() {
x2(b"(?<=(ta+|tb+|tc+|td+))zz", b"tcccccccccczz", 11, 13);
}
#[test]
fn lookbehind_capture_dot_quantified_1() {
x2(b"(?<=(t.{7}|t.{5}|t.{2}|t.))zz", b"tczz", 2, 4);
}
#[test]
fn lookbehind_capture_dot_quantified_2() {
x2(b"(?<=(t.{7}|t.{5}|t.{2}))zz", b"tczzzz", 3, 5);
}
#[test]
fn lookbehind_capture_dot_quantified_3() {
x2(b"(?<=(t.{7}|t.{5}|t.{3}))zz", b"tczzazzbzz", 8, 10);
}
#[test]
fn lookbehind_capture_dot_quantified_nomatch() {
n(b"(?<=(t.{7}|t.{5}|t.{3}))zz", b"tczzazzbczz");
}
#[test]
fn lookbehind_backref_variable_repeat() {
x2(b"(.{1,4})(.{1,4})(?<=\\2\\1)", b"abaaba", 0, 6);
}
#[test]
fn lookbehind_backref_variable_repeat_2() {
x2(b"(.{1,4})(.{1,4})(?<=\\2\\1)", b"ababab", 0, 6);
}
#[test]
fn lookbehind_backref_variable_repeat_nomatch() {
n(b"(.{1,4})(.{1,4})(?<=\\2\\1)", b"abcdabce");
}
#[test]
fn lookbehind_backref_variable_repeat_partial() {
x2(b"(.{1,4})(.{1,4})(?<=\\2\\1)", b"abcdabceabce", 4, 12);
}
#[test]
fn lookbehind_fixed_a() {
x2(b"(?<=a)", b"a", 1, 1);
}
#[test]
fn lookbehind_a_dot_star_w() {
x2(b"(?<=a.*\\w)z", b"abbbz", 4, 5);
}
#[test]
fn lookbehind_a_dot_star_w_nomatch() {
n(b"(?<=a.*\\w)z", b"abb z");
}
#[test]
fn lookbehind_a_dot_star_W() {
x2(b"(?<=a.*\\W)z", b"abb z", 4, 5);
}
#[test]
fn lookbehind_a_dot_star_b() {
x2(b"(?<=a.*\\b)z", b"abb z", 4, 5);
}
#[test]
fn lookbehind_atomic_group() {
x2(b"(?<=(?>abc))", b"abc", 3, 3);
}
#[test]
fn lookbehind_with_grapheme_cluster() {
x2(b"(?<=a\\Xz)", b"abz", 3, 3);
}
#[test]
fn lookbehind_anchor_a_star_nomatch() {
n(b"(?<=^a*)bc", b"zabc");
}
#[test]
fn lookbehind_a_star_word_boundary_nomatch() {
n(b"(?<=a*\\b)b", b"abc");
}
#[test]
fn lookbehind_a_plus_dot_star_cc() {
x2(b"(?<=a+.*[efg])z", b"abcdfz", 5, 6);
}
#[test]
fn lookbehind_a_plus_dot_star_cc_2() {
x2(b"(?<=a+.*[efg])z", b"abcdfgz", 6, 7);
}
#[test]
fn lookbehind_a_plus_dot_star_cc_nomatch() {
n(b"(?<=a+.*[efg])z", b"bcdfz");
}
#[test]
fn lookbehind_a_star_dot_star_cc() {
x2(b"(?<=a*.*[efg])z", b"bcdfz", 4, 5);
}
#[test]
fn lookbehind_a_plus_dot_star_cc_nomatch_2() {
n(b"(?<=a+.*[efg])z", b"abcdz");
}
#[test]
fn lookbehind_alt_v_t_a_plus() {
x2(b"(?<=v|t|a+.*[efg])z", b"abcdfz", 5, 6);
}
#[test]
fn lookbehind_alt_v_t_anchor_a_plus() {
x2(b"(?<=v|t|^a+.*[efg])z", b"abcdfz", 5, 6);
}
#[test]
fn lookbehind_anchor_group_alt() {
x2(b"(?<=^(?:v|t|a+.*[efg]))z", b"abcdfz", 5, 6);
}
#[test]
fn lookbehind_alt_v_anchor_t_a_plus() {
x2(b"(?<=v|^t|a+.*[efg])z", b"uabcdfz", 6, 7);
}
#[test]
fn lookbehind_shortest_priority_nomatch() {
n(b"^..(?<=(a{,2}))\\1z", b"aaaaz");
}
#[test]
fn lookbehind_shortest_priority_match() {
x2(b"^..(?<=(a{,2}))\\1z", b"aaz", 0, 3);
}
#[test]
fn lookbehind_absent_function_error_1() {
e(
b"(?<=(?~|zoo)a.*z)",
b"abcdefz",
ONIGERR_INVALID_LOOK_BEHIND_PATTERN,
);
}
#[test]
fn lookbehind_absent_function_error_2() {
e(
b"(?<=(?~|)a.*z)",
b"abcdefz",
ONIGERR_INVALID_LOOK_BEHIND_PATTERN,
);
}
#[test]
fn lookbehind_absent_function_error_3() {
e(
b"(a(?~|boo)z){0}(?<=\\g<1>)",
b"abcdefz",
ONIGERR_INVALID_LOOK_BEHIND_PATTERN,
);
}
#[test]
fn lookbehind_nested_or_empty_173() {
x2(b"(?<=(?<= )| )", b"abcde fg", 6, 6);
}
#[test]
fn lookbehind_complex_173() {
x2(
b"(?<=D|)(?<=@!nnnnnnnnnIIIIn;{1}D?()|<x@x*xxxD|)(?<=@xxx|xxxxx\\g<1>;{1}x)",
b"(?<=D|)(?<=@!nnnnnnnnnIIIIn;{1}D?()|<x@x*xxxD|)(?<=@xxx|xxxxx\\g<1>;{1}x)",
55,
55,
);
}
#[test]
fn lookbehind_reduced_173() {
x2(b"(?<=;()|)\\g<1>", b"", 0, 0);
}
#[test]
fn lookbehind_backref_k1_match() {
x2(b"(?<=;()|)\\k<1>", b";", 1, 1);
}
#[test]
fn lookbehind_empty_group_175() {
x2(b"(())\\g<3>{0}(?<=|())", b"abc", 0, 0);
}
#[test]
fn lookbehind_empty_capture_backref() {
x2(b"(?<=()|)\\1{0}", b"abc", 0, 0);
}
#[test]
fn lookbehind_neg_too_long_177() {
e(
b"(?<!xxxxxxxxxxxxxxxxxxxxxxx{32774}{65521}xxxxxxxx{65521}xxxxxxxxxxxxxx{32774}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)",
b"",
ONIGERR_INVALID_LOOK_BEHIND_PATTERN,
);
}
#[test]
fn lookbehind_nested_positive() {
x2(b"(?<=(?<=abc))def", b"abcdef", 3, 6);
}
#[test]
fn lookbehind_nested_positive_with_plus() {
x2(b"(?<=ab(?<=.+b)c)def", b"abcdef", 3, 6);
}
#[test]
fn lookbehind_nested_positive_nomatch() {
n(b"(?<=ab(?<=a+)c)def", b"abcdef");
}
#[test]
fn lookbehind_pos_then_neg_nomatch() {
n(b"(?<=abc)(?<!abc)def", b"abcdef");
}
#[test]
fn lookbehind_neg_then_pos_nomatch() {
n(b"(?<!ab.)(?<=.bc)def", b"abcdef");
}
#[test]
fn lookbehind_neg_then_pos_match() {
x2(b"(?<!ab.)(?<=.bc)def", b"abcdefcbcdef", 9, 12);
}
#[test]
fn lookbehind_neg_abc() {
n(b"(?<!abc)def", b"abcdef");
}
#[test]
fn lookbehind_neg_alt_xxx_abc() {
n(b"(?<!xxx|abc)def", b"abcdef");
}
#[test]
fn lookbehind_neg_alt_xxxxx_abc() {
n(b"(?<!xxxxx|abc)def", b"abcdef");
}
#[test]
fn lookbehind_neg_alt_xxxxx_abc_2() {
n(b"(?<!xxxxx|abc)def", b"xxxxxxdef");
}
#[test]
fn lookbehind_neg_alt_x_plus_abc() {
n(b"(?<!x+|abc)def", b"abcdef");
}
#[test]
fn lookbehind_neg_alt_x_plus_abc_2() {
n(b"(?<!x+|abc)def", b"xxxxxxxxxdef");
}
#[test]
fn lookbehind_neg_alt_x_plus_abc_match() {
x2(b"(?<!x+|abc)def", b"xxxxxxxxzdef", 9, 12);
}
#[test]
fn lookbehind_neg_a_dot_star_z_or_a() {
n(b"(?<!a.*z|a)def", b"axxxxxxxzdef");
}
#[test]
fn lookbehind_neg_a_dot_star_z_or_a_2() {
n(b"(?<!a.*z|a)def", b"bxxxxxxxadef");
}
#[test]
fn lookbehind_neg_a_dot_star_z_or_a_match() {
x2(b"(?<!a.*z|a)def", b"axxxxxxxzdefxxdef", 14, 17);
}
#[test]
fn lookbehind_neg_a_dot_star_z_or_a_match_2() {
x2(b"(?<!a.*z|a)def", b"bxxxxxxxadefxxdef", 14, 17);
}
#[test]
fn lookbehind_neg_a_dot_star_z_or_a_match_3() {
x2(b"(?<!a.*z|a)def", b"bxxxxxxxzdef", 9, 12);
}
#[test]
fn lookbehind_neg_x_plus_or_y_plus_digits() {
x2(b"(?<!x+|y+)\\d+", b"xxx572", 4, 6);
}
#[test]
fn lookbehind_neg_3_plus_or_4_plus_digits() {
x2(b"(?<!3+|4+)\\d+", b"33334444", 0, 8);
}
#[test]
fn lookbehind_neg_3_plus_or_4_plus_digits_nomatch() {
n(b".(?<!3+|4+)\\d+", b"33334444");
}
#[test]
fn lookbehind_neg_backref_repeat_nomatch() {
n(b"(.{,3})..(?<!\\1)", b"aaaaa");
}
#[test]
fn lookbehind_neg_backref_repeat_match() {
x2(b"(.{,3})..(?<!\\1)", b"abcde", 0, 5);
}
#[test]
fn lookbehind_neg_backref_repeat_match_2() {
x2(b"(.{,3})...(?<!\\1)", b"abcde", 0, 5);
}
#[test]
fn lookbehind_neg_backref_3_plus() {
x2(b"(a.c)(.{3,}?)(?<!\\1)", b"abcabcd", 0, 7);
}
#[test]
fn lookbehind_neg_backref_a_star() {
x2(b"(a*)(.{3,}?)(?<!\\1)", b"abcabcd", 0, 5);
}
#[test]
fn lookbehind_neg_conditional() {
x2(b"(?:(a.*b)|c.*d)(?<!(?(1))azzzb)", b"azzzzb", 0, 6);
}
#[test]
fn lookbehind_neg_conditional_nomatch() {
n(b"(?:(a.*b)|c.*d)(?<!(?(1))azzzb)", b"azzzb");
}
#[test]
fn lookbehind_neg_literal_with_meta() {
x2(b"<(?<!NT{+}abcd)", b"<(?<!NT{+}abcd)", 0, 1);
}
#[test]
fn lookbehind_neg_a_dot_star_c() {
x2(b"(?<!a.*c)def", b"abbbbdef", 5, 8);
}
#[test]
fn lookbehind_neg_a_dot_star_c_nomatch() {
n(b"(?<!a.*c)def", b"abbbcdef");
}
#[test]
fn lookbehind_neg_a_dot_star_X_word_boundary() {
x2(b"(?<!a.*X\\b)def", b"abbbbbXdef", 7, 10);
}
#[test]
fn lookbehind_neg_a_dot_star_X_nonword_boundary() {
n(b"(?<!a.*X\\B)def", b"abbbbbXdef");
}
#[test]
fn lookbehind_neg_a_dot_star_uvw_match() {
x2(b"(?<!a.*[uvw])def", b"abbbbbXdef", 7, 10);
}
#[test]
fn lookbehind_neg_a_dot_star_uvw_nomatch() {
n(b"(?<!a.*[uvw])def", b"abbbbbwdef");
}
#[test]
fn lookbehind_neg_ab_star_nonspace_plus() {
x2(b"(?<!ab*\\S+)def", b"abbbbb def", 9, 12);
}
#[test]
fn lookbehind_neg_a_dot_star_nonspace() {
x2(b"(?<!a.*\\S)def", b"abbbbb def", 7, 10);
}
#[test]
fn lookbehind_neg_ab_star_space_plus() {
n(b"(?<!ab*\\s+)def", b"abbbbb def");
}
#[test]
fn lookbehind_neg_ab_star_space_plus_nonword() {
x2(b"(?<!ab*\\s+\\B)def", b"abbbbb def", 9, 12);
}
#[test]
fn lookbehind_neg_alt_v_t_a_plus() {
n(b"(?<!v|t|a+.*[efg])z", b"abcdfz");
}
#[test]
fn lookbehind_neg_alt_v_t_a_plus_match() {
x2(b"(?<!v|t|a+.*[efg])z", b"abcdfzavzuz", 10, 11);
}
#[test]
fn lookbehind_neg_alt_v_t_anchor_a_plus() {
n(b"(?<!v|t|^a+.*[efg])z", b"abcdfz");
}
#[test]
fn lookbehind_neg_anchor_group_alt() {
n(b"(?<!^(?:v|t|a+.*[efg]))z", b"abcdfz");
}
#[test]
fn lookbehind_neg_v_anchor_t_a_plus() {
x2(b"(?<!v|^t|^a+.*[efg])z", b"uabcdfz", 6, 7);
}
#[test]
fn lookbehind_backref_circular_empty() {
n(b"(\\k<2>)|(?<=(\\k<1>))", b"");
}
#[test]
fn lookbehind_backref_circular_a() {
x2(b"(a|\\k<2>)|(?<=(\\k<1>))", b"a", 0, 1);
}
#[test]
fn lookbehind_backref_circular_ba() {
x2(b"(a|\\k<2>)|(?<=b(\\k<1>))", b"ba", 1, 2);
}
#[test]
fn lookbehind_neg_fixed_rma_x() {
n(b"(?<!RMA)X", b"123RMAX");
}
#[test]
fn lookbehind_pos_fixed_rma_x() {
x2(b"(?<=RMA)X", b"123RMAX", 6, 7);
}
#[test]
fn lookbehind_neg_fixed_rma_dollar() {
n(b"(?<!RMA)$", b"123RMA");
}
#[test]
fn lookbehind_pos_fixed_rma_dollar() {
x2(b"(?<=RMA)$", b"123RMA", 6, 6);
}
#[test]
fn lookbehind_neg_fixed_rma_big_z() {
n(b"(?<!RMA)\\Z", b"123RMA");
}
#[test]
fn lookbehind_pos_fixed_rma_big_z() {
x2(b"(?<=RMA)\\Z", b"123RMA", 6, 6);
}
#[test]
fn lookbehind_neg_fixed_rma_small_z() {
n(b"(?<!RMA)\\z", b"123RMA");
}
#[test]
fn lookbehind_pos_fixed_rma_small_z() {
x2(b"(?<=RMA)\\z", b"123RMA", 6, 6);
}
#[test]
fn conditional_recursive_1() {
x2(b"((?(a)\\g<1>|b))", b"aab", 0, 3);
}
#[test]
fn conditional_recursive_2() {
x2(b"((?(a)\\g<1>))", b"aab", 0, 2);
}
#[test]
fn conditional_recursive_empty() {
x2(b"((?(a)\\g<1>))", b"", 0, 0);
}
#[test]
fn conditional_recursive_alt() {
x2(b"(b(?(a)|\\g<1>))", b"bba", 0, 3);
}
#[test]
fn conditional_never_ending() {
e(b"(()(?(2)\\g<1>))", b"", ONIGERR_NEVER_ENDING_RECURSION);
}
#[test]
fn conditional_alt_bc() {
x2(b"(?(a)(?:b|c))", b"ac", 0, 2);
}
#[test]
fn conditional_alt_bc_empty() {
x2(b"(?(a)(?:b|c))", b"", 0, 0);
}
#[test]
fn conditional_b_empty() {
x2(b"(?(a)b)", b"", 0, 0);
}
#[test]
fn conditional_anchor_nomatch() {
n(b"^(?(a)b|c)", b"ac");
}
#[test]
fn case_insensitive_a_or_b() {
x2(b"(?i)a|b", b"B", 0, 1);
}
#[test]
fn case_insensitive_group_a_or_b_dot_no_c() {
n(b"((?i)a|b.)|c", b"C");
}
#[test]
fn case_insensitive_c_prefix_no_match() {
n(b"c(?i)a.|b.", b"Caz");
}
#[test]
fn case_insensitive_c_a_or_b() {
x2(b"c(?i)a|b", b"cB", 0, 2);
}
#[test]
fn case_insensitive_c_a_dot_or_b_dot() {
x2(b"c(?i)a.|b.", b"cBb", 0, 3);
}
#[test]
fn case_insensitive_st_lower() {
x2(b"(?i)st", b"st", 0, 2);
}
#[test]
fn case_insensitive_st_upper_s() {
x2(b"(?i)st", b"St", 0, 2);
}
#[test]
fn case_insensitive_st_upper_t() {
x2(b"(?i)st", b"sT", 0, 2);
}
#[test]
fn case_insensitive_st_long_s() {
x2(b"(?i)st", b"\xc5\xbft", 0, 3);
}
#[test]
fn case_insensitive_st_fb05() {
x2(b"(?i)st", b"\xef\xac\x85", 0, 3);
}
#[test]
fn case_insensitive_st_fb06() {
x2(b"(?i)st", b"\xef\xac\x86", 0, 3);
}
#[test]
fn case_insensitive_ast_upper_a() {
x2(b"(?i)ast", b"Ast", 0, 3);
}
#[test]
fn case_insensitive_ast_upper_as() {
x2(b"(?i)ast", b"ASt", 0, 3);
}
#[test]
fn case_insensitive_ast_upper_a_lower_s_upper_t() {
x2(b"(?i)ast", b"AsT", 0, 3);
}
#[test]
fn case_insensitive_ast_long_s() {
x2(b"(?i)ast", b"A\xc5\xbft", 0, 4);
}
#[test]
fn case_insensitive_ast_fb05() {
x2(b"(?i)ast", b"A\xef\xac\x85", 0, 4);
}
#[test]
fn case_insensitive_ast_fb06() {
x2(b"(?i)ast", b"A\xef\xac\x86", 0, 4);
}
#[test]
fn case_insensitive_stz_lower() {
x2(b"(?i)stZ", b"stz", 0, 3);
}
#[test]
fn case_insensitive_stz_upper_s() {
x2(b"(?i)stZ", b"Stz", 0, 3);
}
#[test]
fn case_insensitive_stz_upper_t() {
x2(b"(?i)stZ", b"sTz", 0, 3);
}
#[test]
fn case_insensitive_stz_long_s() {
x2(b"(?i)stZ", b"\xc5\xbftz", 0, 4);
}
#[test]
fn case_insensitive_stz_fb05() {
x2(b"(?i)stZ", b"\xef\xac\x85z", 0, 4);
}
#[test]
fn case_insensitive_stz_fb06() {
x2(b"(?i)stZ", b"\xef\xac\x86z", 0, 4);
}
#[test]
fn case_insensitive_bstz_lower() {
x2(b"(?i)BstZ", b"bstz", 0, 4);
}
#[test]
fn case_insensitive_bstz_upper_s() {
x2(b"(?i)BstZ", b"bStz", 0, 4);
}
#[test]
fn case_insensitive_bstz_upper_t() {
x2(b"(?i)BstZ", b"bsTz", 0, 4);
}
#[test]
fn case_insensitive_bstz_long_s() {
x2(b"(?i)BstZ", b"b\xc5\xbftz", 0, 5);
}
#[test]
fn case_insensitive_bstz_fb05() {
x2(b"(?i)BstZ", b"b\xef\xac\x85z", 0, 5);
}
#[test]
fn case_insensitive_bstz_fb06() {
x2(b"(?i)BstZ", b"b\xef\xac\x86z", 0, 5);
}
#[test]
fn case_insensitive_dot_star_st_end_long_s() {
x2(b"(?i).*st\\z", b"tttssss\xc5\xbft", 0, 10);
}
#[test]
fn case_insensitive_dot_star_st_end_fb05() {
x2(b"(?i).*st\\z", b"tttssss\xef\xac\x85", 0, 10);
}
#[test]
fn case_insensitive_dot_star_st_end_fb06() {
x2(b"(?i).*st\\z", b"tttssss\xef\xac\x86", 0, 10);
}
#[test]
fn case_insensitive_dot_star_a_st_i_end_long_s() {
x2(
b"(?i).*\xe3\x81\x82st\xe3\x81\x84\\z",
b"tttssss\xe3\x81\x82\xc5\xbft\xe3\x81\x84",
0,
16,
);
}
#[test]
fn case_insensitive_dot_star_a_st_i_end_fb05() {
x2(
b"(?i).*\xe3\x81\x82st\xe3\x81\x84\\z",
b"tttssss\xe3\x81\x82\xef\xac\x85\xe3\x81\x84",
0,
16,
);
}
#[test]
fn case_insensitive_dot_star_a_st_i_end_fb06() {
x2(
b"(?i).*\xe3\x81\x82st\xe3\x81\x84\\z",
b"tttssss\xe3\x81\x82\xef\xac\x86\xe3\x81\x84",
0,
16,
);
}
#[test]
fn case_insensitive_dot_star_long_s_t_end() {
x2(b"(?i).*\xc5\xbft\\z", b"tttssssst", 0, 9);
}
#[test]
fn case_insensitive_dot_star_fb05_end() {
x2(b"(?i).*\xef\xac\x85\\z", b"tttssss\xe3\x81\x82st", 0, 12);
}
#[test]
fn case_insensitive_dot_star_fb06_i_end() {
x2(
b"(?i).*\xef\xac\x86\xe3\x81\x84\\z",
b"tttssssst\xe3\x81\x84",
0,
12,
);
}
#[test]
fn case_insensitive_dot_star_fb05_end_self() {
x2(
b"(?i).*\xef\xac\x85\\z",
b"tttssss\xe3\x81\x82\xef\xac\x85",
0,
13,
);
}
#[test]
fn case_insensitive_ss_eszett() {
x2(b"(?i).*ss", b"abcdefghijklmnopqrstuvwxyz\xc3\x9f", 0, 28);
}
#[test]
fn case_insensitive_ss_eszett_dot_star() {
x2(
b"(?i).*ss.*",
b"abcdefghijklmnopqrstuvwxyz\xc3\x9fxyz",
0,
31,
);
}
#[test]
fn case_insensitive_eszett_matches_ss() {
x2(b"(?i).*\xc3\x9f", b"abcdefghijklmnopqrstuvwxyzss", 0, 28);
}
#[test]
fn case_insensitive_dot_star_ss_upper() {
x2(b"(?i).*ss.*", b"abcdefghijklmnopqrstuvwxyzSSxyz", 0, 31);
}
#[test]
fn case_insensitive_ssv_eszett() {
x2(b"(?i)ssv", b"\xc3\x9fv", 0, 3);
}
#[test]
fn case_insensitive_lookbehind_ss_v() {
x2(b"(?i)(?<=ss)v", b"SSv", 2, 3);
}
#[test]
fn case_insensitive_lookbehind_eszett_v() {
x2(b"(?i)(?<=\xc3\x9f)v", b"\xc3\x9fv", 2, 3);
}
#[test]
fn case_insensitive_plus_isss_jcaron() {
x2(b"(?i).+Isss\xc7\xb0", b".+Isss\xc7\xb0", 0, 8);
}
#[test]
fn literal_plus_isss_jcaron() {
x2(b".+Isss\xc7\xb0", b".+Isss\xc7\xb0", 0, 8);
}
#[test]
fn case_insensitive_jcaron_self() {
x2(b"(?i)\xc7\xb0", b"\xc7\xb0", 0, 2);
}
#[test]
fn case_insensitive_jcaron_decomposed() {
x2(b"(?i)\xc7\xb0", b"j\xcc\x8c", 0, 3);
}
#[test]
fn case_insensitive_j_caron_composed() {
x2(b"(?i)j\xcc\x8c", b"\xc7\xb0", 0, 2);
}
#[test]
fn case_insensitive_5_jcaron_self() {
x2(b"(?i)5\xc7\xb0", b"5\xc7\xb0", 0, 3);
}
#[test]
fn case_insensitive_5_jcaron_decomposed() {
x2(b"(?i)5\xc7\xb0", b"5j\xcc\x8c", 0, 4);
}
#[test]
fn case_insensitive_5_j_caron_composed() {
x2(b"(?i)5j\xcc\x8c", b"5\xc7\xb0", 0, 3);
}
#[test]
fn case_insensitive_jcaron_v() {
x2(b"(?i)\xc7\xb0v", b"\xc7\xb0V", 0, 3);
}
#[test]
fn case_insensitive_jcaron_v_decomposed() {
x2(b"(?i)\xc7\xb0v", b"j\xcc\x8cV", 0, 4);
}
#[test]
fn case_insensitive_j_caron_v_composed() {
x2(b"(?i)j\xcc\x8cv", b"\xc7\xb0V", 0, 3);
}
#[test]
fn case_insensitive_jcaron_cc_self() {
x2(b"(?i)[\xc7\xb0]", b"\xc7\xb0", 0, 2);
}
#[test]
fn case_insensitive_jcaron_cc_decomposed() {
x2(b"(?i)[\xc7\xb0]", b"j\xcc\x8c", 0, 3);
}
#[test]
fn case_insensitive_fb00_a() {
x2(b"(?i)\xef\xac\x80a", b"ffa", 0, 3);
}
#[test]
fn case_insensitive_ffz_fb00() {
x2(b"(?i)ffz", b"\xef\xac\x80z", 0, 4);
}
#[test]
fn case_insensitive_u2126_omega() {
x2(b"(?i)\xe2\x84\xa6", b"\xcf\x89", 0, 2);
}
#[test]
fn case_insensitive_a_u2126_omega() {
x2(b"a(?i)\xe2\x84\xa6", b"a\xcf\x89", 0, 3);
}
#[test]
fn case_insensitive_A_u2126_omega() {
x2(b"(?i)A\xe2\x84\xa6", b"a\xcf\x89", 0, 3);
}
#[test]
fn case_insensitive_A_u2126_equals() {
x2(b"(?i)A\xe2\x84\xa6=", b"a\xcf\x89=", 0, 4);
}
#[test]
fn case_insensitive_ss_group_long_s() {
x2(b"(?i:ss)=1234567890", b"\xc5\xbf\xc5\xbf=1234567890", 0, 15);
}
#[test]
fn hex_x_single_codepoint() {
x2(b"\\x{000A}", b"\x0a", 0, 1);
}
#[test]
fn hex_x_multi_codepoint_2() {
x2(b"\\x{000A 002f}", b"\x0a\x2f", 0, 2);
}
#[test]
fn hex_x_multi_codepoint_trailing_space() {
x2(b"\\x{000A 002f }", b"\x0a\x2f", 0, 2);
}
#[test]
fn hex_x_multi_codepoint_extra_spaces() {
x2(b"\\x{007C 001b}", b"\x7c\x1b", 0, 2);
}
#[test]
fn hex_x_multi_codepoint_15() {
x2(
b"\\x{1 2 3 4 5 6 7 8 9 a b c d e f}",
b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
0,
15,
);
}
#[test]
fn hex_x_multi_codepoint_with_literal() {
x2(b"a\\x{000A 002f}@", b"a\x0a\x2f@", 0, 4);
}
#[test]
fn hex_x_multi_codepoint_newline_sep() {
x2(b"a\\x{0060\n0063}@", b"a\x60\x63@", 0, 4);
}
#[test]
fn hex_x_multi_too_long_1() {
e(
b"\\x{00000001 000000012}",
b"",
ONIGERR_TOO_LONG_WIDE_CHAR_VALUE,
);
}
#[test]
fn hex_x_multi_too_long_2() {
e(
b"\\x{000A 00000002f}",
b"",
ONIGERR_TOO_LONG_WIDE_CHAR_VALUE,
);
}
#[test]
fn hex_x_multi_invalid_slash() {
e(b"\\x{000A 002f/", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_multi_invalid_space_slash() {
e(b"\\x{000A 002f /", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_unclosed_brace() {
e(b"\\x{000A", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_unclosed_brace_space() {
e(b"\\x{000A ", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_multi_unclosed() {
e(b"\\x{000A 002f ", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn octal_o_single() {
x2(b"\\o{102}", b"B", 0, 1);
}
#[test]
fn octal_o_multi_2() {
x2(b"\\o{102 103}", b"BC", 0, 2);
}
#[test]
fn octal_o_multi_pq() {
x2(b"\\o{0160 0000161}", b"pq", 0, 2);
}
#[test]
fn octal_o_multi_15() {
x2(
b"\\o{1 2 3 4 5 6 7 10 11 12 13 14 15 16 17}",
b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
0,
15,
);
}
#[test]
fn octal_o_multi_trailing_space() {
x2(b"\\o{0007 0010 }", b"\x07\x08", 0, 2);
}
#[test]
fn octal_o_invalid_slash() {
e(b"\\o{0000 0015/", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn octal_o_invalid_space_slash() {
e(b"\\o{0000 0015 /", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn octal_o_unclosed() {
e(b"\\o{0015", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn octal_o_unclosed_space() {
e(b"\\o{0015 ", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn octal_o_invalid_hex_digit() {
e(b"\\o{0007 002f}", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_single_in_cc() {
x2(b"[\\x{000A}]", b"\x0a", 0, 1);
}
#[test]
fn hex_x_multi_in_cc_plus() {
x2(b"[\\x{000A 002f}]+", b"\x0a\x2f\x2e", 0, 2);
}
#[test]
fn hex_x_multi_in_cc_5_values() {
x2(
b"[\\x{01 0F 1A 2c 4B}]+",
b"\x20\x01\x0f\x1a\x2c\x4b\x1b",
1,
6,
);
}
#[test]
fn hex_x_multi_in_cc_with_range() {
x2(b"[\\x{0020 0024}-\\x{0026}]+", b"\x25\x24\x26\x23", 0, 3);
}
#[test]
fn hex_x_multi_in_cc_range_and_value() {
x2(
b"[\\x{0030}-\\x{0033 005a}]+",
b"\x30\x31\x32\x33\x5a\x1c",
0,
5,
);
}
#[test]
fn hex_x_in_cc_unclosed() {
e(b"[\\x{000A]", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_in_cc_unclosed_space() {
e(b"[\\x{000A ]", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_in_cc_unclosed_space_bracket() {
e(b"[\\x{000A }]", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn octal_o_single_in_cc() {
x2(b"[\\o{102}]", b"B", 0, 1);
}
#[test]
fn octal_o_multi_in_cc_star() {
x2(b"[\\o{102 103}]*", b"BC", 0, 2);
}
#[test]
fn octal_o_multi_in_cc_invalid() {
e(
b"[a\\o{002 003]bcde|zzz",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_range_syntax() {
x2(b"[\\x{0030-0039}]+", b"abc0123456789def", 3, 13);
}
#[test]
fn hex_x_range_syntax_spaces() {
x2(b"[\\x{0030 - 0039 }]+", b"abc0123456789def", 3, 13);
}
#[test]
fn hex_x_range_and_values() {
x2(b"[\\x{0030 - 0039 0063 0064}]+", b"abc0123456789def", 2, 14);
}
#[test]
fn hex_x_range_and_range() {
x2(b"[\\x{0030 - 0039 0063-0065}]+", b"acde019b", 1, 7);
}
#[test]
fn hex_x_range_invalid_double_range() {
e(
b"[\\x{0030 - 0039-0063 0064}]+",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_range_invalid_trailing_dash() {
e(b"[\\x{0030 - }]+", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_range_invalid_double_dash() {
e(
b"[\\x{0030 -- 0040}]+",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_range_invalid_double_dash_no_space() {
e(b"[\\x{0030--0040}]+", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn hex_x_range_invalid_dash_space_dash() {
e(
b"[\\x{0030 - - 0040}]+",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_range_invalid_value_trailing_dash() {
e(
b"[\\x{0030 0044 - }]+",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_range_invalid_mixed() {
e(
b"[a-\\x{0070 - 0039}]+",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_multi_in_range() {
x2(b"[a-\\x{0063 0071}]+", b"dabcqz", 1, 5);
}
#[test]
fn hex_x_dash_range_in_cc() {
x2(b"[-\\x{0063-0065}]+", b"ace-df", 1, 5);
}
#[test]
fn hex_x_mixed_range() {
x2(b"[\\x61-\\x{0063 0065}]+", b"abced", 0, 4);
}
#[test]
fn hex_x_mixed_range_invalid() {
e(
b"[\\x61-\\x{0063-0065}]+",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn hex_x_multi_with_literal_in_cc() {
x2(b"[t\\x{0063 0071}]+", b"tcqb", 0, 3);
}
#[test]
fn hex_x_multi_with_shorthand_in_cc() {
x2(b"[\\W\\x{0063 0071}]+", b"*cqa", 0, 3);
}
#[test]
fn true_anychar_recursive() {
x2(b"(\\O|(?=z\\g<2>*))(\\g<0>){0}", b"a", 0, 1);
}
#[test]
fn isolation_option_abc() {
x2(b"(?Ii)abc", b"abc", 0, 3);
}
#[test]
fn isolation_option_abc_upper() {
x2(b"(?Ii)abc", b"ABC", 0, 3);
}
#[test]
fn isolation_option_group() {
x2(b"(?Ii:abc)", b"abc", 0, 3);
}
#[test]
fn isolation_option_alt() {
x2(b"(?Ii)xyz|abc", b"aBc", 0, 3);
}
#[test]
fn isolation_option_group_alt() {
x2(b"(?Ii:zz|abc|AZ)", b"ABc", 0, 3);
}
#[test]
fn isolation_option_error_suffix() {
e(b"(?Ii:abc)d", b"abc", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_error_neg() {
e(b"(?-Ii:abc)", b"abc", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_neg_i() {
x2(b"(?I-i:abc)", b"abc", 0, 3);
}
#[test]
fn isolation_option_error_i_neg_I() {
e(b"(?i-I:abc)", b"abc", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn case_insensitive_kelvin_sign() {
x2(b"(?i)\xe2\x84\xaa", b"k", 0, 1);
}
#[test]
fn isolation_option_kelvin_no_match() {
n(b"(?Ii)\xe2\x84\xaa", b"k");
}
#[test]
fn isolation_option_error_in_capture() {
e(b"((?Ii)abc)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_in_noncapture() {
x2(b"(?:(?Ii)abc)", b"ABC", 0, 3);
}
#[test]
fn isolation_option_nested_noncapture() {
x2(b"(?:(?:(?Ii)abc))", b"ABC", 0, 3);
}
#[test]
fn isolation_option_error_after_x() {
e(b"x(?Ii)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_error_after_group() {
e(b"()(?Ii)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_error_after_noncapture() {
e(b"(?:)(?Ii)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_error_after_anchor() {
e(b"^(?Ii)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn isolation_option_dollar() {
x2(b"(?Ii)$", b"", 0, 0);
}
#[test]
fn isolation_option_alt_empty() {
x2(b"(?Ii)|", b"", 0, 0);
}
#[test]
fn isolation_option_error_double() {
e(b"(?Ii)|(?Ii)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn greedy_a_star() {
x2(b"a*", b"aabcaaa", 0, 2);
}
#[test]
fn longest_option_a_star() {
x2(b"(?L)a*", b"aabcaaa", 4, 7);
}
#[test]
fn longest_option_alt_quantifiers() {
x2(b"(?L)a{4}|a{3}|b*", b"baaaaabbb", 1, 5);
}
#[test]
fn longest_option_alt_quantifiers_2() {
x2(b"(?L)a{3}|a{4}|b*", b"baaaaabbb", 1, 5);
}
#[test]
fn longest_option_error_suffix() {
e(b"x(?L)xxxxx", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn longest_option_error_neg() {
e(b"(?-L)x", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn backref_group_1() {
x3(b"(..)\\1", b"abab", 0, 2, 1);
}
#[test]
fn no_numbered_backref_error() {
e(b"(?C)(..)\\1", b"abab", ONIGERR_INVALID_BACKREF);
}
#[test]
fn no_numbered_backref_error_neg() {
e(b"(?-C)", b"", ONIGERR_INVALID_GROUP_OPTION);
}
#[test]
fn no_numbered_backref_error_named() {
e(
b"(?C)(.)(.)(.)(?<name>.)\\1",
b"abcdd",
ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED,
);
}
#[test]
fn longest_option_recursive() {
x2(b"(?L)z|a\\g<0>a", b"aazaa", 0, 5);
}
#[test]
fn longest_option_recursive_case_insensitive() {
x2(b"(?Li)z|a\\g<0>a", b"aazAA", 0, 5);
}
#[test]
fn longest_option_group_recursive_case_insensitive() {
x2(b"(?Li:z|a\\g<0>a)", b"aazAA", 0, 5);
}
#[test]
fn longest_option_recursive_longest() {
x2(b"(?L)z|a\\g<0>a", b"aazaaaazaaaa", 3, 12);
}
#[test]
fn isolation_case_s_no_long_s() {
n(b"(?iI)s", b"\xc5\xbf");
}
#[test]
fn isolation_case_s_cc_no_long_s() {
n(b"(?iI)[s]", b"\xc5\xbf");
}
#[test]
fn isolation_case_s_group_no_long_s() {
n(b"(?iI:s)", b"\xc5\xbf");
}
#[test]
fn isolation_case_s_cc_group_no_long_s() {
n(b"(?iI:[s])", b"\xc5\xbf");
}
#[test]
fn isolation_case_word_class_long_s() {
x2(b"(?iI)(?:[[:word:]])", b"\xc5\xbf", 0, 2);
}
#[test]
fn isolation_case_W_word_class_no_long_s() {
n(b"(?iI)(?W:[[:word:]])", b"\xc5\xbf");
}
#[test]
fn isolation_case_W_w_no_long_s() {
n(b"(?iI)(?W:\\w)", b"\xc5\xbf");
}
#[test]
fn isolation_case_W_w_cc_no_long_s() {
n(b"(?iI)(?W:[\\w])", b"\xc5\xbf");
}
#[test]
fn isolation_case_W_p_word_no_long_s() {
n(b"(?iI)(?W:\\p{Word})", b"\xc5\xbf");
}
#[test]
fn isolation_case_W_p_word_cc_no_long_s() {
n(b"(?iI)(?W:[\\p{Word}])", b"\xc5\xbf");
}
#[test]
fn iw_word_class_long_s() {
x2(b"(?iW:[[:word:]])", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_p_word_cc_long_s() {
x2(b"(?iW:[\\p{Word}])", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_w_cc_long_s() {
x2(b"(?iW:[\\w])", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_p_word_no_long_s() {
n(b"(?iW:\\p{Word})", b"\xc5\xbf");
}
#[test]
fn iw_w_no_long_s() {
n(b"(?iW:\\w)", b"\xc5\xbf");
}
#[test]
fn case_insensitive_p_word_long_s() {
x2(b"(?i)\\p{Word}", b"\xc5\xbf", 0, 2);
}
#[test]
fn case_insensitive_w_long_s() {
x2(b"(?i)\\w", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_neg_word_class_long_s() {
x2(b"(?iW:[[:^word:]])", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_neg_p_word_cc_long_s() {
x2(b"(?iW:[\\P{Word}])", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_neg_w_cc_long_s() {
x2(b"(?iW:[\\W])", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_neg_p_word_long_s() {
x2(b"(?iW:\\P{Word})", b"\xc5\xbf", 0, 2);
}
#[test]
fn iw_neg_w_long_s() {
x2(b"(?iW:\\W)", b"\xc5\xbf", 0, 2);
}
#[test]
fn case_insensitive_neg_p_word_long_s() {
n(b"(?i)\\P{Word}", b"\xc5\xbf");
}
#[test]
fn case_insensitive_neg_w_long_s() {
n(b"(?i)\\W", b"\xc5\xbf");
}
#[test]
fn iw_neg_word_class_s() {
x2(b"(?iW:[[:^word:]])", b"s", 0, 1);
}
#[test]
fn iw_neg_p_word_cc_s() {
x2(b"(?iW:[\\P{Word}])", b"s", 0, 1);
}
#[test]
fn iw_neg_w_cc_s() {
x2(b"(?iW:[\\W])", b"s", 0, 1);
}
#[test]
fn iw_neg_p_word_s() {
n(b"(?iW:\\P{Word})", b"s");
}
#[test]
fn iw_neg_w_s() {
n(b"(?iW:\\W)", b"s");
}
#[test]
fn case_insensitive_neg_p_word_s() {
n(b"(?i)\\P{Word}", b"s");
}
#[test]
fn case_insensitive_neg_w_s() {
n(b"(?i)\\W", b"s");
}
#[test]
fn posix_punct_colon() {
x2(b"[[:punct:]]", b":", 0, 1);
}
#[test]
fn posix_punct_dollar() {
x2(b"[[:punct:]]", b"$", 0, 1);
}
#[test]
fn posix_punct_several() {
x2(b"[[:punct:]]+", b"$+<=>^`|~", 0, 9);
}
#[test]
fn posix_punct_not_alpha() {
n(b"[[:punct:]]", b"a");
}
#[test]
fn posix_punct_not_digit() {
n(b"[[:punct:]]", b"7");
}
#[test]
fn posix_punct_property() {
x2(b"\\p{PosixPunct}+", b"$\xc2\xa6", 0, 3);
}
#[test]
fn general_newline_dot_star() {
x2(b"\\A.*\\R", b"\n", 0, 1);
}
#[test]
fn true_anychar_star_newline() {
x2(b"\\A\\O*\\R", b"\n", 0, 1);
}
#[test]
fn newline_star_general_newline() {
x2(b"\\A\\n*\\R", b"\n", 0, 1);
}
#[test]
fn general_newline_star_general_newline() {
x2(b"\\A\\R*\\R", b"\n", 0, 1);
}
#[test]
fn literal_t_star_general_newline() {
x2(b"\\At*\\R", b"\n", 0, 1);
}
#[test]
fn dot_bounded_star_general_newline() {
x2(b"\\A.{0,99}\\R", b"\n", 0, 1);
}
#[test]
fn true_anychar_bounded_general_newline() {
x2(b"\\A\\O{0,99}\\R", b"\n", 0, 1);
}
#[test]
fn newline_bounded_general_newline() {
x2(b"\\A\\n{0,99}\\R", b"\n", 0, 1);
}
#[test]
fn general_newline_bounded_general_newline() {
x2(b"\\A\\R{0,99}\\R", b"\n", 0, 1);
}
#[test]
fn literal_t_bounded_general_newline() {
x2(b"\\At{0,99}\\R", b"\n", 0, 1);
}
#[test]
fn dot_star_newline() {
x2(b"\\A.*\\n", b"\n", 0, 1);
}
#[test]
fn dot_bounded_newline() {
x2(b"\\A.{0,99}\\n", b"\n", 0, 1);
}
#[test]
fn dot_star_true_anychar() {
x2(b"\\A.*\\O", b"\n", 0, 1);
}
#[test]
fn dot_bounded_true_anychar() {
x2(b"\\A.{0,99}\\O", b"\n", 0, 1);
}
#[test]
fn dot_star_whitespace() {
x2(b"\\A.*\\s", b"\n", 0, 1);
}
#[test]
fn dot_bounded_whitespace() {
x2(b"\\A.{0,99}\\s", b"\n", 0, 1);
}
#[test]
fn empty_loop_b_or_plus_d() {
n(b"a(b|)+d", b"abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcd");
}
#[test]
fn invalid_utf8_fd() {
e(b" \xfd", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn invalid_utf8_fc_in_pattern() {
e(
b"()0\\xfc00000\\xfc00000\\xfc00000\xfc",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn invalid_utf8_fa() {
e(b"000||0\xfa", b"0", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn invalid_utf8_f0_case_insensitive() {
e(
b"(?i)000000000000000000000\xf0",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn invalid_utf8_f5_backslash() {
e(b"0000\\\xf5", b"0", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn invalid_utf8_fd_case_insensitive() {
e(
b"(?i)FFF00000000000000000\xfd",
b"",
ONIGERR_INVALID_CODE_POINT_VALUE,
);
}
#[test]
fn issue_192_complex_lookbehind() {
n(
b"(?x)\n (?<!\\+\\+|--)(?<=[({\\[,?=>:*]|&&|\\|\\||\\?|\\*\\/|^await|[^\\._$[:alnum:]]await|^return|[^\\._$[:alnum:]]return|^default|[^\\._$[:alnum:]]default|^yield|[^\\._$[:alnum:]]yield|^)\\s*\n (?!<\\s*[_$[:alpha:]][_$[:alnum:]]*((\\s+extends\\s+[^=>])|,)) # look ahead is not type parameter of arrow\n (?=(<)\\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?<!\\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?<!\\.|-))(?=((<\\s*)|(\\s+))(?!\\?)|\\/?>))",
b" while (i < len && f(array[i]))",
);
}
#[test]
fn long_utf8_string_issue_221() {
x2(
b"aaaaaaaaaaaaaaaaaaaaaaa\xe3\x81\x82b",
b"aaaaaaaaaaaaaaaaaaaaaaa\xe3\x81\x82b",
0,
27,
);
}
#[test]
fn large_repeat_literal_nomatch() {
n(b"d{65538}+{61533} ", b"d{65538}+{61533} ");
}
#[test]
fn too_big_repeat_range_1() {
e(
b"x{55380}{77590}",
b"",
ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE,
);
}
#[test]
fn too_big_repeat_range_2() {
e(
b"(xyz){40000}{99999}(?<name>vv)",
b"",
ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE,
);
}
#[test]
fn too_big_repeat_range_3() {
e(
b"f{90000,90000}{80000,80000}",
b"",
ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE,
);
}
#[test]
fn large_repeat_range_nomatch() {
n(b"f{90000,90000}{80000,80001}", b"");
}
#[test]
fn unicode_property_common() {
x2(b"\\p{Common}", b"\xe3\x8b\xbf", 0, 3);
}
#[test]
fn unicode_property_enclosed_cjk() {
x2(
b"\\p{In_Enclosed_CJK_Letters_and_Months}",
b"\xe3\x8b\xbf",
0,
3,
);
}
#[test]
fn error_invalid_codepoint_7fffffff() {
e(b"\\x{7fffffff}", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_invalid_codepoint_7fffffff_cc() {
e(b"[\\x{7fffffff}]", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_invalid_u_short() {
e(b"\\u040", b"@", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_invalid_u_empty() {
e(b"\\u", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_never_ending_recursion() {
e(b"(?<abc>\\g<abc>)", b"zzzz", ONIGERR_NEVER_ENDING_RECURSION);
}
#[test]
fn error_undefined_callout() {
e(b"(*FOO)", b"abcdefg", ONIGERR_UNDEFINED_CALLOUT_NAME);
}
#[test]
fn error_target_repeat_not_specified_star() {
e(
b"*",
b"abc",
ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED,
);
}
#[test]
fn error_target_repeat_not_specified_pipe_star() {
e(
b"|*",
b"abc",
ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED,
);
}
#[test]
fn error_target_repeat_not_specified_option_star() {
e(
b"(?i)*",
b"abc",
ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED,
);
}
#[test]
fn error_target_repeat_not_specified_group_star() {
e(
b"(?:*)",
b"abc",
ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED,
);
}
#[test]
fn error_target_repeat_not_specified_m_group_star() {
e(
b"(?m:*)",
b"abc",
ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED,
);
}
#[test]
fn empty_noncapture_star() {
x2(b"(?:)*", b"abc", 0, 0);
}
#[test]
fn error_target_repeat_invalid_anchor() {
e(b"^*", b"abc", ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
}
#[test]
fn error_target_repeat_not_specified_pipe_question() {
e(
b"abc|?",
b"",
ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED,
);
}
#[test]
fn dollar_true_anychar() {
x2(b"$\\O", b"bb\n", 2, 3);
}
#[test]
fn error_posix_bracket_premature_end_1() {
e(b"[[:::]", b":[", ONIGERR_PREMATURE_END_OF_CHAR_CLASS);
}
#[test]
fn error_posix_bracket_premature_end_2() {
e(b"[[:\\]:]", b":]", ONIGERR_PREMATURE_END_OF_CHAR_CLASS);
}
#[test]
fn error_posix_bracket_premature_end_3() {
e(b"[[:\\[:]", b":[", ONIGERR_PREMATURE_END_OF_CHAR_CLASS);
}
#[test]
fn error_posix_bracket_premature_end_4() {
e(b"[[:\\]]", b":]", ONIGERR_PREMATURE_END_OF_CHAR_CLASS);
}
#[test]
fn error_posix_bracket_invalid_type_u() {
e(b"[[:u:]]", b"", ONIGERR_INVALID_POSIX_BRACKET_TYPE);
}
#[test]
fn error_posix_bracket_invalid_type_upp() {
e(b"[[:upp:]]", b"", ONIGERR_INVALID_POSIX_BRACKET_TYPE);
}
#[test]
fn error_posix_bracket_invalid_type_uppers() {
e(b"[[:uppers:]]", b"", ONIGERR_INVALID_POSIX_BRACKET_TYPE);
}
#[test]
fn absent_empty() {
x2(b"(?~)", b"", 0, 0);
}
#[test]
fn absent_empty_with_input() {
x2(b"(?~)", b"A", 0, 0);
}
#[test]
fn absent_ab() {
x2(b"(?~ab)", b"abc", 0, 0);
}
#[test]
fn absent_abc() {
x2(b"(?~abc)", b"abc", 0, 0);
}
#[test]
fn absent_abc_or_ab() {
x2(b"(?~abc|ab)", b"abc", 0, 0);
}
#[test]
fn absent_ab_or_abc() {
x2(b"(?~ab|abc)", b"abc", 0, 0);
}
#[test]
fn absent_a_dot_c() {
x2(b"(?~a.c)", b"abc", 0, 0);
}
#[test]
fn absent_a_dot_c_or_ab() {
x2(b"(?~a.c|ab)", b"abc", 0, 0);
}
#[test]
fn absent_ab_or_a_dot_c() {
x2(b"(?~ab|a.c)", b"abc", 0, 0);
}
#[test]
fn absent_after_aaaaa() {
x2(b"aaaaa(?~)", b"aaaaaaaaaa", 0, 5);
}
#[test]
fn absent_empty_alt_aaa() {
x2(b"(?~(?:|aaa))", b"aaa", 0, 0);
}
#[test]
fn absent_aaa_or_empty() {
x2(b"(?~aaa|)", b"aaa", 0, 0);
}
#[test]
fn absent_nested() {
x2(b"a(?~(?~)).", b"abcdefghijklmnopqrstuvwxyz", 0, 26);
}
#[test]
fn absent_c_comment() {
x2(b"/\\*(?~\\*/)\\*/", b"/* */ */", 0, 5);
}
#[test]
fn absent_word_plus_zzzzz() {
x2(b"(?~\\w+)zzzzz", b"zzzzz", 0, 5);
}
#[test]
fn absent_word_star_zzzzz() {
x2(b"(?~\\w*)zzzzz", b"zzzzz", 0, 5);
}
#[test]
fn absent_a_dot_c_or_b() {
x2(b"(?~A.C|B)", b"ABC", 0, 0);
}
#[test]
fn absent_xyz_or_abc_a_1() {
x2(b"(?~XYZ|ABC)a", b"ABCa", 1, 4);
}
#[test]
fn absent_xyz_or_abc_a_2() {
x2(b"(?~XYZ|ABC)a", b"aABCa", 0, 1);
}
#[test]
fn absent_html_tag() {
x2(b"<[^>]*>(?~[<>])</[^>]*>", b"<a>vvv</a> <b> </b>", 0, 10);
}
#[test]
fn absent_ab_multiline() {
x2(b"(?~ab)", b"ccc\ndab", 0, 5);
}
#[test]
fn absent_ab_multiline_m() {
x2(b"(?m:(?~ab))", b"ccc\ndab", 0, 5);
}
#[test]
fn absent_ab_multiline_neg_m() {
x2(b"(?-m:(?~ab))", b"ccc\ndab", 0, 5);
}
#[test]
fn absent_abc_xyz() {
x2(b"(?~abc)xyz", b"xyz012345678901234567890123456789abc", 0, 3);
}
#[test]
fn absent_expr_digits() {
x2(b"(?~|78|\\d*)", b"123456789", 0, 6);
}
#[test]
fn absent_expr_def() {
x2(b"(?~|def|(?:abc|de|f){0,100})", b"abcdedeabcfdefabc", 0, 11);
}
#[test]
fn absent_expr_ab_dot_star() {
x2(b"(?~|ab|.*)", b"ccc\nddd", 0, 3);
}
#[test]
fn absent_expr_ab_true_any_star() {
x2(b"(?~|ab|\\O*)", b"ccc\ndab", 0, 5);
}
#[test]
fn absent_expr_ab_true_any_2_10() {
x2(b"(?~|ab|\\O{2,10})", b"ccc\ndab", 0, 5);
}
#[test]
fn absent_expr_ab_true_any_1_10() {
x2(b"(?~|ab|\\O{1,10})", b"ab", 1, 2);
}
#[test]
fn absent_expr_ab_true_any_2_10_no_match() {
n(b"(?~|ab|\\O{2,10})", b"ab");
}
#[test]
fn absent_expr_abc_true_any_1_10() {
x2(b"(?~|abc|\\O{1,10})", b"abc", 1, 3);
}
#[test]
fn absent_expr_ab_true_any_5_10_or_abc() {
x2(b"(?~|ab|\\O{5,10})|abc", b"abc", 0, 3);
}
#[test]
fn absent_expr_ab_true_any_1_10_long() {
x2(b"(?~|ab|\\O{1,10})", b"cccccccccccab", 0, 10);
}
#[test]
fn absent_expr_aaa_empty() {
x2(b"(?~|aaa|)", b"aaa", 0, 0);
}
#[test]
fn absent_expr_empty_a_star() {
x2(b"(?~||a*)", b"aaaaaa", 0, 0);
}
#[test]
fn absent_expr_empty_a_star_lazy() {
x2(b"(?~||a*?)", b"aaaaaa", 0, 0);
}
#[test]
fn absent_expr_backref() {
x2(b"(a)(?~|b|\\1)", b"aaaaaa", 0, 2);
}
#[test]
fn absent_expr_backref_2() {
x2(b"(a)(?~|bb|(?:a\\1)*)", b"aaaaaa", 0, 5);
}
#[test]
fn absent_expr_backref_3() {
x2(b"(b|c)(?~|abac|(?:a\\1)*)", b"abababacabab", 1, 4);
}
#[test]
fn absent_expr_possessive_no_match() {
n(b"(?~|c|a*+)a", b"aaaaa");
}
#[test]
fn absent_expr_possessive_1() {
x2(b"(?~|aaaaa|a*+)", b"aaaaa", 0, 0);
}
#[test]
fn absent_expr_possessive_2() {
x2(b"(?~|aaaaaa|a*+)b", b"aaaaaab", 1, 7);
}
#[test]
fn absent_expr_atomic() {
x2(b"(?~|abcd|(?>))", b"zzzabcd", 0, 0);
}
#[test]
fn absent_expr_lazy() {
x2(b"(?~|abc|a*?)", b"aaaabc", 0, 0);
}
#[test]
fn absent_range_a_star() {
x2(b"(?~|abc)a*", b"aaaaaabc", 0, 5);
}
#[test]
fn absent_range_a_star_z() {
x2(b"(?~|abc)a*z|aaaaaabc", b"aaaaaabc", 0, 8);
}
#[test]
fn absent_range_aaaaaa() {
x2(b"(?~|aaaaaa)a*", b"aaaaaa", 0, 0);
}
#[test]
fn absent_range_abc_aaaa() {
x2(b"(?~|abc)aaaa|aaaabc", b"aaaabc", 0, 6);
}
#[test]
fn absent_range_atomic_aaaa() {
x2(b"(?>(?~|abc))aaaa|aaaabc", b"aaaabc", 0, 6);
}
#[test]
fn absent_range_empty() {
x2(b"(?~|)a", b"a", 0, 1);
}
#[test]
fn absent_range_a_no_match() {
n(b"(?~|a)a", b"a");
}
#[test]
fn absent_range_a_nested() {
x2(b"(?~|a)(?~|)a", b"a", 0, 1);
}
#[test]
fn absent_range_a_dot_star() {
x2(b"(?~|a).*(?~|)a", b"bbbbbbbbbbbbbbbbbbbba", 0, 21);
}
#[test]
fn absent_range_complex_1() {
x2(b"(?~|abc).*(xyz|pqr)(?~|)abc", b"aaaaxyzaaapqrabc", 0, 16);
}
#[test]
fn absent_range_complex_2() {
x2(
b"(?~|abc).*(xyz|pqr)(?~|)abc",
b"aaaaxyzaaaabcpqrabc",
11,
19,
);
}
#[test]
fn absent_range_complex_no_match() {
n(
b"\\A(?~|abc).*(xyz|pqrabc)(?~|)abc",
b"aaaaxyzaaaabcpqrabcabc",
);
}
#[test]
fn ja_lookahead_positive() {
x2("(?=せ)せ".as_bytes(), "せ".as_bytes(), 0, 3);
}
#[test]
fn ja_lookahead_positive_no_match() {
n("(?=う).".as_bytes(), "い".as_bytes());
}
#[test]
fn ja_lookahead_negative() {
x2("(?!う)か".as_bytes(), "か".as_bytes(), 0, 3);
}
#[test]
fn ja_lookahead_negative_no_match() {
n("(?!と)あ".as_bytes(), "と".as_bytes());
}
#[test]
fn ja_alternation_1() {
x2("あ|い".as_bytes(), "あ".as_bytes(), 0, 3);
}
#[test]
fn ja_alternation_2() {
x2("あ|い".as_bytes(), "い".as_bytes(), 0, 3);
}
#[test]
fn ja_case_insensitive_backref() {
x2("((?i:あvず))\\1".as_bytes(), "あvずあvず".as_bytes(), 0, 14);
}
#[test]
fn ja_named_group_recursion() {
x2(
"(?<愚か>変|\\(\\g<愚か>\\))".as_bytes(),
"((((((変))))))".as_bytes(),
0,
15,
);
}
#[test]
fn ja_mutual_recursion() {
x2(
"\\A(?:\\g<阿_1>|\\g<云_2>|\\z終了 (?<阿_1>観|自\\g<云_2>自)(?<云_2>在|菩薩\\g<阿_1>菩薩))$".as_bytes(),
"菩薩自菩薩自在自菩薩自菩薩".as_bytes(),
0, 39,
);
}
#[test]
fn error_utf8_too_short_xf4() {
e(b"\\xF4", b"", ONIGERR_TOO_SHORT_MULTI_BYTE_STRING);
}
#[test]
fn error_utf8_invalid_xf5() {
e(b"\\xF5", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_utf8_invalid_xff() {
e(b"\\xFF", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_utf8_too_short_xf4_in_cc() {
e(b"[\\xF4]", b"", ONIGERR_TOO_SHORT_MULTI_BYTE_STRING);
}
#[test]
fn error_utf8_invalid_xf5_in_cc() {
e(b"[\\xF5]", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn error_utf8_invalid_range_xff() {
e(b"[\\x00-\\xFF]", b"", ONIGERR_INVALID_CODE_POINT_VALUE);
}
#[test]
fn conditional_recursion_complex() {
x2(
b"((?()0+)+++(((0\\g<0>)0)|())++++((?(1)(0\\g<0>))++++++0*())++++((?(1)(0\\g<1>)+)++++++++++*())++++((?(1)((0)\\g<0>)+)++())+0++*+++(((0\\g<0>))*())++++((?(1)(0\\g<0>)+)++++++++++*|)++++*+++((?(1)((0)\\g<0>)+)+++++++++())++*|)++++((?()0))|",
b"abcde",
0, 0,
);
}
#[test]
fn callout_fail() {
n(b"(*FAIL)", b"abcdefg");
}
#[test]
fn callout_fail_repeated() {
n(b"abcd(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)(*FAIL)", b"abcdefg");
}
#[test]
fn callout_max() {
x2(b"(?:[ab]|(*MAX{2}).)*", b"abcbaaccaaa", 0, 7);
}
#[test]
fn callout_count_cmp() {
x2(
b"(?:(*COUNT[AB]{X})[ab]|(*COUNT[CD]{X})[cd])*(*CMP{AB,<,CD})",
b"abababcdab",
5,
8,
);
}
#[test]
fn callout_conditional_code() {
x2(b"(?(?{....})123|456)", b"123", 0, 3);
}
#[test]
fn callout_conditional_fail() {
x2(b"(?(*FAIL)123|456)", b"456", 0, 3);
}
#[test]
fn self_call_possessive_zero() {
x2(b"\\g'0'++{,0}", b"abcdefgh", 0, 0);
}
#[test]
fn self_call_possessive_zero_lazy() {
x2(b"\\g'0'++{,0}?", b"abcdefgh", 0, 0);
}
#[test]
fn self_call_possessive_zero_b() {
x2(b"\\g'0'++{,0}b", b"abcdefgh", 1, 2);
}
#[test]
fn self_call_possessive_zero_lazy_def() {
x2(b"\\g'0'++{,0}?def", b"abcdefgh", 3, 6);
}
#[test]
fn backref_greedy_star_x2() {
x2(b"(a*)\\1", b"aaaaa", 0, 4);
}
#[test]
fn absent_in_lookbehind() {
x2(b"(?<=a|(?~END)|b)c", b"ENDc", 3, 4);
}
#[test]
fn general_newline_crlf() {
x2(b"\\R", b"\r\n", 0, 2);
}
#[test]
fn general_newline_cr() {
x2(b"\\R", b"\r", 0, 1);
}
#[test]
fn general_newline_lf() {
x2(b"\\R", b"\n", 0, 1);
}
#[test]
fn general_newline_vt() {
x2(b"\\R", b"\x0b", 0, 1);
}
#[test]
fn general_newline_crlf_no_separate_lf() {
n(b"\\R\\n", b"\r\n");
}
#[test]
fn general_newline_nel() {
x2(b"\\R", b"\xc2\x85", 0, 2);
}
#[test]
fn not_newline_a() {
x2(b"\\N", b"a", 0, 1);
}
#[test]
fn not_newline_lf() {
n(b"\\N", b"\n");
}
#[test]
fn not_newline_multiline_mode() {
n(b"(?m:\\N)", b"\n");
}
#[test]
fn not_newline_non_multiline_mode() {
n(b"(?-m:\\N)", b"\n");
}
#[test]
fn true_anychar_a() {
x2(b"\\O", b"a", 0, 1);
}
#[test]
fn true_anychar_lf() {
x2(b"\\O", b"\n", 0, 1);
}
#[test]
fn true_anychar_multiline_mode() {
x2(b"(?m:\\O)", b"\n", 0, 1);
}
#[test]
fn true_anychar_non_multiline_mode() {
x2(b"(?-m:\\O)", b"\n", 0, 1);
}
#[test]
fn keep_empty() {
x2(b"\\K", b"a", 0, 0);
}
#[test]
fn keep_after_a() {
x2(b"a\\K", b"a", 1, 1);
}
#[test]
fn keep_a_b() {
x2(b"a\\Kb", b"ab", 1, 2);
}
#[test]
fn keep_alternation() {
x2(b"(a\\Kb|ac\\Kd)", b"acd", 2, 3);
}
#[test]
fn keep_repeated() {
x2(b"(a\\Kb|\\Kac\\K)*", b"acababacab", 9, 10);
}
#[test]
fn option_word_is_ascii() {
n(b"(?W)a*\\W", b"aaa");
}
#[test]
fn option_neg_word_pword_match_ko() {
x2(b"(?-W:\\p{Word})", "\u{3053}".as_bytes(), 0, 3);
}
#[test]
fn option_word_pword_nomatch_ko() {
n(b"(?W:\\p{Word})", "\u{3053}".as_bytes());
}
#[test]
fn option_word_pword_match_k() {
x2(b"(?W:\\p{Word})", b"k", 0, 1);
}
#[test]
fn option_neg_word_posix_word_match_ko() {
x2(b"(?-W:[[:word:]])", "\u{3053}".as_bytes(), 0, 3);
}
#[test]
fn option_word_posix_word_nomatch_ko() {
n(b"(?W:[[:word:]])", "\u{3053}".as_bytes());
}
#[test]
fn option_neg_digit_pdigit_match_fullwidth_3() {
x2(b"(?-D:\\p{Digit})", "\u{FF13}".as_bytes(), 0, 3);
}
#[test]
fn option_digit_pdigit_nomatch_fullwidth_3() {
n(b"(?D:\\p{Digit})", "\u{FF13}".as_bytes());
}
#[test]
fn option_neg_space_pspace_match_nel() {
x2(b"(?-S:\\p{Space})", b"\xc2\x85", 0, 2);
}
#[test]
fn option_space_pspace_nomatch_nel() {
n(b"(?S:\\p{Space})", b"\xc2\x85");
}
#[test]
fn option_neg_posix_pword_match_ko() {
x2(b"(?-P:\\p{Word})", "\u{3053}".as_bytes(), 0, 3);
}
#[test]
fn option_posix_pword_nomatch_ko() {
n(b"(?P:\\p{Word})", "\u{3053}".as_bytes());
}
#[test]
fn option_neg_word_w_match_ko() {
x2(b"(?-W:\\w)", "\u{3053}".as_bytes(), 0, 3);
}
#[test]
fn option_word_w_nomatch_ko() {
n(b"(?W:\\w)", "\u{3053}".as_bytes());
}
#[test]
fn option_neg_word_w_match_k() {
x2(b"(?-W:\\w)", b"k", 0, 1);
}
#[test]
fn option_word_w_match_k() {
x2(b"(?W:\\w)", b"k", 0, 1);
}
#[test]
fn option_neg_word_big_w_nomatch_ko() {
n(b"(?-W:\\W)", "\u{3053}".as_bytes());
}
#[test]
fn option_word_big_w_match_ko() {
x2(b"(?W:\\W)", "\u{3053}".as_bytes(), 0, 3);
}
#[test]
fn option_neg_word_big_w_nomatch_k() {
n(b"(?-W:\\W)", b"k");
}
#[test]
fn option_word_big_w_nomatch_k() {
n(b"(?W:\\W)", b"k");
}
#[test]
fn option_neg_word_b_match_ko() {
x2(b"(?-W:\\b)", "\u{3053}".as_bytes(), 0, 0);
}
#[test]
fn option_word_b_nomatch_ko() {
n(b"(?W:\\b)", "\u{3053}".as_bytes());
}
#[test]
fn option_neg_word_b_match_h() {
x2(b"(?-W:\\b)", b"h", 0, 0);
}
#[test]
fn option_word_b_match_h() {
x2(b"(?W:\\b)", b"h", 0, 0);
}
#[test]
fn option_neg_word_big_b_nomatch_ko() {
n(b"(?-W:\\B)", "\u{3053}".as_bytes());
}
#[test]
fn option_word_big_b_match_ko() {
x2(b"(?W:\\B)", "\u{3053}".as_bytes(), 0, 0);
}
#[test]
fn option_neg_word_big_b_nomatch_h() {
n(b"(?-W:\\B)", b"h");
}
#[test]
fn option_word_big_b_nomatch_h() {
n(b"(?W:\\B)", b"h");
}
#[test]
fn option_neg_posix_b_match_ko() {
x2(b"(?-P:\\b)", "\u{3053}".as_bytes(), 0, 0);
}
#[test]
fn option_posix_b_nomatch_ko() {
n(b"(?P:\\b)", "\u{3053}".as_bytes());
}
#[test]
fn option_neg_posix_b_match_h() {
x2(b"(?-P:\\b)", b"h", 0, 0);
}
#[test]
fn option_posix_b_match_h() {
x2(b"(?P:\\b)", b"h", 0, 0);
}
#[test]
fn option_neg_posix_big_b_nomatch_ko() {
n(b"(?-P:\\B)", "\u{3053}".as_bytes());
}
#[test]
fn option_posix_big_b_match_ko() {
x2(b"(?P:\\B)", "\u{3053}".as_bytes(), 0, 0);
}
#[test]
fn option_neg_posix_big_b_nomatch_h() {
n(b"(?-P:\\B)", b"h");
}
#[test]
fn option_posix_big_b_nomatch_h() {
n(b"(?P:\\B)", b"h");
}
#[test]
fn egcb_cr_lf_boundary_nomatch() {
n(b".\\y\\O", b"\x0d\x0a");
}
#[test]
fn egcb_cr_lf_no_boundary() {
x2(b".\\Y\\O", b"\x0d\x0a", 0, 2);
}
#[test]
fn egcb_g_combining_diaeresis_boundary() {
n(b"^.\\y.$", b"\x67\xCC\x88");
}
#[test]
fn egcb_g_combining_diaeresis_no_boundary() {
x2(b".\\Y.", b"\x67\xCC\x88", 0, 3);
}
#[test]
fn egcb_g_combining_diaeresis_full() {
x2(b"\\y.\\Y.\\y", b"\x67\xCC\x88", 0, 3);
}
#[test]
fn egcb_hangul_syllable_gag() {
x2(b"\\y.\\y", b"\xEA\xB0\x81", 0, 3);
}
#[test]
fn egcb_hangul_jamo_lvt_no_boundary() {
x2(
b"^.\\Y.\\Y.$",
b"\xE1\x84\x80\xE1\x85\xA1\xE1\x86\xA8",
0,
9,
);
}
#[test]
fn egcb_hangul_jamo_lvt_boundary_nomatch() {
n(b"^.\\y.\\Y.$", b"\xE1\x84\x80\xE1\x85\xA1\xE1\x86\xA8");
}
#[test]
fn egcb_tamil_no_boundary() {
x2(b".\\Y.", b"\xE0\xAE\xA8\xE0\xAE\xBF", 0, 6);
}
#[test]
fn egcb_tamil_boundary_nomatch() {
n(b".\\y.", b"\xE0\xAE\xA8\xE0\xAE\xBF");
}
#[test]
fn egcb_thai_no_boundary() {
x2(b".\\Y.", b"\xE0\xB8\x81\xE0\xB8\xB3", 0, 6);
}
#[test]
fn egcb_thai_boundary_nomatch() {
n(b".\\y.", b"\xE0\xB8\x81\xE0\xB8\xB3");
}
#[test]
fn egcb_devanagari_no_boundary() {
x2(b".\\Y.", b"\xE0\xA4\xB7\xE0\xA4\xBF", 0, 6);
}
#[test]
fn egcb_devanagari_boundary_nomatch() {
n(b".\\y.", b"\xE0\xA4\xB7\xE0\xA4\xBF");
}
#[test]
fn egcb_extpict_zwj_extpict() {
x2(b"..\\Y.", b"\xE3\x80\xB0\xE2\x80\x8D\xE2\xAD\x95", 0, 9);
}
#[test]
fn egcb_extpict_extend_zwj_extpict() {
x2(
b"...\\Y.",
b"\xE3\x80\xB0\xCC\x82\xE2\x80\x8D\xE2\xAD\x95",
0,
11,
);
}
#[test]
fn egcb_extpict_nonextend_zwj_extpict_nomatch() {
n(b"...\\Y.", b"\xE3\x80\xB0\xCD\xB0\xE2\x80\x8D\xE2\xAD\x95");
}
#[test]
fn egcb_x_cr_lf_one_cluster() {
n(b"^\\X\\X$", b"\x0d\x0a");
}
#[test]
fn egcb_x_cr_lf_single() {
x2(b"^\\X$", b"\x0d\x0a", 0, 2);
}
#[test]
fn egcb_x_g_diaeresis_not_three() {
n(b"^\\X\\X.$", b"\x67\xCC\x88");
}
#[test]
fn egcb_x_g_diaeresis_one_cluster() {
x2(b"^\\X$", b"\x67\xCC\x88", 0, 3);
}
#[test]
fn egcb_x_hangul_jamo_one_cluster() {
x2(b"^\\X$", b"\xE1\x84\x80\xE1\x85\xA1\xE1\x86\xA8", 0, 9);
}
#[test]
fn egcb_x_hangul_jamo_not_three() {
n(b"^\\X\\X\\X$", b"\xE1\x84\x80\xE1\x85\xA1\xE1\x86\xA8");
}
#[test]
fn egcb_x_tamil_one_cluster() {
x2(b"^\\X$", b"\xE0\xAE\xA8\xE0\xAE\xBF", 0, 6);
}
#[test]
fn egcb_x_tamil_not_two() {
n(b"\\X\\X", b"\xE0\xAE\xA8\xE0\xAE\xBF");
}
#[test]
fn egcb_x_thai_one_cluster() {
x2(b"^\\X$", b"\xE0\xB8\x81\xE0\xB8\xB3", 0, 6);
}
#[test]
fn egcb_x_thai_not_two() {
n(b"\\X\\X", b"\xE0\xB8\x81\xE0\xB8\xB3");
}
#[test]
fn egcb_x_devanagari_one_cluster() {
x2(b"^\\X$", b"\xE0\xA4\xB7\xE0\xA4\xBF", 0, 6);
}
#[test]
fn egcb_x_devanagari_not_two() {
n(b"\\X\\X", b"\xE0\xA4\xB7\xE0\xA4\xBF");
}
#[test]
fn egcb_x_tamil_no_trailing_dot() {
n(b"^\\X.$", b"\xE0\xAE\xA8\xE0\xAE\xBF");
}
#[test]
fn egcb_x_in_word() {
x2(b"h\\Xllo", b"ha\xCC\x80llo", 0, 7);
}
#[test]
fn text_segment_g_boundary_abc() {
x2(b"(?y{g})\\yabc\\y", b"abc", 0, 3);
}
#[test]
fn text_segment_g_x_single_char() {
x2(b"(?y{g})\\y\\X\\y", b"abc", 0, 1);
}
#[test]
fn text_segment_w_boundary_abc() {
x2(b"(?y{w})\\yabc\\y", b"abc", 0, 3);
}
#[test]
fn text_segment_w_x_cr_lf() {
x2(b"(?y{w})\\X", b"\r\n", 0, 2);
}
#[test]
fn text_segment_w_x_wb3a() {
x2(b"(?y{w})\\X", b"\x0cz", 0, 1);
}
#[test]
fn text_segment_w_x_wb3b() {
x2(b"(?y{w})\\X", b"q\x0c", 0, 1);
}
#[test]
fn text_segment_w_x_wb3c() {
x2(b"(?y{w})\\X", b"\xE2\x80\x8D\xE2\x9D\x87", 0, 6);
}
#[test]
fn text_segment_w_x_wb3d() {
x2(b"(?y{w})\\X", b"\x20\x20", 0, 2);
}
#[test]
fn text_segment_w_x_wb4() {
x2(b"(?y{w})\\X", b"a\xE2\x80\x8D", 0, 4);
}
#[test]
fn text_segment_w_x_wb5() {
x2(b"(?y{w})\\y\\X\\y", b"abc", 0, 3);
}
#[test]
fn text_segment_w_x_wb6_7() {
x2(b"(?y{w})\\y\\X\\y", b"v\xCE\x87w", 0, 4);
}
#[test]
fn text_segment_w_x_wb7a() {
x2(b"(?y{w})\\y\\X\\y", b"\xD7\x93\x27", 0, 3);
}
#[test]
fn text_segment_w_x_wb7b_7c() {
x2(b"(?y{w})\\y\\X\\y", b"\xD7\x93\x22\xD7\x93", 0, 5);
}
#[test]
fn text_segment_w_x_wb8() {
x2(b"(?y{w})\\X", b"14 45", 0, 2);
}
#[test]
fn text_segment_w_x_wb9() {
x2(b"(?y{w})\\X", b"a14", 0, 3);
}
#[test]
fn text_segment_w_x_wb10() {
x2(b"(?y{w})\\X", b"832e", 0, 4);
}
#[test]
fn text_segment_w_x_wb11_12() {
x2(b"(?y{w})\\X", b"8\xEF\xBC\x8C\xDB\xB0", 0, 6);
}
#[test]
fn text_segment_w_x_wb13() {
x2(b"(?y{w})\\y\\X\\y", "\u{30B1}\u{30F3}".as_bytes(), 0, 6);
}
#[test]
fn text_segment_w_x_wb13a_13b() {
x2(
b"(?y{w})\\y\\X\\y",
b"\xE3\x82\xB1\xE3\x83\xB3\xE2\x80\xAF\xE3\x82\xBF",
0,
12,
);
}
#[test]
fn text_segment_w_x_wb999() {
x2(b"(?y{w})\\y\\X\\y", b"\x21\x23", 0, 1);
}
#[test]
fn text_segment_w_x_kanji() {
x2(b"(?y{w})\\y\\X\\y", "\u{5C71}\u{30A2}".as_bytes(), 0, 3);
}
#[test]
fn text_segment_w_x_numeric_dot() {
x2(b"(?y{w})\\X", b"3.14", 0, 4);
}
#[test]
fn text_segment_w_x_numeric_space() {
x2(b"(?y{w})\\X", b"3 14", 0, 1);
}
#[test]
fn ja_optional_match() {
x2("変?".as_bytes(), "変".as_bytes(), 0, 3);
}
#[test]
fn ja_star_match() {
x2("量*".as_bytes(), "量".as_bytes(), 0, 3);
}
#[test]
fn check_validity_invalid_utf8_search() {
use ferroni::regexec::onig_search;
let reg = onig_new(
b"a",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap();
let invalid = b"\xff\xfe";
let (r, _) = onig_search(
®,
invalid,
invalid.len(),
0,
invalid.len(),
Some(OnigRegion::new()),
ONIG_OPTION_CHECK_VALIDITY_OF_STRING,
);
assert_eq!(r, ONIGERR_INVALID_WIDE_CHAR_VALUE);
}
#[test]
fn check_validity_valid_utf8_search() {
use ferroni::regexec::onig_search;
let reg = onig_new(
b"a",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap();
let valid = b"abc";
let (r, _) = onig_search(
®,
valid,
valid.len(),
0,
valid.len(),
Some(OnigRegion::new()),
ONIG_OPTION_CHECK_VALIDITY_OF_STRING,
);
assert_eq!(r, 0); }
#[test]
fn check_validity_invalid_utf8_match() {
use ferroni::regexec::onig_match;
let reg = onig_new(
b"a",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap();
let invalid = b"\xc0\x80"; let (r, _) = onig_match(
®,
invalid,
invalid.len(),
0,
Some(OnigRegion::new()),
ONIG_OPTION_CHECK_VALIDITY_OF_STRING,
);
assert_eq!(r, ONIGERR_INVALID_WIDE_CHAR_VALUE);
}
#[test]
fn check_validity_scan_invalid() {
use ferroni::regexec::onig_scan;
let reg = onig_new(
b"a",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap();
let invalid = b"a\xfe";
let (r, _) = onig_scan(
®,
invalid,
invalid.len(),
OnigRegion::new(),
ONIG_OPTION_CHECK_VALIDITY_OF_STRING,
|_n, _pos, _region| 0,
);
assert_eq!(r, ONIGERR_INVALID_WIDE_CHAR_VALUE);
}
#[test]
fn cclass_mb_truncated_utf8_input_mismatch() {
n("[ぁ-ん]".as_bytes(), &[0xE3]);
}
#[test]
fn cclass_mb_not_truncated_utf8_input_matches() {
x2("[^ぁ-ん]".as_bytes(), &[0xE3], 0, 1);
}
#[test]
fn backward_search_optimized() {
use ferroni::regexec::onig_search;
let reg = onig_new(
b"abc",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap();
let input = b"xxabcxx";
let (r, region) = onig_search(
®,
input,
input.len(),
6,
0,
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(r, 2); let region = region.unwrap();
assert_eq!(region.beg[0], 2);
assert_eq!(region.end[0], 5);
}
#[test]
fn backward_search_multibyte() {
use ferroni::regexec::onig_search;
let reg = onig_new(
"あ".as_bytes(),
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&OnigSyntaxOniguruma,
)
.unwrap();
let input = "xxあyy".as_bytes();
let (r, region) = onig_search(
®,
input,
input.len(),
input.len(),
0,
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(r, 2);
let region = region.unwrap();
assert_eq!(region.beg[0], 2);
assert_eq!(region.end[0], 5);
}
fn syntax_with_capture_history() -> OnigSyntaxType {
let mut syn = OnigSyntaxOniguruma.clone();
syn.op2 |= ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY;
syn
}
#[test]
fn capture_history_unnamed() {
use ferroni::regexec::{onig_get_capture_tree, onig_search};
let syn = syntax_with_capture_history();
let reg = onig_new(
b"(?@a+)",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&syn,
)
.unwrap();
let input = b"aaa";
let (r, region) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(r, 0);
let region = region.unwrap();
assert_eq!(region.beg[1], 0);
assert_eq!(region.end[1], 3);
let tree = onig_get_capture_tree(®ion);
assert!(tree.is_some(), "capture history tree should be populated");
let root = tree.unwrap();
assert_eq!(root.group, 0);
assert_eq!(root.beg, 0);
assert_eq!(root.end, 3);
assert_eq!(root.childs.len(), 1);
assert_eq!(root.childs[0].group, 1);
assert_eq!(root.childs[0].beg, 0);
assert_eq!(root.childs[0].end, 3);
}
#[test]
fn capture_history_named() {
use ferroni::regexec::{onig_get_capture_tree, onig_search};
let syn = syntax_with_capture_history();
let reg = onig_new(
b"(?@<name>a+)",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&syn,
)
.unwrap();
let input = b"aaa";
let (r, region) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(r, 0);
let region = region.unwrap();
assert_eq!(region.beg[1], 0);
assert_eq!(region.end[1], 3);
let tree = onig_get_capture_tree(®ion);
assert!(tree.is_some());
let root = tree.unwrap();
assert_eq!(root.childs.len(), 1);
assert_eq!(root.childs[0].group, 1);
}
#[test]
fn capture_history_traverse() {
use ferroni::regexec::{onig_get_capture_tree, onig_search};
use ferroni::regtrav::onig_capture_tree_traverse;
let syn = syntax_with_capture_history();
let reg = onig_new(
b"(?@a+)b(?@c+)",
ONIG_OPTION_NONE,
&ferroni::encodings::utf8::ONIG_ENCODING_UTF8,
&syn,
)
.unwrap();
let input = b"aabcc";
let (r, region) = onig_search(
®,
input,
input.len(),
0,
input.len(),
Some(OnigRegion::new()),
ONIG_OPTION_NONE,
);
assert_eq!(r, 0);
let region = region.unwrap();
let tree = onig_get_capture_tree(®ion);
assert!(tree.is_some());
let root = tree.unwrap();
assert_eq!(root.childs.len(), 2);
assert_eq!(root.childs[0].group, 1);
assert_eq!(root.childs[0].beg, 0);
assert_eq!(root.childs[0].end, 2);
assert_eq!(root.childs[1].group, 2);
assert_eq!(root.childs[1].beg, 3);
assert_eq!(root.childs[1].end, 5);
let mut visited = Vec::new();
onig_capture_tree_traverse(
®ion,
ONIG_TRAVERSE_CALLBACK_AT_FIRST,
|group, _beg, _end, _level, _at| {
visited.push(group);
0
},
);
assert_eq!(visited, vec![0, 1, 2]);
}