The Battle for Wesnoth  1.17.0-dev
test_macro_define.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2020 - 2021
3  by CrawlCycle <73139676+CrawlCycle@users.noreply.github.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Test if the WML preprocessor and parser together can correctly process
19  * \#define and \#undef macros.
20  */
21 
22 #define GETTEXT_DOMAIN "wesnoth-test"
23 
25 #include <boost/test/unit_test.hpp>
26 
27 BOOST_AUTO_TEST_SUITE(feature_test_WML_macro_define)
28 
29 BOOST_AUTO_TEST_CASE(macro_define_noArgument_ParseAsExpected)
30 {
31  // Test WML macro: #define
32  std::string actual = "#define Macro\n"
33  "[A][/A]\n"
34  "#enddef\n"
35  "{Macro}\n"
36  "{Macro}{Macro}\n"
37  "{Macro}{Macro}{Macro}\n";
38  std::string expected = "";
39  for(int i = 0; i < 6; ++i) {
40  expected += "[A][/A]";
41  }
42  check_wml_equivalence(actual, expected);
43 }
44 
45 BOOST_AUTO_TEST_CASE(macro_define_1Argument_ParseAsExpected)
46 {
47  // Test WML macro: #define with 1 argument
48  std::string actual = "#define MACRO\n"
49  "abc#enddef\n"
50  "a=\"{MACRO}\"\n";
51  std::string expected = "a=\"abc\"";
52  check_wml_equivalence(actual, expected);
53 }
54 
55 BOOST_AUTO_TEST_SUITE_END()
Tool to check if two WML string are equivalent.
void check_wml_equivalence(const std::string &a, const std::string &b)
Assert two WML strings are equivalent.
BOOST_AUTO_TEST_CASE(macro_define_noArgument_ParseAsExpected)
BOOST_AUTO_TEST_SUITE(filesystem)
std::size_t i
Definition: function.cpp:967