Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
cetlib
cetlib
test
regex_t.cc
Go to the documentation of this file.
1
#ifdef STANDALONE_TEST
2
#include <cassert>
3
#define BOOST_TEST_REQUIRE assert
4
#define BOOST_TEST assert
5
#else
6
#define BOOST_TEST_MODULE (regex test)
7
#include "boost/test/unit_test.hpp"
8
#include "
cetlib/LibraryManager.h
"
9
#endif
10
11
#include <fstream>
12
#include <iostream>
13
#include <regex>
14
#include <string>
15
#include <vector>
16
17
#ifdef STANDALONE_TEST
18
int
19
main
()
20
{
21
#else
22
BOOST_AUTO_TEST_SUITE(RegexTests)
23
24
BOOST_AUTO_TEST_CASE
(pluginRegex)
25
#endif
26
{
27
std::ifstream
inFile
(
"regex.txt"
);
28
BOOST_TEST_REQUIRE
(static_cast<bool>(inFile));
29
#ifdef STANDALONE_TEST
30
std::string
const
pattern_stem
= {
"(?:[A-Za-z0-9\\-]*_)*[A-Za-z0-9]+_"
};
31
#else
32
cet::LibraryManager
dummy
(
"noplugin"
);
33
std::string
const
pattern_stem = dummy.
patternStem
();
34
#endif
35
std::string
pattern
=
36
std::string
(
"lib("
) + pattern_stem +
")([A-Za-z0-9]+)\\.so"
;
37
for
(
std::string
line
; std::getline(inFile,
line
);) {
38
static
std::regex
const
r
(pattern);
39
std::smatch subs;
40
bool
result
= std::regex_match(
line
, subs,
r
);
41
std::cout <<
line
<<
" match: "
<< std::boolalpha << result
42
<< (result ?
43
(
std::string
(
" (stem "
) +
44
subs[1].str().substr(0, subs[1].
str
().
size
() - 1) +
45
", type "
+ subs[2].str() +
")"
) :
46
""
)
47
<<
std::endl
;
48
BOOST_TEST(result);
49
}
50
}
51
52
#ifndef STANDALONE_TEST
53
BOOST_AUTO_TEST_CASE
(alternationCheck_subscript)
54
#endif
55
{
56
std::regex
const
pattern1{R
"(.*\[(?:\d*[1-9]|\d+0)\])"};
57
std::regex
const
pattern2
{R
"(.*\[(?:\d+0|\d*[1-9])\])"};
58
59
std::vector<std::string>
const
tests
{
"test[0]"
,
"test[1]"
,
"test[10]"
};
60
61
auto
verify_match
= [&pattern1, &
pattern2
](
std::string
const
&
test
) {
62
return
std::regex_match(
test
, pattern1) ==
63
std::regex_match(
test
,
pattern2
);
64
};
65
66
for
(
auto
const
&
test
:
tests
)
67
BOOST_TEST(
verify_match
(
test
));
68
}
69
70
#ifndef STANDALONE_TEST
71
BOOST_AUTO_TEST_CASE
(alternationCheck_dot)
72
#endif
73
{
74
std::regex
const
pattern1{R
"(.*\.(?:\d*[1-9]|\d+0))"};
75
std::regex
const
pattern2
{R
"(.*\.(?:\d+0|\d*[1-9]))"};
76
77
std::vector<std::string>
const
tests
{
78
"test.0"
,
79
"test.1"
,
80
"test.10"
// Using pattern1 vs. pattern2 gives different result w/
81
// clang 3.6
82
};
83
84
auto
verify_match
= [&pattern1, &
pattern2
](
std::string
const
&
test
) {
85
return
std::regex_match(
test
, pattern1) ==
86
std::regex_match(
test
,
pattern2
);
87
};
88
89
for
(
auto
const
&
test
:
tests
)
90
BOOST_TEST(
verify_match
(
test
));
91
}
92
93
#ifdef STANDALONE_TEST
94
}
95
#else
96
BOOST_AUTO_TEST_SUITE_END()
97
#endif
pattern2
std::regex const pattern2
Definition:
regex_t.cc:57
freeze_graph.main
main
Definition:
freeze_graph.py:218
result
static QCString result
Definition:
fortranscanner.cpp:56614
string
std::string string
Definition:
nybbler.cc:12
test
Definition:
PandoraAnalysis_module.cc:49
BOOST_TEST_REQUIRE
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
util::size
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition:
StdUtils.h:92
cet::LibraryManager::patternStem
std::string patternStem() const
Definition:
LibraryManager.h:132
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(SourceListWithComments)
Definition:
artapp_basicSourceOptions_t.cc:10
fhicl::has_insertion_operator_impl::test
yes & test(std::ostream &)
LibraryManager.h
inFile
TFile * inFile
Definition:
makeDST.cxx:36
cet::LibraryManager
Definition:
LibraryManager.h:19
pattern
std::string pattern
Definition:
regex_t.cc:35
pduneana::line
void line(double t, double *p, double &x, double &y, double &z)
Definition:
PDSPAnalyzer_module.cc:4741
tests
Definition:
gtestGAtmoFlux.cxx:193
pattern_stem
std::string const pattern_stem
Definition:
regex_t.cc:33
dummy
cet::LibraryManager dummy("noplugin")
verify_match
auto verify_match
Definition:
regex_t.cc:61
str
static QCString str
Definition:
fortrancode.cpp:27098
plot_model.r
r
Definition:
plot_model.py:57
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11