@@ -715,13 +715,52 @@ public void testTrim() throws Exception {
715715
716716 c .getConsole ().setWaterMarks (50 , 100 );
717717 c .waitForScheduledJobs ();
718- c .verifyContentByOffset ("0123456789" , 0 );
718+ c .verifyContentByOffset ("0123456789" , 1 );
719719 assertTrue (c .getDocument ().getNumberOfLines () < 15 , "Document not trimmed." );
720720 }
721721 closeConsole (c );
722722 }
723723 }
724724
725+ /**
726+ * Check that trimming within a line doesn't split '\r\n'.
727+ */
728+ @ Test
729+ public void testTrimNewline () throws Exception {
730+ final IOConsoleTestUtil c = getTestUtil ("Test trim newline" );
731+ try (IOConsoleOutputStream out = c .getDefaultOutputStream ()) {
732+ c .writeFast ("first\n " );
733+ c .writeFast ("0123456789\r \n " , out );
734+ c .write ("last\n " );
735+ c .verifyContentByLine ("first" , 0 ).verifyContentByLine ("last" , -2 );
736+ assertTrue (c .getDocument ().getNumberOfLines () > 2 , "Document not filled." );
737+ c .getConsole ().setWaterMarks (6 , 16 );
738+ c .waitForScheduledJobs ();
739+ c .verifyContent ("\r \n last\n " );
740+ closeConsole (c );
741+ }
742+ }
743+
744+ /**
745+ * Check that trimming within a line doesn't split surrogate pairs, e.g.
746+ * emoji symbols.
747+ */
748+ @ Test
749+ public void testTrimSurrogateCharacters () throws Exception {
750+ final IOConsoleTestUtil c = getTestUtil ("Test trim newline" );
751+ try (IOConsoleOutputStream out = c .getDefaultOutputStream ()) {
752+ c .writeFast ("first\n " );
753+ c .writeFast ("1😀2😀3\n " , out );
754+ c .write ("last\n " );
755+ c .verifyContentByLine ("first" , 0 ).verifyContentByLine ("last" , -2 );
756+ assertTrue (c .getDocument ().getNumberOfLines () > 2 , "Document not filled." );
757+ c .getConsole ().setWaterMarks (8 , 16 );
758+ c .waitForScheduledJobs ();
759+ c .verifyContentByOffset ("😀3\n las" , 0 );
760+ closeConsole (c );
761+ }
762+ }
763+
725764 /**
726765 * Some extra tests for IOConsolePartitioner.
727766 */
0 commit comments