void cpp_hl_tests(RegEx& e, bool recurse = true) { if(flags[4] & REG_MERGE) return; if(e.error_code()) { if(search_text != BOOST_RE_STR("!")) { begin_error(); cout << "Expression did not compile with class RegEx" << endl; } return; } if(recurse) { // copy and assign test: RegEx e2(e); cpp_hl_tests(e2, false); e2 = e; cpp_hl_tests(e2, false); } if(flags[4] & REG_GREP) { // try to do grep: hl_match_id = 0; GrepCallback cb = hl_grep_test_proc; e.Grep(cb, search_text.c_str(), flags[3]); } else { if(e.Search(search_text.c_str(), flags[3])) { unsigned int i = 0; unsigned int j = 0; while(matches[j] != -2) { if( (matches[j] != (int)e.Position(i)) || ((matches[j] != -1) && ((matches[j+1] - matches[j] != (int)e.Length(i)))) ) { begin_error(); cout << "RegEx::Search error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl; } ++i; j += 2; } } else { if(matches[0] != -1) { begin_error(); cout << "match expected but not found with RexEx::Search" << endl; } } // // test RegEx::Match only if we expect to match all of the input: // if((matches[0] == 0) && (matches[1] == search_text.size())) { if(e.Match(search_text.c_str(), flags[3])) { unsigned int i = 0; unsigned int j = 0; while(matches[j] != -2) { if( (matches[j] != (int)e.Position(i)) || ((matches[j] != -1) && ((matches[j+1] - matches[j] != (int)e.Length(i)))) ) { begin_error(); cout << "RegEx::Match error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl; } ++i; j += 2; } } else { begin_error(); cout << "Match expected but not found with RegEx::Match" << endl; } } } }
bool #if defined(__BORLANDC__) || defined(BOOST_MSVC) __cdecl #endif hl_grep_test_proc(const RegEx& e) { std::ptrdiff_t start, end; start = e.Position(0); end = start + e.Length(); if((matches[hl_match_id] != start) || (matches[hl_match_id + 1] != end)) { begin_error(); cout << "class RegEx grep match error: found [" << start << "," << end << "] expected [" << matches[hl_match_id] << "," << matches[hl_match_id+1] << "]" << endl; } if(0 == (flags[4] & REG_GREP)) { for(unsigned int sub = 1; sub < e.Marks(); ++sub) { start = e.Position(sub); end = start + e.Length(sub); if((matches[2*sub] != start) || (matches[2*sub + 1] != end)) { begin_error(); cout << "class RegEx grep match error: found in sub " << sub << " [" << start << "," << end << "] expected [" << matches[2*sub] << "," << matches[2*sub+1] << "]" << endl; } } } // // check $`: start = e.Position(-1); end = start + e.Length(-1); if(start == -1) { if(hl_match_id && ( matches[hl_match_id] != matches[hl_match_id - 1] ) ) { begin_error(); cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << matches[hl_match_id-1] << "," << matches[hl_match_id] << "]" << endl; } else if((!hl_match_id) && (0 != matches[0])) { begin_error(); cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << 0 << "," << matches[0] << "]" << endl; } } else { if(hl_match_id && ( (end != matches[hl_match_id]) || (start != matches[hl_match_id - 1]) ) ) { begin_error(); cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << matches[hl_match_id-1] << "," << matches[hl_match_id] << "]" << endl; } else if((!hl_match_id) && ((start != 0) || (end != matches[0]))) { begin_error(); cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << 0 << "," << matches[0] << "]" << endl; } } // // check $': start = e.Position(-2); end = start + e.Length(-2); if(start == -1) { if(matches[hl_match_id + 1] != (int)search_text.size()) { begin_error(); cout << "class RegEx grep error in $': found [" << start << "," << end << "] expected [" << matches[hl_match_id + 1] << "," << (search_text.size()) << "]" << endl; } } else if((start != matches[hl_match_id + 1]) || (end != (int)search_text.size())) { begin_error(); cout << "class RegEx grep error in $': found [" << start << "," << end << "] expected [" << matches[hl_match_id + 1] << "," << (search_text.size()) << "]" << endl; } hl_match_id += 2; return true; }