OmniSciDB  04ee39c94c
UtilTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "../Utils/Regexp.h"
18 #include "../Utils/StringLike.h"
19 #include "TestHelpers.h"
20 
21 #include <gtest/gtest.h>
22 
23 TEST(Utils, StringLike) {
24  ASSERT_TRUE(string_like("abc", 3, "abc", 3, '\\'));
25  ASSERT_FALSE(string_like("abc", 3, "ABC", 3, '\\'));
26  ASSERT_TRUE(string_ilike("Xyzabc", 6, "xyz%", 4, '\\'));
27  ASSERT_TRUE(string_like("abcxyzefg", 9, "%xyz%", 5, '\\'));
28  ASSERT_TRUE(string_like("abcxyzefgXYZhij", 15, "%xyz%XYZ%", 9, '\\'));
29  ASSERT_TRUE(string_like("abcxOzefgXpZhij", 15, "%x_z%X_Z%", 9, '\\'));
30  ASSERT_TRUE(string_like("abc100%efg", 10, "%100!%___", 9, '!'));
31  ASSERT_TRUE(string_like("[ hello", 7, "%\\[%", 4, '\\'));
32  ASSERT_TRUE(string_like("hello [", 7, "%\\[%", 4, '\\'));
33 }
34 
35 TEST(Utils, Regexp) {
36  ASSERT_TRUE(regexp_like("abc", 3, "abc", 3, '\\'));
37  ASSERT_FALSE(regexp_like("abc", 3, "ABC", 3, '\\'));
38  ASSERT_TRUE(regexp_like("Xyzabc", 6, "[xX]yz.*", 8, '\\'));
39  ASSERT_TRUE(regexp_like("abcxyzefg", 9, ".*xyz.*", 7, '\\'));
40  ASSERT_TRUE(regexp_like("abcxyzefgXYZhij", 15, ".*xyz.*XYZ.*", 12, '\\'));
41  ASSERT_TRUE(regexp_like("abcxOzefgXpZhij", 15, ".+x.z.*X.Z.*", 12, '\\'));
42  // Custom escape characters are not yet supported.
43  ASSERT_FALSE(regexp_like("abc100%efg", 10, ".+100!%...", 10, '!'));
44  ASSERT_TRUE(regexp_like("[ hello", 7, ".*\\[.*", 6, '\\'));
45  ASSERT_TRUE(regexp_like("hello [", 7, ".*\\[.*", 6, '\\'));
46 }
47 
48 int main(int argc, char* argv[]) {
50  ::testing::InitGoogleTest(&argc, argv);
51 
52  int err{0};
53  try {
54  err = RUN_ALL_TESTS();
55  } catch (const std::exception& e) {
56  LOG(ERROR) << e.what();
57  }
58  return err;
59 }
#define LOG(tag)
Definition: Logger.h:182
TEST(Utils, StringLike)
Definition: UtilTest.cpp:23
DEVICE bool regexp_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: Regexp.cpp:40
DEVICE bool string_ilike(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: StringLike.cpp:257
DEVICE bool string_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: StringLike.cpp:246
int main(int argc, char *argv[])
Definition: UtilTest.cpp:48
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194