ToString() public method

public ToString ( ) : string
return string
Example #1
0
        public void TestResolveControlChunk()
        {
            FormatBuilder builder = new FormatBuilder()
                                    .AppendFormat("{" + FormatBuilder.ForegroundColorTag + ":Custom}")
                                    .Resolve(
                (_, c) =>
            {
                if (string.Equals(
                        c.Tag,
                        FormatBuilder.ForegroundColorTag,
                        StringComparison.CurrentCultureIgnoreCase) &&
                    string.Equals(c.Format, "Custom"))
                {
                    return(Color.Green);
                }
                return(Resolution.Unknown);
            },
                false,
                true);

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);
                Assert.AreEqual("{fg:Green}", writer.ToString());
            }
        }
Example #2
0
        public void TestReplaceColor()
        {
            FormatBuilder builder = new FormatBuilder()
                                    .Append("Some text. ")
                                    .AppendForegroundColor(Color.Red)
                                    .Append("Some red text. ")
                                    .AppendForegroundColor(Color.Green)
                                    .AppendLine("Some green text.");

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);

                Assert.AreEqual(
                    "Some text. {fg:Red}Some red text. {fg:Green}Some green text.\r\n",
                    writer.ToString());
            }

            builder.Resolve(
                (_, c) =>
                string.Equals(
                    c.Tag,
                    FormatBuilder.ForegroundColorTag,
                    StringComparison.CurrentCultureIgnoreCase) &&
                string.Equals(
                    c.Format,
                    "Green",
                    StringComparison.CurrentCultureIgnoreCase)
                        ? new FormatChunk(c, Color.Blue)
                        : Resolution.UnknownYet,
                resolveControls: true);

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);

                Assert.AreEqual(
                    "Some text. {fg:Red}Some red text. {fg:Blue}Some green text.\r\n",
                    writer.ToString());
            }
        }
Example #3
0
        public void TestTrailingControlChunks()
        {
            FormatBuilder builder = new FormatBuilder(100)
                                    .Append("Text")
                                    .AppendFormat("{" + FormatBuilder.ForegroundColorTag + "}");

            using (TestColoredTextWriter writer = new TestColoredTextWriter())
            {
                builder.WriteTo(writer);
                Assert.AreEqual("Text{/fg}", writer.ToString());
            }

            builder.Clear();
            builder.AppendLine("Text")
            .AppendFormat("{" + FormatBuilder.ForegroundColorTag + "}");

            using (TestColoredTextWriter writer = new TestColoredTextWriter())
            {
                builder.WriteTo(writer);
                Assert.AreEqual("Text\r\n{/fg}", writer.ToString());
            }
        }
Example #4
0
        public void TestColoredWriter()
        {
            FormatBuilder builder = new FormatBuilder()
                                    .Append("Some normal text, ")
                                    .AppendForegroundColor(Color.Red)
                                    .Append("some red text, ")
                                    .AppendResetForegroundColor()
                                    .Append("some more normal text, ")
                                    .AppendForegroundColor(Color.Green)
                                    .Append("some green ")
                                    .AppendBackgroundColor(Color.Blue)
                                    .Append("and some blue ")
                                    .AppendResetBackgroundColor()
                                    .AppendLine("and back to green.");

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);

                Assert.AreEqual(
                    "Some normal text, {fg:Red}some red text, {/fg}some more normal text, {fg:Green}some green {bg:Blue}and some blue {/bg}and back to green.\r\n",
                    writer.ToString());
            }
        }
Example #5
0
        public void TestReplaceColor()
        {
            FormatBuilder builder = new FormatBuilder()
                .Append("Some text. ")
                .AppendForegroundColor(Color.Red)
                .Append("Some red text. ")
                .AppendForegroundColor(Color.Green)
                .AppendLine("Some green text.");

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);

                Assert.AreEqual(
                    "Some text. {fg:Red}Some red text. {fg:Green}Some green text.\r\n",
                    writer.ToString());
            }

            builder.Resolve(
                (_, c) =>
                    string.Equals(
                        c.Tag,
                        FormatBuilder.ForegroundColorTag,
                        StringComparison.CurrentCultureIgnoreCase) &&
                    string.Equals(
                        c.Format,
                        "Green",
                        StringComparison.CurrentCultureIgnoreCase)
                        ? new FormatChunk(c, Color.Blue)
                        : Resolution.UnknownYet,
                resolveControls: true);

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);

                Assert.AreEqual(
                    "Some text. {fg:Red}Some red text. {fg:Blue}Some green text.\r\n",
                    writer.ToString());
            }
        }
Example #6
0
        public void TestColoredWriter()
        {
            FormatBuilder builder = new FormatBuilder()
                .Append("Some normal text, ")
                .AppendForegroundColor(Color.Red)
                .Append("some red text, ")
                .AppendResetForegroundColor()
                .Append("some more normal text, ")
                .AppendForegroundColor(Color.Green)
                .Append("some green ")
                .AppendBackgroundColor(Color.Blue)
                .Append("and some blue ")
                .AppendResetBackgroundColor()
                .AppendLine("and back to green.");

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);

                Assert.AreEqual(
                    "Some normal text, {fg:Red}some red text, {/fg}some more normal text, {fg:Green}some green {bg:Blue}and some blue {/bg}and back to green.\r\n",
                    writer.ToString());
            }
        }
        public void TestTrailingControlChunks()
        {
            FormatBuilder builder = new FormatBuilder(100)
                .Append("Text")
                .AppendFormat("{" + FormatBuilder.ForegroundColorTag + "}");

            using (TestColoredTextWriter writer = new TestColoredTextWriter())
            {
                builder.WriteTo(writer);
                Assert.AreEqual("Text{/fg}", writer.ToString());
            }

            builder.Clear();
            builder.AppendLine("Text")
                .AppendFormat("{" + FormatBuilder.ForegroundColorTag + "}");

            using (TestColoredTextWriter writer = new TestColoredTextWriter())
            {
                builder.WriteTo(writer);
                Assert.AreEqual("Text\r\n{/fg}", writer.ToString());
            }
        }
        public void TestResolveControlChunk()
        {
            FormatBuilder builder = new FormatBuilder()
                .AppendFormat("{" + FormatBuilder.ForegroundColorTag + ":Custom}")
                .Resolve(
                    (_, c) =>
                    {
                        if (string.Equals(
                            c.Tag,
                            FormatBuilder.ForegroundColorTag,
                            StringComparison.CurrentCultureIgnoreCase) &&
                            string.Equals(c.Format, "Custom"))
                            return Color.Green;
                        return Resolution.Unknown;
                    },
                    false,
                    true);

            using (TestColoredTextWriter writer = new TestColoredTextWriter(true))
            {
                builder.WriteTo(writer);
                Assert.AreEqual("{fg:Green}", writer.ToString());
            }
        }