Debian Codegraph @

Testing/kwsVariablePerLineTest.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 kwsVariablePerLineTest(int, char* [] )
25 {
26 std::string buffer;
27 buffer = "//This is a test\r\nint a,b, c;";
28
29 kws::Parser parser;
30 parser.SetBuffer(buffer);
31 parser.Check("VariablePerLine","1");
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 good syntax
47 buffer = "int a;\r\nint b;";
48 parser.ClearErrors();
49 parser.SetBuffer(buffer);
50 parser.Check("VariablePerLine","1");
51
52 std::cout << "Test for good syntax: ";
53 errors = parser.GetErrors();
54 if (!errors.empty()) {
55 for (auto &error : errors) {
56 std::cout << error.description << std::endl;
57 }
58 std::cout << "[FAILED]" << std::endl;
59 return EXIT_FAILURE;
60 }
61 std::cout << "[PASSED]" << std::endl;
62
63 // Test for good syntax
64 buffer = "int a,b;";
65 parser.ClearErrors();
66 parser.SetBuffer(buffer);
67 parser.Check("VariablePerLine","2");
68
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
81 buffer = "template < int t,\r\nint x, int c > foo;";
82 parser.ClearErrors();
83 parser.SetBuffer(buffer);
84 parser.Check("VariablePerLine","1");
85
86 std::cout << "Test for good syntax: ";
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
96 // Test for good syntax
97 buffer = "void func( int t,\r\n int x, int c, \r\n int d );";
98 parser.ClearErrors();
99 parser.SetBuffer(buffer);
100 parser.Check("VariablePerLine","1");
101
102 std::cout << "Test for good syntax: ";
103 errors = parser.GetErrors();
104 if (!errors.empty()) {
105 for (auto &error : errors) {
106 std::cout << error.description << std::endl;
107 }
108 std::cout << "[FAILED]" << std::endl;
109 return EXIT_FAILURE;
110 }
111 std::cout << "[PASSED]" << std::endl;
112
113 std::cout << "[DONE]" << std::endl;
114
115 return 0;
116 }