Some unit test fixups

- WFL tokenizer had a conditionally-compiled test; this is now moved to the official unit tests
- MSVC was not including one of the unit test source files
This commit is contained in:
Celtic Minstrel 2017-03-16 14:56:38 -04:00
parent e16588812a
commit e0b85e5dda
4 changed files with 34 additions and 30 deletions

View file

@ -3345,6 +3345,11 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Tests\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Tests\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\tests\test_formula_core.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_with_VLD|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\tests\test_formula_function.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_with_VLD|Win32'">true</ExcludedFromBuild>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug_with_VLD|Win32'">$(IntDir)Tests\</ObjectFileName>

View file

@ -1522,6 +1522,9 @@
<ClCompile Include="..\..\src\font\text_surface.cpp">
<Filter>Font</Filter>
</ClCompile>
<ClCompile Include="..\..\src\tests\test_formula_core.cpp">
<Filter>Tests</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\addon\client.hpp">

View file

@ -283,33 +283,3 @@ token get_token(iterator& i1, const iterator i2) {
}
}
#ifdef UNIT_TEST_TOKENIZER
int main()
{
using namespace formula_tokenizer;
std::string test = "(abc + 4 * (5+3))^2";
std::string::const_iterator i1 = test.begin();
std::string::const_iterator i2 = test.end();
TOKEN_TYPE types[] = {TOKEN_LPARENS, TOKEN_IDENTIFIER,
TOKEN_WHITESPACE, TOKEN_OPERATOR,
TOKEN_WHITESPACE, TOKEN_INTEGER,
TOKEN_WHITESPACE, TOKEN_OPERATOR,
TOKEN_WHITESPACE, TOKEN_LPARENS,
TOKEN_INTEGER, TOKEN_OPERATOR,
TOKEN_INTEGER, TOKEN_RPARENS,
TOKEN_RPARENS, TOKEN_KEYWORD,
TOKEN_OPERATOR, TOKEN_INTEGER};
std::string tokens[] = {"(", "abc", " ", "+", " ", "4", " ",
"*", " ", "(", "5", "+", "3", ")", ")", "functions"};
for(int n = 0; n != sizeof(types)/sizeof(*types); ++n) {
token t = get_token(i1,i2);
assert(std::string(t.begin,t.end) == tokens[n]);
assert(t.type == types[n]);
}
return 0;
}
#endif

View file

@ -20,6 +20,7 @@
#include "formula/formula.hpp"
#include "formula/callable.hpp"
#include "formula/tokenizer.hpp"
using namespace game_logic;
@ -172,4 +173,29 @@ BOOST_AUTO_TEST_CASE(test_formula_containers) {
BOOST_CHECK_EQUAL(myslice[3].as_int(), 19);
}
BOOST_AUTO_TEST_CASE(test_formula_tokenizer) {
using namespace formula_tokenizer;
std::string test = "(abc + 4 * (5+3))^2";
std::string::const_iterator i1 = test.begin();
std::string::const_iterator i2 = test.end();
TOKEN_TYPE types[] = {TOKEN_LPARENS, TOKEN_IDENTIFIER,
TOKEN_WHITESPACE, TOKEN_OPERATOR,
TOKEN_WHITESPACE, TOKEN_INTEGER,
TOKEN_WHITESPACE, TOKEN_OPERATOR,
TOKEN_WHITESPACE, TOKEN_LPARENS,
TOKEN_INTEGER, TOKEN_OPERATOR,
TOKEN_INTEGER, TOKEN_RPARENS,
TOKEN_RPARENS, TOKEN_KEYWORD,
TOKEN_OPERATOR, TOKEN_INTEGER};
std::string tokens[] = {"(", "abc", " ", "+", " ", "4", " ",
"*", " ", "(", "5", "+", "3", ")", ")", "functions"};
for(std::string tok : tokens) {
token t = get_token(i1, i2);
assert(std::string(t.begin, t.end) == tokens[n]);
assert(t.type == types[n]);
}
return 0;
}
BOOST_AUTO_TEST_SUITE_END()