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