preprocessor: Created a simple test. But it fails currently.

This commit is contained in:
Daniel Marjamäki 2008-10-26 12:19:19 +00:00
parent 69e5e09581
commit f792bf4a0d
3 changed files with 48 additions and 0 deletions

View File

@ -17,5 +17,17 @@
*/ */
#include "preprocessor.h"
#include <sstream>
void preprocess(std::istream &istr, std::map<std::string, std::string> &result)
{
std::ostringstream ostr;
std::string line;
while ( getline(istr, line) )
ostr << line << "\n";
}

View File

@ -21,8 +21,13 @@
#define preprocessorH #define preprocessorH
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include <map>
#include <istream>
#include <string>
void preprocess(std::istream &istr, std::map<std::string, std::string> &result);
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #endif

View File

@ -24,6 +24,9 @@
#include "testsuite.h" #include "testsuite.h"
#include "preprocessor.h" #include "preprocessor.h"
#include <map>
#include <string>
class TestPreprocessor : public TestFixture class TestPreprocessor : public TestFixture
{ {
public: public:
@ -37,8 +40,36 @@ private:
TEST_CASE( test1 ); TEST_CASE( test1 );
} }
void check(const char filedata[], const std::map<std::string,std::string> &expected)
{
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
preprocess( istr, actual );
ASSERT_EQUALS( expected.size(), actual.size() );
for ( std::map<std::string,std::string>::const_iterator it = actual.begin(); it != actual.end(); ++it )
{
std::map<std::string,std::string>::const_iterator it2 = expected.find(it->first);
if ( it2 == expected.end() )
assertFail(__FILE__, __LINE__);
else
ASSERT_EQUALS( it->second, it2->second );
}
}
void test1() void test1()
{ {
const char filedata[] = "#ifdef WIN32\n"
" abcdef\n"
"#else\n"
" qwerty\n"
"#endif\n";
std::map<std::string, std::string> expected;
expected[""] = "\n\n\n qwerty\n\n";
expected["WIN32"] = "\n abcdef\n\n\n\n";
check( filedata, expected );
} }
}; };