forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaming_utils_test.cc
125 lines (113 loc) · 3.87 KB
/
naming_utils_test.cc
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2017-2020 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "common/strings/naming_utils.h"
#include "gtest/gtest.h"
namespace verible {
namespace {
// Tests that all strings containing more than just upper case letters,
// underscores, and digits are rejected.
TEST(IsNameAllCapsUnderscoresDigitsTest, RejectTests) {
static const char* test_cases[] = {
"foo", "HAS A SPACE", "NOT_ALL_UPPERCASe", "MiXeD",
"FO?O", "lower", "lower_underscore",
};
for (const auto data : test_cases) {
EXPECT_FALSE(IsNameAllCapsUnderscoresDigits(data));
}
}
// Tests that all strings containing only upper case letters, underscores, and
// digits are accepted.
TEST(IsNameAllCapsUnderscoresDigitsTest, AcceptTests) {
static const char* test_cases[] = {
"", "FOO", "HAS_UNDERSCORE", "_UNDERSCORE_AT_BEGINNING",
"___", "__UPPER__", "_123", "FOO_1",
};
for (const auto data : test_cases) {
EXPECT_TRUE(IsNameAllCapsUnderscoresDigits(data));
}
}
// Tests that all strings containing underscores not next to digits are
// rejected.
TEST(AllUnderscoresFollowedByDigitsTest, RejectTests) {
static const char* test_cases[] = {
"Hello_World", "_H1", "Hello_", "1_", "Foo1_Bar",
"Fo_1_o", "_", "Hello__1", "Hello__World", "__1",
};
for (const auto data : test_cases) {
EXPECT_FALSE(AllUnderscoresFollowedByDigits(data));
}
}
// Tests that all strings containing underscores next to a digit are accepted.
TEST(AllUnderscoresFollowedByDigitsTest, AcceptTests) {
static const char* test_cases[] = {
"",
"Foo_1",
"Foo_1_1",
"_1",
};
for (const auto data : test_cases) {
EXPECT_TRUE(AllUnderscoresFollowedByDigits(data));
}
}
// Tests that all strings not following UpperCamelCase naming convention are
// rejected.
TEST(IsUpperCamelCaseWithDigitsTest, RejectTests) {
static const char* test_cases[] = {
"Hello_World", "hello_world", "helloworld", "helloWorld", "Hello_1_World",
"Hello__1", "Foo_", "_Foo", "_1", "__Foo",
};
for (const auto data : test_cases) {
EXPECT_FALSE(IsUpperCamelCaseWithDigits(data));
}
}
// Tests that all strings following UpperCamelCase naming convention are
// accepted.
TEST(IsUpperCamelCaseWithDigitsTest, AcceptTests) {
static const char* test_cases[] = {
"",
"HelloWorld",
"Foo_1",
"HelloWorld_1",
"HelloWorld_1_1",
"HelloWorld1",
"ABCWorld",
};
for (const auto data : test_cases) {
EXPECT_TRUE(IsUpperCamelCaseWithDigits(data));
}
}
// Tests that all strings following lower_snake_case naming convention are
// accepted.
TEST(IsLowerSnakeCaseWithDigitsTest, AcceptTests) {
static const char* test_cases[] = {
"", "hello_world", "hello_1_world", "hello_1", "hello_world_1_1",
"hello1", "hello_",
};
for (const auto data : test_cases) {
EXPECT_TRUE(IsLowerSnakeCaseWithDigits(data));
}
}
// Tests that all strings not following lower_snake_case naming convention are
// rejected.
TEST(IsLowerSnakeCaseWithDigitsTest, RejectTests) {
static const char* test_cases[] = {
"_1", "__hello", "Hello_world", "hello_1_World",
"hello_1W", "HelloWorld", "helLo1_",
};
for (const auto data : test_cases) {
EXPECT_FALSE(IsLowerSnakeCaseWithDigits(data));
}
}
} // namespace
} // namespace verible