wrap.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include <library/cpp/getopt/small/wrap.h>
  3. Y_UNIT_TEST_SUITE(Wrap) {
  4. Y_UNIT_TEST(TestWrapping) {
  5. UNIT_ASSERT_STRINGS_EQUAL(
  6. NLastGetopt::Wrap(5, "a b c d eeffeff").Quote(),
  7. TString("a b c\nd\neeffeff").Quote()
  8. );
  9. UNIT_ASSERT_STRINGS_EQUAL(
  10. NLastGetopt::Wrap(5, "a b\nc d\neeffeff").Quote(),
  11. TString("a b\nc d\neeffeff").Quote()
  12. );
  13. UNIT_ASSERT_STRINGS_EQUAL(
  14. NLastGetopt::Wrap(5, "a b\n c d\neeffeff").Quote(),
  15. TString("a b\n c\nd\neeffeff").Quote()
  16. );
  17. UNIT_ASSERT_STRINGS_EQUAL(
  18. NLastGetopt::Wrap(5, "a b\nx c d\neeffeff").Quote(),
  19. TString("a b\nx\nc d\neeffeff").Quote()
  20. );
  21. UNIT_ASSERT_STRINGS_EQUAL(
  22. NLastGetopt::Wrap(5, "a b\nx \n c d\neeffeff").Quote(),
  23. TString("a b\nx\n c\nd\neeffeff").Quote()
  24. );
  25. UNIT_ASSERT_STRINGS_EQUAL(
  26. NLastGetopt::Wrap(5, "a b\nx \n c d\neeffeff").Quote(),
  27. TString("a b\nx\n c\nd\neeffeff").Quote()
  28. );
  29. }
  30. Y_UNIT_TEST(TestWrappingIndent) {
  31. UNIT_ASSERT_STRINGS_EQUAL(
  32. NLastGetopt::Wrap(5, "a b c d", "|>").Quote(),
  33. TString("a b\n|>c d").Quote()
  34. );
  35. UNIT_ASSERT_STRINGS_EQUAL(
  36. NLastGetopt::Wrap(5, "a b\n\nc d", "|>").Quote(),
  37. TString("a b\n|>\n|>c d").Quote()
  38. );
  39. }
  40. Y_UNIT_TEST(TestWrappingAnsi) {
  41. UNIT_ASSERT_STRINGS_EQUAL(
  42. NLastGetopt::Wrap(5, "\033[1;2;3;4;5mx\033[1;2;3;4;5mx\033[1;2;3;4;5mx\033[1;2;3;4;5mx\033[1;2;3;4;5m").Quote(),
  43. TString("\033[1;2;3;4;5mx\033[1;2;3;4;5mx\033[1;2;3;4;5mx\033[1;2;3;4;5mx\033[1;2;3;4;5m").Quote()
  44. );
  45. UNIT_ASSERT_STRINGS_EQUAL(
  46. NLastGetopt::Wrap(5, "a \033[1;2;3;4;5mb c\033[1;2;3;4;5m \033[1;2;3;4;5md e f").Quote(),
  47. TString("a \033[1;2;3;4;5mb c\033[1;2;3;4;5m\n\033[1;2;3;4;5md e f").Quote()
  48. );
  49. UNIT_ASSERT_STRINGS_EQUAL(
  50. NLastGetopt::Wrap(5, "a b \033[1;2;3;4;5m c d").Quote(),
  51. TString("a b \033[1;2;3;4;5m\nc d").Quote()
  52. );
  53. UNIT_ASSERT_STRINGS_EQUAL(
  54. NLastGetopt::Wrap(5, "a b \033[1;2;3;4;5m c d").Quote(),
  55. TString("a b\n\033[1;2;3;4;5m c d").Quote()
  56. );
  57. }
  58. Y_UNIT_TEST(TestTextInfo) {
  59. size_t lastLineLen;
  60. bool hasParagraphs;
  61. NLastGetopt::Wrap(5, "a b c d e", "", &lastLineLen, &hasParagraphs);
  62. UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 3);
  63. UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, false);
  64. NLastGetopt::Wrap(5, "a b c\n\nd e f h", "", &lastLineLen, &hasParagraphs);
  65. UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 1);
  66. UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, true);
  67. NLastGetopt::Wrap(5, "a b c\n\n", "", &lastLineLen, &hasParagraphs);
  68. UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 0);
  69. UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, true);
  70. NLastGetopt::Wrap(5, "\n \na b c", "", &lastLineLen, &hasParagraphs);
  71. UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 5);
  72. UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, true);
  73. NLastGetopt::Wrap(5, "\nx\na b c", "", &lastLineLen, &hasParagraphs);
  74. UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 5);
  75. UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, false);
  76. }
  77. }