Debian Codegraph @

Testing/kwsSemiColonSpaceTest.cxx

raw
1 /*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 #if defined(_MSC_VER)
19 #pragma warning ( disable : 4786 )
20 #endif
21
22 #include "kwsParser.h"
23
24 int kwsSemiColonSpaceTest(int, char* [] )
25 {
26 std::string buffer;
27 buffer = "Test() ;";
28
29 kws::Parser parser;
30 parser.SetBuffer(buffer);
31 parser.Check("SemicolonSpace","0");
32
33 // Test for bad syntax
34 std::cout << "Test for bad syntax: ";
35 kws::Parser::ErrorVectorType errors = parser.GetErrors();
36 if (!errors.empty()) {
37 for (auto &error : errors) {
38 std::cout << error.description << std::endl;
39 }
40 } else {
41 std::cout << "[FAILED]" << std::endl;
42 return EXIT_FAILURE;
43 }
44 std::cout << "[PASSED]" << std::endl;
45
46 // Test for bad syntax
47 buffer = "Test();;";
48 parser.ClearErrors();
49 parser.SetBuffer(buffer);
50 parser.Check("SemicolonSpace","0");
51 std::cout << "Test for bad syntax: ";
52 errors = parser.GetErrors();
53 if (!errors.empty()) {
54 for (auto &error : errors) {
55 std::cout << error.description << std::endl;
56 }
57 } else {
58 std::cout << "[FAILED]" << std::endl;
59 return EXIT_FAILURE;
60 }
61 std::cout << "[PASSED]" << std::endl;
62
63
64 // Test for good syntax
65 buffer = "std::string str = \" ;\"; ";
66 parser.ClearErrors();
67 parser.SetBuffer(buffer);
68 parser.Check("SemicolonSpace","0");
69 std::cout << "Test for good syntax: ";
70 errors = parser.GetErrors();
71 if (!errors.empty()) {
72 for (auto &error : errors) {
73 std::cout << error.description << std::endl;
74 }
75 std::cout << "[FAILED]" << std::endl;
76 return EXIT_FAILURE;
77 }
78 std::cout << "[PASSED]" << std::endl;
79
80 // Test for good syntax of initializer value return lists
81 buffer = "const int spacing{ 1 };";
82 parser.ClearErrors();
83 parser.SetBuffer(buffer);
84 parser.Check("SemicolonSpace","0");
85
86 std::cout << "Test for return value initializer lists: ";
87 errors = parser.GetErrors();
88 if (!errors.empty()) {
89 for (auto &error : errors) {
90 std::cout << error.description << std::endl;
91 }
92 std::cout << "[FAILED]" << std::endl;
93 return EXIT_FAILURE;
94 }
95 std::cout << "[PASSED]" << std::endl;
96
97 // Test for good syntax
98 buffer = "class myclass\n{\nmyfunction(){};\n\n\n\n};";
99 parser.ClearErrors();
100 parser.SetBuffer(buffer);
101 parser.Check("SemicolonSpace","0");
102
103 std::cout << "Test for good syntax: ";
104 errors = parser.GetErrors();
105 if (!errors.empty()) {
106 for (auto &error : errors) {
107 std::cout << error.description << std::endl;
108 }
109 std::cout << "[FAILED]" << std::endl;
110 return EXIT_FAILURE;
111 }
112 std::cout << "[PASSED]" << std::endl;
113
114 // Test for good syntax
115 buffer = "class myclass\n{\nmyfunction(){test;}\n\n\n\n};";
116 parser.ClearErrors();
117 parser.SetBuffer(buffer);
118 parser.Check("SemicolonSpace","0");
119
120 std::cout << "Test for good syntax: ";
121 errors = parser.GetErrors();
122 if (!errors.empty()) {
123 for (auto &error : errors) {
124 std::cout << error.description << std::endl;
125 }
126 std::cout << "[FAILED]" << std::endl;
127 return EXIT_FAILURE;
128 }
129 std::cout << "[PASSED]" << std::endl;
130
131 // Test for good syntax
132 buffer = "Test();";
133 parser.ClearErrors();
134 parser.SetBuffer(buffer);
135 parser.Check("SemicolonSpace","0");
136
137 std::cout << "Test for good syntax: ";
138 errors = parser.GetErrors();
139 if (!errors.empty()) {
140 for (auto &error : errors) {
141 std::cout << error.description << std::endl;
142 }
143 std::cout << "[FAILED]" << std::endl;
144 return EXIT_FAILURE;
145 }
146 std::cout << "[PASSED]" << std::endl;
147
148 // Test for good syntax
149 buffer = "std::string str( \"();;\" );";
150 //buffer += "}\n";
151 parser.ClearErrors();
152 parser.SetBuffer(buffer);
153 parser.Check("SemicolonSpace","0");
154
155 std::cout << "Test for good syntax: ";
156 errors = parser.GetErrors();
157 if (!errors.empty()) {
158 for (auto &error : errors) {
159 std::cout << error.description << std::endl;
160 }
161 std::cout << "[FAILED]" << std::endl;
162 return EXIT_FAILURE;
163 }
164 std::cout << "[PASSED]" << std::endl;
165
166 std::cout << "[DONE]" << std::endl;
167
168 return 0;
169 }