-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cc
More file actions
99 lines (95 loc) · 3.36 KB
/
Copy pathtest.cc
File metadata and controls
99 lines (95 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// #include "Regex/Regex.hpp"
#include "Regex.h"
#include <fstream>
#include <iostream>
#include <stdexcept>
using namespace std;
RE::Regex re;
void rexTest(const string& s)
{
cout << s << endl;
ifstream fs(s);
if (not fs.good())
throw invalid_argument("not fs.good()");
string a, b, c, d;
char tmp[1000];
int cnt = 0, linenum = 0;
while (fs >> a >> b >> c >> d)
{
if (c == "NULL")
continue;
int l = 0, r = 0;
sscanf(d.c_str(), "(%d,%d)%s", &l, &r, tmp);
if (b.front() == '^')
b.erase(0, 1);
if (b.back() == '$')
b.pop_back();
try
{
re.assign(b);
}
catch (const std::exception& e)
{
cout << e.what() << endl;
cout << a << endl;
}
linenum++;
if ((r - l == int(c.length()) and not re.match(c)) or (r - l != int(c.length()) and re.match(c)))
{
cout << a;
cout << " not match!" << endl;
cout << "----" << endl;
cout << b << '\t' << c << '\t' << d << endl;
cout << "----" << endl;
}
else
cnt++;
}
fs.close();
cout << s << ' ' << cnt << '/' << linenum << " cases Done!" << endl;
}
void searchTest(const std::string& rex, const std::string& source, bool flag = true)
{
RE::Regex re2(rex);
string tar = (source);
auto res = re2.search(tar, flag);
cout << res.size() << ' ' << rex << endl;
for (auto&& i : res)
{
// cout << i.first << " " << i.second << endl;
cout << tar << endl;
for (size_t j = 0; j < tar.length(); j++)
{
if (j < i.first)
cout << ' ';
else if (j == i.first)
cout << '^';
else if (j < i.second)
cout << '-';
else if (j == i.second)
cout << '^';
}
cout << endl;
}
}
signed main(void)
{
for (int i = 0; i < 6; i++)
{
rexTest("./rexTestCase/rexTestCase" + to_string(i) + ".txt");
}
cout << "Over!" << endl;
searchTest("ab|cd", "abcdhfcd");
searchTest("aa*", "abcaaaaaaa", true);
searchTest("aa*", "abcaaaaaaa", false);
searchTest("aaa", "abcaaaaaaa");
searchTest(".*", "abcaaaaaaa");
searchTest(".*@", "delta-in-hub@github.com");
searchTest("[\\d]{2}", "abc123123aaa21aa1aa");
searchTest("([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9~-]+).)+([-A-Za-z0-9~\\\\/])+", "http://www.fapiao.com/dddp-web/pdf/download?request=6e7JGxxxxx4ILd-kExxxxxxxqJ4-CHLmqVnenXC692m74H38sdfdsazxcUmfcOH2fAfY1Vw__%5EDadIfJgiEf"); //https://zhuanlan.zhihu.com/p/163279494
searchTest("[a-zA-Z0-9._]+@([a-zA-Z0-9]+.)+com", "power.overwhelming@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); //https://zhuanlan.zhihu.com/p/46294360
searchTest("(0|[0-1]){2,15}(hello){0,2}([0-9]+)+", "00hellohello0000000000000000000000000000");
searchTest("([01]+)+b", "10101010110101001100101010101010101010101010101010000"); //https://www.zhihu.com/question/21145025/answer/189268974
searchTest("\\d+\\d", "11"); //https://www.zhihu.com/question/27434493/answer/36701865 评论
return 0;
}