You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.8 KiB

  1. #include "UnitTestPCH.h"
  2. #include "utRemoveComments.h"
  3. CPPUNIT_TEST_SUITE_REGISTRATION (RemoveCommentsTest);
  4. // ------------------------------------------------------------------------------------------------
  5. void RemoveCommentsTest :: setUp (void)
  6. {
  7. // nothing to do here
  8. }
  9. // ------------------------------------------------------------------------------------------------
  10. void RemoveCommentsTest :: tearDown (void)
  11. {
  12. // nothing to do here
  13. }
  14. // ------------------------------------------------------------------------------------------------
  15. void RemoveCommentsTest :: testSingleLineComments (void)
  16. {
  17. const char* szTest = "int i = 0; \n"
  18. "if (4 == //)\n"
  19. "\ttrue) { // do something here \n"
  20. "\t// hello ... and bye //\n";
  21. char* szTest2 = new char[::strlen(szTest)+1];
  22. ::strcpy(szTest2,szTest);
  23. const char* szTestResult = "int i = 0; \n"
  24. "if (4 == \n"
  25. "\ttrue) { \n"
  26. "\t \n";
  27. CommentRemover::RemoveLineComments("//",szTest2,' ');
  28. CPPUNIT_ASSERT(0 == ::strcmp(szTest2,szTestResult));
  29. delete[] szTest2;
  30. }
  31. // ------------------------------------------------------------------------------------------------
  32. void RemoveCommentsTest :: testMultiLineComments (void)
  33. {
  34. char* szTest =
  35. "/* comment to be removed */\n"
  36. "valid text /* \n "
  37. " comment across multiple lines */"
  38. " / * Incomplete comment */ /* /* multiple comments */ */";
  39. const char* szTestResult =
  40. " \n"
  41. "valid text "
  42. " "
  43. " / * Incomplete comment */ */";
  44. char* szTest2 = new char[::strlen(szTest)+1];
  45. ::strcpy(szTest2,szTest);
  46. CommentRemover::RemoveMultiLineComments("/*","*/",szTest2,' ');
  47. CPPUNIT_ASSERT(0 == ::strcmp(szTest2,szTestResult));
  48. delete[] szTest2;
  49. }