public void AppendLiteral()
        {
            var expected = new StringBuilder();
            var actual   = new StringBuilder();

            StringBuilder.AppendInterpolatedStringHandler iab = new StringBuilder.AppendInterpolatedStringHandler(0, 0, actual);

            foreach (string s in new[] { "", "a", "bc", "def", "this is a long string", "!" })
            {
                expected.Append(s);
                iab.AppendLiteral(s);
            }

            actual.Append(ref iab);

            Assert.Equal(expected.ToString(), actual.ToString());
        }
Exemple #2
0
        public void DebugHandler_AppendOverloads_MatchStringBuilderHandler()
        {
            var actual = new Debug.AssertInterpolatedStringHandler(0, 0, condition: false, out bool shouldAppend);

            Assert.True(shouldAppend);

            var sb       = new StringBuilder();
            var expected = new StringBuilder.AppendInterpolatedStringHandler(0, 0, sb);

            actual.AppendLiteral("abcd");
            expected.AppendLiteral("abcd");

            actual.AppendFormatted(123);
            expected.AppendFormatted(123);

            actual.AppendFormatted(45.6, 10);
            expected.AppendFormatted(45.6, 10);

            actual.AppendFormatted(default(Guid), "X");
            expected.AppendFormatted(default(Guid), "X");

            DateTime dt = DateTime.UtcNow;

            actual.AppendFormatted(dt, -100, "r");
            expected.AppendFormatted(dt, -100, "r");

            actual.AppendFormatted("hello");
            expected.AppendFormatted("hello");

            actual.AppendFormatted("world", -10, null);
            expected.AppendFormatted("world", -10, null);

            actual.AppendFormatted((ReadOnlySpan <char>) "nice to");
            expected.AppendFormatted((ReadOnlySpan <char>) "nice to");

            actual.AppendFormatted((ReadOnlySpan <char>) "nice to", 0, "anything");
            expected.AppendFormatted((ReadOnlySpan <char>) "nice to", 0, "anything");

            actual.AppendFormatted((object)DayOfWeek.Monday, 42, null);
            expected.AppendFormatted((object)DayOfWeek.Monday, 42, null);

            VerifyAssert(() => Debug.Assert(false, actual), sb.ToString());
        }
Exemple #3
0
 /// <summary>Writes the specified string to the handler.</summary>
 /// <param name="value">The string to write.</param>
 public void AppendLiteral(string value) => _stringBuilderHandler.AppendLiteral(value);