aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/ut/wrap.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/getopt/ut/wrap.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/getopt/ut/wrap.cpp')
-rw-r--r--library/cpp/getopt/ut/wrap.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/library/cpp/getopt/ut/wrap.cpp b/library/cpp/getopt/ut/wrap.cpp
new file mode 100644
index 0000000000..3444eea102
--- /dev/null
+++ b/library/cpp/getopt/ut/wrap.cpp
@@ -0,0 +1,96 @@
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <library/cpp/getopt/small/wrap.h>
+
+Y_UNIT_TEST_SUITE(Wrap) {
+ Y_UNIT_TEST(TestWrapping) {
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b c d eeffeff").Quote(),
+ TString("a b c\nd\neeffeff").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b\nc d\neeffeff").Quote(),
+ TString("a b\nc d\neeffeff").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b\n c d\neeffeff").Quote(),
+ TString("a b\n c\nd\neeffeff").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b\nx c d\neeffeff").Quote(),
+ TString("a b\nx\nc d\neeffeff").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b\nx \n c d\neeffeff").Quote(),
+ TString("a b\nx\n c\nd\neeffeff").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b\nx \n c d\neeffeff").Quote(),
+ TString("a b\nx\n c\nd\neeffeff").Quote()
+ );
+ }
+
+ Y_UNIT_TEST(TestWrappingIndent) {
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b c d", "|>").Quote(),
+ TString("a b\n|>c d").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b\n\nc d", "|>").Quote(),
+ TString("a b\n|>\n|>c d").Quote()
+ );
+ }
+
+ Y_UNIT_TEST(TestWrappingAnsi) {
+ UNIT_ASSERT_STRINGS_EQUAL(
+ 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(),
+ 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()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ 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(),
+ 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()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b \033[1;2;3;4;5m c d").Quote(),
+ TString("a b \033[1;2;3;4;5m\nc d").Quote()
+ );
+
+ UNIT_ASSERT_STRINGS_EQUAL(
+ NLastGetopt::Wrap(5, "a b \033[1;2;3;4;5m c d").Quote(),
+ TString("a b\n\033[1;2;3;4;5m c d").Quote()
+ );
+ }
+
+ Y_UNIT_TEST(TestTextInfo) {
+ size_t lastLineLen;
+ bool hasParagraphs;
+
+ NLastGetopt::Wrap(5, "a b c d e", "", &lastLineLen, &hasParagraphs);
+ UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 3);
+ UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, false);
+
+ NLastGetopt::Wrap(5, "a b c\n\nd e f h", "", &lastLineLen, &hasParagraphs);
+ UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 1);
+ UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, true);
+
+ NLastGetopt::Wrap(5, "a b c\n\n", "", &lastLineLen, &hasParagraphs);
+ UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 0);
+ UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, true);
+
+ NLastGetopt::Wrap(5, "\n \na b c", "", &lastLineLen, &hasParagraphs);
+ UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 5);
+ UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, true);
+
+ NLastGetopt::Wrap(5, "\nx\na b c", "", &lastLineLen, &hasParagraphs);
+ UNIT_ASSERT_VALUES_EQUAL(lastLineLen, 5);
+ UNIT_ASSERT_VALUES_EQUAL(hasParagraphs, false);
+ }
+}