forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilog_token_classifications_test.cc
110 lines (100 loc) · 5.2 KB
/
verilog_token_classifications_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
// 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 "verilog/parser/verilog_token_classifications.h"
#include "gtest/gtest.h"
#include "verilog/parser/verilog_token_enum.h"
namespace verilog {
namespace {
TEST(VerilogTokenTest, IsWhitespaceTest) {
EXPECT_TRUE(IsWhitespace(verilog_tokentype::TK_NEWLINE));
EXPECT_TRUE(IsWhitespace(verilog_tokentype::TK_SPACE));
EXPECT_FALSE(IsWhitespace(verilog_tokentype::TK_class));
EXPECT_FALSE(IsWhitespace(verilog_tokentype::SymbolIdentifier));
}
// Given a verilog_tokentype, test that IsComment returns true only for comments
TEST(VerilogTokenTest, IsCommentTest) {
EXPECT_TRUE(IsComment(verilog_tokentype::TK_COMMENT_BLOCK));
EXPECT_TRUE(IsComment(verilog_tokentype::TK_EOL_COMMENT));
EXPECT_FALSE(IsComment(verilog_tokentype::DR_begin_keywords));
EXPECT_FALSE(IsComment(verilog_tokentype::SymbolIdentifier));
}
TEST(VerilogTokenTest, IsUnaryOperatorTest) {
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype('*')));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype('/')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('+')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('-')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('~')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('&')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('!')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('|')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype('^')));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype::TK_NAND));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype::TK_NOR));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype::TK_NXOR));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype::TK_INCR));
EXPECT_TRUE(IsUnaryOperator(verilog_tokentype::TK_DECR));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype(':')));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype('?')));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype(',')));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype('.')));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype(';')));
EXPECT_FALSE(IsUnaryOperator(verilog_tokentype('#')));
}
TEST(VerilogTokenTest, IsTernaryOperatorTest) {
EXPECT_FALSE(IsTernaryOperator(verilog_tokentype('*')));
EXPECT_FALSE(IsTernaryOperator(verilog_tokentype('/')));
EXPECT_FALSE(IsTernaryOperator(verilog_tokentype('+')));
EXPECT_FALSE(IsTernaryOperator(verilog_tokentype('-')));
EXPECT_TRUE(IsTernaryOperator(verilog_tokentype('?')));
EXPECT_TRUE(IsTernaryOperator(verilog_tokentype(':')));
}
TEST(VerilogTokenTest, IsUnlexedTest) {
EXPECT_TRUE(IsUnlexed(verilog_tokentype::PP_define_body));
EXPECT_TRUE(IsUnlexed(verilog_tokentype::MacroArg));
EXPECT_FALSE(IsUnlexed(verilog_tokentype::TK_COMMENT_BLOCK));
EXPECT_FALSE(IsUnlexed(verilog_tokentype::SymbolIdentifier));
}
TEST(VerilogTokenTest, IsIdentifierLikeTest) {
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::SymbolIdentifier));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::PP_Identifier));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::MacroIdentifier));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::MacroIdItem));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::MacroCallId));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::SystemTFIdentifier));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::EscapedIdentifier));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Swidth));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Srecrem));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Ssetuphold));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Speriod));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Shold));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Srecovery));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Sremoval));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Ssetup));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Sskew));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Stimeskew));
EXPECT_TRUE(IsIdentifierLike(verilog_tokentype::TK_Swidth));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_StringLiteral));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_DecNumber));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_DecBase));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_DecDigits));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_always));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_wire));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_EOL_COMMENT));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_COMMENT_BLOCK));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TKK_attribute));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype::TK_ATTRIBUTE));
EXPECT_FALSE(IsIdentifierLike(verilog_tokentype('+')));
}
} // namespace
} // namespace verilog