15 #define GETTEXT_DOMAIN "wesnoth-test"
17 #include <boost/test/unit_test.hpp>
30 if(key ==
"strength") {
32 }
else if(key ==
"agility") {
42 if(key ==
"members") {
43 i_[0].add(
"strength",
variant(12));
44 i_[1].add(
"strength",
variant(16));
45 i_[2].add(
"strength",
variant(14));
46 std::vector<variant> members;
47 for(
int n = 0;
n != 3; ++
n) {
48 members.emplace_back(i_[
n].fake_ptr());
52 }
else if(key ==
"char") {
73 BOOST_CHECK_EQUAL(
formula(
"strength").evaluate(
c).as_int(), 15);
74 BOOST_CHECK_EQUAL(
formula(
"17").evaluate().as_int(), 17);
76 BOOST_CHECK_EQUAL(
formula(
"strength/2 + agility").evaluate(
c).as_int(), 19);
77 BOOST_CHECK_EQUAL(
formula(
"(strength+agility)/2").evaluate(
c).as_int(), 13);
79 BOOST_CHECK_EQUAL(
formula(
"20 % 3").evaluate().as_int(), 2);
80 BOOST_CHECK_EQUAL(
formula(
"19.5 % 3").evaluate().as_decimal(),
81 static_cast<int>(1000.0 * 1.5));
83 BOOST_CHECK_EQUAL(
formula(
"-5").evaluate().as_int(), -5);
85 BOOST_CHECK_EQUAL(
formula(
"4^2").evaluate().as_int(), 16);
86 BOOST_CHECK_EQUAL(
formula(
"2+3^3").evaluate().as_int(), 29);
87 BOOST_CHECK_EQUAL(
formula(
"2*3^3+2").evaluate().as_int(), 56);
88 BOOST_CHECK_EQUAL(
formula(
"2^3^2").evaluate().as_int(), 512);
89 BOOST_CHECK_EQUAL(
formula(
"9^3").evaluate().as_int(), 729);
90 BOOST_CHECK(
formula(
"(-2)^0.5").evaluate().is_null());
95 BOOST_CHECK_EQUAL(
formula(
"strength > 12").evaluate(
c).as_int(), 1);
96 BOOST_CHECK_EQUAL(
formula(
"strength > 18").evaluate(
c).as_int(), 0);
98 BOOST_CHECK_EQUAL(
formula(
"if(strength > 12, 7, 2)").evaluate(
c).as_int(), 7);
99 BOOST_CHECK_EQUAL(
formula(
"if(strength > 18, 7, 2)").evaluate(
c).as_int(), 2);
101 BOOST_CHECK_EQUAL(
formula(
"2 and 1").evaluate().as_int(), 1);
102 BOOST_CHECK_EQUAL(
formula(
"2 and 0").evaluate().as_int(), 0);
103 BOOST_CHECK_EQUAL(
formula(
"2 or 0").evaluate().as_int(), 2);
105 BOOST_CHECK_EQUAL(
formula(
"not 5").evaluate().as_int(), 0);
106 BOOST_CHECK_EQUAL(
formula(
"not 0").evaluate().as_int(), 1);
113 BOOST_CHECK_EQUAL(
formula(
"char.strength").evaluate(
p).as_int(), 15);
114 BOOST_CHECK_EQUAL(
formula(
"choose(members,strength).strength").evaluate(
p).as_int(), 16);
116 BOOST_CHECK_EQUAL(
formula(
"char.sum([strength, agility, intelligence])").evaluate(
p).as_int(), 37);
121 BOOST_CHECK_EQUAL(
formula(
"x*5 where x=1").evaluate().as_int(), 5);
122 BOOST_CHECK_EQUAL(
formula(
"x*5 where x=2").evaluate().as_int(), 10);
124 BOOST_CHECK_EQUAL(
formula(
"x*(a*b where a=2,b=1) where x=5").evaluate().as_int(), 10);
125 BOOST_CHECK_EQUAL(
formula(
"char.strength * ability where ability=3").evaluate(
p).as_int(), 45);
130 BOOST_CHECK_EQUAL(
formula(
"'abcd' = 'abcd'").evaluate().as_bool(),
true);
131 BOOST_CHECK_EQUAL(
formula(
"'abcd' = 'acd'").evaluate().as_bool(),
false);
133 BOOST_CHECK_EQUAL(
formula(
"'ab' .. 'cd'").evaluate().as_string(),
"abcd");
135 BOOST_CHECK_EQUAL(
formula(
"'strength, agility: [strength], [agility]'").evaluate(
c).as_string(),
136 "strength, agility: 15, 12");
138 BOOST_CHECK_EQUAL(
formula(
"'String with [']quotes['] and [(]brackets[)]!'").evaluate().as_string(),
139 "String with 'quotes' and [brackets]!");
140 BOOST_CHECK_EQUAL(
formula(
"'String with ['embedded ' .. 'string']!'").evaluate().as_string(),
141 "String with embedded string!");
146 assert(dice_roll >= 3 && dice_roll <= 18);
152 BOOST_CHECK_EQUAL(myarray[0].as_int(), 1);
153 BOOST_CHECK_EQUAL(myarray[1].as_int(), 2);
154 BOOST_CHECK_EQUAL(myarray[2].as_int(), 3);
158 BOOST_CHECK_EQUAL(mydict[
variant(
"foo")].as_int(), 5);
159 BOOST_CHECK_EQUAL(mydict[
variant(
"bar")].as_int(), 7);
163 BOOST_CHECK_EQUAL(myrange[0].as_int(), -2);
164 BOOST_CHECK_EQUAL(myrange[1].as_int(), -1);
165 BOOST_CHECK_EQUAL(myrange[2].as_int(), 0);
166 BOOST_CHECK_EQUAL(myrange[3].as_int(), 1);
167 BOOST_CHECK_EQUAL(myrange[4].as_int(), 2);
171 BOOST_CHECK_EQUAL(myslice[0].as_int(), 11);
172 BOOST_CHECK_EQUAL(myslice[1].as_int(), 13);
173 BOOST_CHECK_EQUAL(myslice[2].as_int(), 17);
174 BOOST_CHECK_EQUAL(myslice[3].as_int(), 19);
179 const std::string test =
"[(abc + 4 * (5+3))^2.0, functions, '[']thing[']']";
180 auto i1 = test.begin();
181 auto i2 = test.end();
182 const std::array<std::pair<std::string, token_type>, 25> tokens {{
209 for(
const auto& [str,
type] : tokens) {
211 assert(std::string(
t.begin,
t.end) == str);
212 assert(
t.type ==
type);
216 BOOST_AUTO_TEST_SUITE_END()
variant get_value(const std::string &key) const
variant get_value(const std::string &key) const
std::size_t num_elements() const
token get_token(iterator &i1, const iterator i2)
BOOST_AUTO_TEST_SUITE(filesystem)
static map_location::direction n