clang-tidy: google tests applicable
[alexxy/gromacs.git] / src / gromacs / utility / tests / gmxregex.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal \file
36  * \brief Tests for gmx::Regex
37  *
38  * These tests ensure that basic regex operations work. We have
39  * two different underlying implementations, so we need to prove
40  * to ourselves that these work the same on the range of operations
41  * we try to use.
42  *
43  * \author Mark Abraham <mark.j.abraham@gmail.com>
44  * \ingroup module_utility
45  */
46
47 #include "gmxpre.h"
48
49 #include "gromacs/utility/gmxregex.h"
50
51 #include <future>
52 #include <gtest/gtest.h>
53
54
55 namespace gmx
56 {
57 namespace test
58 {
59 namespace
60 {
61
62 TEST(RegexBasicTest, BasicMatchesWorkWhenSupported)
63 {
64     if (!Regex::isSupported())
65     {
66         return;
67     }
68
69     EXPECT_TRUE(regexMatch("dog", Regex("dog")));
70     EXPECT_TRUE(regexMatch("dog", Regex("^dog")));
71     EXPECT_TRUE(regexMatch("dog", Regex("dog$")));
72     EXPECT_TRUE(regexMatch("dog", Regex("^dog$")));
73     EXPECT_TRUE(regexMatch("dog", Regex(".*d.*")));
74     EXPECT_TRUE(regexMatch("dog", Regex("d+og")));
75
76     EXPECT_FALSE(regexMatch("dog", Regex("cat")));
77     EXPECT_FALSE(regexMatch("dog", Regex("^og")));
78     EXPECT_FALSE(regexMatch("dog", Regex("do$")));
79     EXPECT_FALSE(regexMatch("dog", Regex("^o$")));
80     EXPECT_FALSE(regexMatch("dog", Regex(".*c.*")));
81     EXPECT_FALSE(regexMatch("dog", Regex("c+dog")));
82 }
83
84 TEST(RegexBasicTest, MatchesForCharacterClassesWorkWhenSupported)
85 {
86     if (!Regex::isSupported())
87     {
88         return;
89     }
90
91     EXPECT_TRUE(regexMatch("Dog", Regex("[[:alpha:]]+")));
92     EXPECT_TRUE(regexMatch("dog", Regex("[[:lower:]]+")));
93     EXPECT_TRUE(regexMatch("DOG", Regex("[[:upper:]]+")));
94     EXPECT_TRUE(regexMatch("123", Regex("[[:digit:]]+")));
95     EXPECT_TRUE(regexMatch("123aE", Regex("[[:xdigit:]]+")));
96     EXPECT_TRUE(regexMatch("Dog123", Regex("[[:alnum:]]+")));
97     EXPECT_TRUE(regexMatch(" ", Regex("[[:space:]]+")));
98     EXPECT_TRUE(regexMatch("\t ", Regex("[[:blank:]]+")));
99     EXPECT_TRUE(regexMatch(".,:;-", Regex("[[:punct:]]+")));
100     EXPECT_TRUE(regexMatch("Dog,123", Regex("[[:graph:]]+")));
101     EXPECT_TRUE(regexMatch("Dog, 123", Regex("[[:print:]]+")));
102
103     EXPECT_FALSE(regexMatch("D0g", Regex("[[:alpha:]]+")));
104     EXPECT_FALSE(regexMatch("Dog", Regex("[[:lower:]]+")));
105     EXPECT_FALSE(regexMatch("Dog", Regex("[[:upper:]]+")));
106     EXPECT_FALSE(regexMatch("D0g", Regex("[[:digit:]]+")));
107     EXPECT_FALSE(regexMatch("12xyz3aE", Regex("[[:xdigit:]]+")));
108     EXPECT_FALSE(regexMatch("Dog, 123", Regex("[[:alnum:]]+")));
109     EXPECT_FALSE(regexMatch("dog", Regex("[[:space:]]+")));
110     EXPECT_FALSE(regexMatch("dog\t ", Regex("[[:blank:]]+")));
111     EXPECT_FALSE(regexMatch(".,:d;-", Regex("[[:punct:]]+")));
112     EXPECT_FALSE(regexMatch("Dog,123 ", Regex("[[:graph:]]+")));
113
114     EXPECT_TRUE(regexMatch(" ", Regex("[[:space:]]")));
115     EXPECT_TRUE(regexMatch(" ", Regex("[[:blank:]]")));
116     EXPECT_TRUE(regexMatch("\t", Regex("[[:blank:]]")));
117     EXPECT_TRUE(regexMatch("\t", Regex("[[:space:]]")));
118 }
119
120 } // namespace
121 } // namespace test
122 } // namespace gmx