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.

TextBlockTest.cpp 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory>
  4. #include <string>
  5. #include "../../src/TextBlock.h"
  6. int main(void) {
  7. TextBlock jenny;
  8. size_t lines;
  9. if (jenny.getValue() != "") {
  10. std::cout << "FAIL Start: " << jenny.getValue() << std::endl;
  11. }
  12. lines = jenny.setValue("Everybody mad at the rocks that I wear");
  13. if (jenny.getValue() != "Everybody mad at the rocks that I wear") {
  14. std::cout << "FAIL SetSingle: " << lines << " " << jenny.getValue() << std::endl;
  15. }
  16. jenny.deleteAt(0, 0, 1);
  17. if (jenny.getValue() != "verybody mad at the rocks that I wear") {
  18. std::cout << "FAIL DelFirst: " << lines << " " << jenny.getValue() << std::endl;
  19. }
  20. jenny.deleteAt(jenny.getValue().size() -1, 0, 1);
  21. if (jenny.getValue() != "verybody mad at the rocks that I wea") {
  22. std::cout << "FAIL DelLast: " << lines << " " << jenny.getValue() << std::endl;
  23. }
  24. lines = jenny.setValue("Men go working\rSome go stealing");
  25. if (jenny.getValue() != "Men go working\rSome go stealing") {
  26. std::cout << "FAIL SetMutli: " << lines << " " << jenny.getValue() << std::endl;
  27. }
  28. lines = jenny.setValue("Men go working\rSome go stealing\r");
  29. if (jenny.getValue() != "Men go working\rSome go stealing\r") {
  30. std::cout << "FAIL SetMutliTrailing: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  31. }
  32. lines = jenny.setValue("");
  33. if (jenny.getValue() != "") {
  34. std::cout << "FAIL SetClear: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  35. }
  36. jenny.insertAt("r", 0, 0);
  37. if (jenny.getValue() != "r") {
  38. std::cout << "FAIL InsertChar: " << lines << " " << jenny.getValue() << std::endl;
  39. }
  40. jenny.insertAt("cha", 0, 0);
  41. if (jenny.getValue() != "char") {
  42. std::cout << "FAIL InsertString: " << lines << " " << jenny.getValue() << std::endl;
  43. }
  44. jenny.insertAt("s", jenny.getValue().size(), 0);
  45. if (jenny.getValue() != "chars") {
  46. std::cout << "FAIL AppendChar: " << lines << " " << jenny.getValue() << std::endl;
  47. }
  48. jenny.insertAt("tring", jenny.getValue().size(), 0);
  49. if (jenny.getValue() != "charstring") {
  50. std::cout << "FAIL AppendString: " << lines << " " << jenny.getValue() << std::endl;
  51. }
  52. lines = jenny.setValue("135");
  53. if (jenny.getValue() != "135") {
  54. std::cout << "FAIL SetClear: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  55. }
  56. jenny.insertAt("2", 1, 0);
  57. if (jenny.getValue() != "1235") {
  58. std::cout << "FAIL Insert2: " << lines << " " << jenny.getValue() << std::endl;
  59. }
  60. jenny.insertAt("4", 3, 0);
  61. if (jenny.getValue() != "12345") {
  62. std::cout << "FAIL Insert3: " << lines << " " << jenny.getValue() << std::endl;
  63. }
  64. jenny.deleteAt(3, 0, 1); // delete char we just added
  65. if (jenny.getValue() != "1235") {
  66. std::cout << "FAIL Delete3: " << lines << " " << jenny.getValue() << std::endl;
  67. }
  68. jenny.deleteAt(1, 0, 1); // delete char we just added
  69. if (jenny.getValue() != "135") {
  70. std::cout << "FAIL Delete1: " << lines << " " << jenny.getValue() << std::endl;
  71. }
  72. lines = jenny.setValue("asdf");
  73. if (jenny.getValue() != "asdf") {
  74. std::cout << "FAIL SetClear: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  75. }
  76. jenny.deleteAt(2, 0, 1); // delete char we just added
  77. if (jenny.getValue() != "asf") {
  78. std::cout << "FAIL Delete2: " << lines << " " << jenny.getValue() << std::endl;
  79. }
  80. lines = jenny.setValue("\r");
  81. if (jenny.getValue() != "\r") {
  82. std::cout << "FAIL SetNewline: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  83. }
  84. jenny.deleteAt(0, 0, 1); // delete char we just added
  85. if (jenny.getValue() != "") {
  86. std::cout << "FAIL DeleteLine: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  87. }
  88. lines = jenny.setValue("zxcv\rzxcv\r");
  89. //jenny.print();
  90. if (jenny.getValue() != "zxcv\rzxcv\r") {
  91. std::cout << "FAIL Set2Newline: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  92. }
  93. jenny.deleteAt(0, 2, 1); // delete char last trailing slash
  94. if (jenny.getValue() != "zxcv\rzxcv") {
  95. std::cout << "FAIL DeleteTrailingLine: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  96. }
  97. jenny.deleteAt(3, 1, 1); // delete char last trailing slash
  98. if (jenny.getValue() != "zxcv\rzxc") {
  99. std::cout << "FAIL Delete3: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  100. }
  101. jenny.deleteAt(2, 1, 1); // delete char last trailing slash
  102. if (jenny.getValue() != "zxcv\rzx") {
  103. std::cout << "FAIL Delete2: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  104. }
  105. jenny.deleteAt(1, 1, 1); // delete char last trailing slash
  106. if (jenny.getValue() != "zxcv\rz") {
  107. std::cout << "FAIL Delete1: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  108. }
  109. jenny.deleteAt(0, 1, 1); // delete char last trailing slash
  110. if (jenny.getValue() != "zxcv\r") {
  111. std::cout << "FAIL Delete0: " << lines << " [" << jenny.getValue() << "]" << std::endl;
  112. }
  113. return 0;
  114. }