assimp/test/unit/utRemoveComments.cpp

57 lines
1.6 KiB
C++
Raw Normal View History

2015-05-19 04:24:07 +00:00
#include "UnitTestPCH.h"
#include <RemoveComments.h>
using namespace std;
using namespace Assimp;
// ------------------------------------------------------------------------------------------------
TEST(RemoveCommentsTest, testSingleLineComments)
{
2015-05-19 04:26:05 +00:00
const char* szTest = "int i = 0; \n"
"if (4 == //)\n"
"\ttrue) { // do something here \n"
"\t// hello ... and bye //\n";
2015-05-19 04:24:07 +00:00
2015-10-01 18:29:15 +00:00
const size_t len( ::strlen( szTest ) + 1 );
char* szTest2 = new char[ len ];
::strncpy( szTest2, szTest, len );
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
const char* szTestResult = "int i = 0; \n"
"if (4 == \n"
"\ttrue) { \n"
"\t \n";
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
CommentRemover::RemoveLineComments("//",szTest2,' ');
EXPECT_STREQ(szTestResult, szTest2);
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
delete[] szTest2;
2015-05-19 04:24:07 +00:00
}
// ------------------------------------------------------------------------------------------------
TEST(RemoveCommentsTest, testMultiLineComments)
{
2015-05-19 04:26:05 +00:00
const char* szTest =
"/* comment to be removed */\n"
"valid text /* \n "
" comment across multiple lines */"
" / * Incomplete comment */ /* /* multiple comments */ */";
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
const char* szTestResult =
" \n"
"valid text "
" "
" / * Incomplete comment */ */";
2015-05-19 04:24:07 +00:00
2015-10-01 18:29:15 +00:00
const size_t len( ::strlen( szTest ) + 1 );
char* szTest2 = new char[ len ];
::strncpy( szTest2, szTest, len );
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
CommentRemover::RemoveMultiLineComments("/*","*/",szTest2,' ');
EXPECT_STREQ(szTestResult, szTest2);
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
delete[] szTest2;
2015-05-19 04:24:07 +00:00
}