Debian Codegraph @

Testing/kwsSwitchCaseTest.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 kwsSwitchCaseTest(int, char* [] )
25 {
26 std::string buffer;
27 buffer = "void()\n{\ntest;\n};";
28
29 kws::Parser parser;
30 parser.SetBuffer(buffer);
31 parser.Check("Indent","SPACE,2,true,true");
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 = "void()\n{\n test;\n};";
48 parser.ClearErrors();
49 parser.SetBuffer(buffer);
50 parser.Check("Indent","SPACE,2,true,true");
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.line << " : " << error.description << std::endl;
57 }
58 std::cout << "[FAILED]" << std::endl;
59 return EXIT_FAILURE;
60 }
61 std::cout << "[PASSED]" << std::endl;
62
63 std::cout << "[DONE]" << std::endl;
64
65 return 0;
66 }