From 373e611ace1ce46066c5e0d6fd163b9e28618838 Mon Sep 17 00:00:00 2001 From: Jozef Grajciar Date: Sun, 20 Jan 2019 11:37:17 +0100 Subject: [PATCH 1/2] Fix length calculation in case linebreak is first original fix by @Danielhu229 https://github.com/catchorg/Catch2/pull/1470 --- TextFlow.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TextFlow.hpp b/TextFlow.hpp index 41b7e30..96b09bf 100644 --- a/TextFlow.hpp +++ b/TextFlow.hpp @@ -78,6 +78,8 @@ namespace TextFlow { m_suffix = false; auto width = m_column.m_width-indent(); m_end = m_pos; + if(!line().empty() && line()[m_pos] == '\n') + ++m_end; while( m_end < line().size() && line()[m_end] != '\n' ) ++m_end; From c062f58c84c2421256f0868b0d5c6e35c8f7c7a7 Mon Sep 17 00:00:00 2001 From: Jozef Grajciar Date: Sun, 20 Jan 2019 11:52:59 +0100 Subject: [PATCH 2/2] Tests: added test for messages starting with linebreak --- TextFlow_Tests.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/TextFlow_Tests.cpp b/TextFlow_Tests.cpp index 414e1e0..0d1b475 100644 --- a/TextFlow_Tests.cpp +++ b/TextFlow_Tests.cpp @@ -279,6 +279,22 @@ TEST_CASE( "another long string" ) { " convallis posuere, libero nisi ultricies orci, nec lobortis." ); } +TEST_CASE( "message with linebreak at start" ) +{ + const auto message = std::string( + "\nthis is a message starting with linebreak" + ); + + auto col = Column( message ) + .width(79) + .indent(2); + + REQUIRE(col.toString() == + " \n" + "this is a message starting with linebreak" + ); +} + std::mt19937 rng; std::uniform_int_distribution wordCharGenerator(33,126); std::uniform_int_distribution wsGenerator(0, 11);