public void TestThatAppendingLineInsertsNewLine()
        {
            var builder = new ColoredMultistringBuilder();

            builder.AppendLine(Enumerable.Empty <ColoredMultistring>());

            builder.ShouldProduce(new ColoredString(Environment.NewLine));
        }
        public void TestAppendingBareStringYieldsColorlessMultistring()
        {
            var builder = new ColoredMultistringBuilder();

            builder.Append(anyString);

            builder.ShouldProduce(new ColoredString(anyString, null, null));
        }
        public void TestAppendingMultipleCharsAppendsSingleColorlessString()
        {
            const int anyCharCount = 3;

            var builder = new ColoredMultistringBuilder();

            builder.Append(anyChar, anyCharCount);

            builder.ShouldProduce(new ColoredString(new string(anyChar, anyCharCount)));
        }
        public void TestRemovingZeroLengthPreservesBuilderContent()
        {
            var builder = new ColoredMultistringBuilder();

            builder.Append(anyArrayOfMultipleColoredStrings);

            builder.Remove(0, 0);

            builder.ShouldProduce(anyArrayOfMultipleColoredStrings);
        }
        public void TestStringInsertionAtStartOfBuilder()
        {
            var builder = new ColoredMultistringBuilder();

            builder.Append(anyArrayOfMultipleColoredStrings);

            builder.Insert(0, anyString);

            builder.ShouldProduce(
                new ColoredString[] { anyString }.Concat(anyArrayOfMultipleColoredStrings));
        }
        public void TestAppendingMultistringAddsItsPieces()
        {
            var anyColoredStrings = anyArrayOfMultipleColoredStrings;
            var anyMultistring    = new ColoredMultistring(anyColoredStrings);

            var builder = new ColoredMultistringBuilder();

            builder.Append(anyMultistring);

            builder.ShouldProduce(anyMultistring.Content);
        }
        public void TestRemovingAcrossPieces()
        {
            var builder = new ColoredMultistringBuilder();

            builder.Append(anyArrayOfMultipleColoredStrings);

            builder.Remove(1, builder.Length - 2);
            builder.ShouldProduce(
                anyArrayOfMultipleColoredStrings[0].Substring(0, 1),
                anyArrayOfMultipleColoredStrings.Last().Substring(anyArrayOfMultipleColoredStrings.Last().Length - 1));
        }
        public void TestStringInsertionAtEndOfBuilder()
        {
            var builder = new ColoredMultistringBuilder();

            builder.Append(anyArrayOfMultipleColoredStrings);

            builder.Insert(builder.Length, anyString);

            builder.ShouldProduce(
                anyArrayOfMultipleColoredStrings.Concat(new ColoredString[] { anyString }));
        }
        public void TestStringInsertionInMiddleOfPieceWithSameColor()
        {
            var cs = new ColoredString("abc");

            var builder = new ColoredMultistringBuilder();

            builder.Append(cs);

            builder.Insert(1, "de");

            builder.ShouldProduce("adebc");
        }
        public void TestAppendingMultiplePiecesInOneOperationYieldsSameAsMultipleAppends()
        {
            var anyStrings        = anyArrayOfMultipleStrings;
            var mergedString      = string.Join(string.Empty, anyStrings);
            var anyColoredStrings = anyArrayOfMultipleColoredStrings;

            var builder = new ColoredMultistringBuilder();

            builder.Append(anyColoredStrings);

            builder.ShouldProduce(anyColoredStrings);
        }
        public void TestTruncationTrimsContentFromLastPiece()
        {
            var anyFirstCs  = AnyColoredString("ab");
            var anySecondCs = AnyColoredString("cde");

            var builder = new ColoredMultistringBuilder();

            builder.Append(new[] { anyFirstCs, anySecondCs });

            builder.Truncate(3);
            builder.ShouldProduce(
                anyFirstCs,
                anySecondCs.WithContent("c"));
        }
        public void TestStringInsertionInMiddleOfPieceWithDifferentColor()
        {
            var cs = AnyColoredString("abc");

            var builder = new ColoredMultistringBuilder();

            builder.Append(cs);

            builder.Insert(1, "de");

            builder.ShouldProduce(
                cs.Transform(_ => "a"),
                "de",
                cs.Transform(_ => "bc"));
        }
        public void TestCharInsertionInMiddleOfPieceWithDifferentColor()
        {
            var cs = AnyColoredString("abc");

            var builder = new ColoredMultistringBuilder();

            builder.Append(cs);

            builder.Insert(1, 'x');

            builder.ShouldProduce(
                cs.WithContent("a"),
                new ColoredString("x"),
                cs.WithContent("bc"));
        }
        public void TestIterativelyAppendingMultiplePiecesWithSameColorMergesStrings()
        {
            var anyStrings        = anyArrayOfMultipleStrings;
            var mergedString      = string.Join(string.Empty, anyStrings);
            var anyColoredStrings = anyArrayOfMultipleColoredStrings;

            var builder = new ColoredMultistringBuilder();

            foreach (var cs in anyColoredStrings)
            {
                builder.Append(cs);
            }

            builder.Length.Should().Be(mergedString.Length);
            builder.ToString().Should().Be(mergedString);
            builder.ShouldProduce(anyColoredStrings);
        }
        public void TestRemovingMiddleOfPiecePreservesSurroundingText()
        {
            var builder = new ColoredMultistringBuilder();

            const string anyString = "SomeStringWithLength";
            var          piece     = new ColoredString(anyString, Any.Enum <ConsoleColor>());

            const int removeIndex  = 2;
            const int removeLength = 3;

            builder.Append(piece);
            builder.Remove(removeIndex, removeLength);

            builder.ShouldProduce(new ColoredString(
                                      anyString.Remove(removeIndex, removeLength),
                                      piece.ForegroundColor, piece.BackgroundColor));
        }
        public void TestIndexSetOperationUpdatesBuilder()
        {
            const char anyUpdatedChar = 'Y';

            var anyFirstString  = AnyColoredString("abc");
            var anySecondString = AnyColoredString("defg");

            var builder = new ColoredMultistringBuilder();

            builder.Append(new ColoredString[] { anyFirstString, anySecondString });

            builder[0] = anyUpdatedChar;
            builder[6] = anyUpdatedChar;

            builder.ShouldProduce(
                anyFirstString.WithContent("Ybc"),
                anySecondString.WithContent("defY"));
        }
        public void TestAppendingMultipleMultistrings()
        {
            var anyColoredStrings = anyArrayOfMultipleColoredStrings;
            var anyMultistring    = new ColoredMultistring(anyColoredStrings);

            var anyOtherArrayOfMultipleColoredStrings = new[]
            {
                new ColoredString("Another", ConsoleColor.Cyan),
                new ColoredString("string", ConsoleColor.Gray)
            };

            var anyOtherMultistring = new ColoredMultistring(anyOtherArrayOfMultipleColoredStrings);

            var builder = new ColoredMultistringBuilder();

            builder.Append(new[] { anyMultistring, anyOtherMultistring });

            builder.ShouldProduce(anyColoredStrings.Concat(anyOtherMultistring.Content));
        }