public void TestEmptyChunksIgnored()
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object> {
                { "tag", Resolution.Empty }
            };

            FormatBuilder builder = new FormatBuilder(100, 4, firstLineIndentSize: 4)
                                    .AppendFormat("Text{tag}text");

            Assert.AreEqual("    Texttext", builder.ToString(dictionary));

            builder.Clear();
            builder.AppendFormat("Text{tag}");

            Assert.AreEqual("    Text", builder.ToString(dictionary));

            builder.Clear();
            builder.AppendFormat("Text{tag: sub {tag}}");

            Assert.AreEqual("    Text sub ", builder.ToString(dictionary));

            builder.Clear();
            builder.AppendFormat("Text{tag:{<items>:{<item>}}}");

            Assert.AreEqual("    Text", builder.ToString(dictionary));
        }
Пример #2
0
        public void TestResolveObjects()
        {
            TestClass tc = new TestClass(123, true, new List <int> {
                1, 1, 2, 3, 5, 8
            });
            FormatBuilder builder = new FormatBuilder();

            builder.AppendFormat(
                "{0:({Number:N2}, {Boolean}) [{List:{<items>:{<item>}}{<join>:,}}]}",
                tc);
            Assert.AreEqual("(123.00, True) [1,1,2,3,5,8]", builder.ToString());

            builder.Clear();
            builder.AppendFormat(
                "{0:Count: {Count} \\{ {<items>:\\{{Key}: {Value}\\}}{<join>:, } \\}}",
                new Dictionary <string, int>
            {
                { "Foo", 123 },
                { "Bar", 456 },
                { "Test", 789 }
            });
            Assert.AreEqual("Count: 3 { {Foo: 123}, {Bar: 456}, {Test: 789} }", builder.ToString());

            builder.Clear();
            builder.AppendFormat(
                "Length: {0:{Length}} \"{0}\"",
                FormatResources.LoremIpsum);
            Assert.AreEqual(string.Format("Length: {0} \"{1}\"", FormatResources.LoremIpsum.Length, FormatResources.LoremIpsum), builder.ToString());
        }
        public void TestAlignment()
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object> {
                { "tag", "1" }
            };
            FormatBuilder builder = new FormatBuilder("{tag,3}");

            Assert.AreEqual("  1", builder.ToString(dictionary));
            builder.Clear();

            builder.AppendFormat("{tag,-3}");
            Assert.AreEqual("1  ", builder.ToString(dictionary));
            builder.Clear();

            builder.AppendFormat("{tag,3:2{tag}}");
            Assert.AreEqual(" 21", builder.ToString(dictionary));
            builder.Clear();

            builder.AppendFormat("{tag,-3:2{tag}}");
            Assert.AreEqual("21 ", builder.ToString(dictionary));
            builder.Clear();
        }
Пример #4
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());
            }
        }
Пример #5
0
        public void TestResolveObjects()
        {
            TestClass tc = new TestClass(123, true, new List<int>{1, 1, 2, 3, 5, 8});
            FormatBuilder builder = new FormatBuilder();
            builder.AppendFormat(
                "{0:({Number:N2}, {Boolean}) [{List:{<items>:{<item>}}{<join>:,}}]}",
                tc);
            Assert.AreEqual("(123.00, True) [1,1,2,3,5,8]", builder.ToString());

            builder.Clear();
            builder.AppendFormat(
                "{0:Count: {Count} \\{ {<items>:\\{{Key}: {Value}\\}}{<join>:, } \\}}",
                new Dictionary<string, int>
                {
                    {"Foo", 123},
                    {"Bar", 456},
                    {"Test", 789}
                });
            Assert.AreEqual("Count: 3 { {Foo: 123}, {Bar: 456}, {Test: 789} }", builder.ToString());

            builder.Clear();
            builder.AppendFormat(
                "Length: {0:{Length}} \"{0}\"",
                FormatResources.LoremIpsum);
            Assert.AreEqual(string.Format("Length: {0} \"{1}\"", FormatResources.LoremIpsum.Length, FormatResources.LoremIpsum), builder.ToString());
        }
Пример #6
0
 /// <summary>
 /// Writes the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 public override void Write(bool value)
 {
     Debug.Assert(Builder.IsEmpty);
     Builder.Append(value);
     Position = Builder.WriteTo(_writer, null, Position);
     Builder.Clear();
 }
        public void TestAlignment()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object> { { "tag", "1" } };
            FormatBuilder builder = new FormatBuilder("{tag,3}");
            Assert.AreEqual("  1",builder.ToString(dictionary));
            builder.Clear();

            builder.AppendFormat("{tag,-3}");
            Assert.AreEqual("1  ", builder.ToString(dictionary));
            builder.Clear();

            builder.AppendFormat("{tag,3:2{tag}}");
            Assert.AreEqual(" 21", builder.ToString(dictionary));
            builder.Clear();

            builder.AppendFormat("{tag,-3:2{tag}}");
            Assert.AreEqual("21 ", builder.ToString(dictionary));
            builder.Clear();
        }
        public void TestEmptyChunksIgnored()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object> { { "tag", Resolution.Empty } };

            FormatBuilder builder = new FormatBuilder(100, 4, firstLineIndentSize: 4)
                .AppendFormat("Text{tag}text");

            Assert.AreEqual("    Texttext", builder.ToString(dictionary));

            builder.Clear();
            builder.AppendFormat("Text{tag}");

            Assert.AreEqual("    Text", builder.ToString(dictionary));

            builder.Clear();
            builder.AppendFormat("Text{tag: sub {tag}}");

            Assert.AreEqual("    Text sub ", builder.ToString(dictionary));

            builder.Clear();
            builder.AppendFormat("Text{tag:{<items>:{<item>}}}");

            Assert.AreEqual("    Text", builder.ToString(dictionary));
        }
Пример #9
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());
            }
        }