diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 7b1ed2731dd8..16c850de7a60 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -7584,6 +7584,12 @@ public StringBuilder(string value, int startIndex, int length, int capacity) { } public System.Text.StringBuilder AppendJoin(string separator, System.Collections.Generic.IEnumerable values) { throw null; } public System.Text.StringBuilder AppendLine() { throw null; } public System.Text.StringBuilder AppendLine(string value) { throw null; } + public struct ChunkEnumerator + { + public ChunkEnumerator GetEnumerator() { throw null; } + public bool MoveNext() { throw null; } + public ReadOnlyMemory Current { get { throw null; } } + } public System.Text.StringBuilder Clear() { throw null; } public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) { } public void CopyTo(int sourceIndex, System.Span destination, int count) { } @@ -7613,6 +7619,7 @@ public void CopyTo(int sourceIndex, System.Span destination, int count) { public System.Text.StringBuilder Insert(int index, uint value) { throw null; } [System.CLSCompliantAttribute(false)] public System.Text.StringBuilder Insert(int index, ulong value) { throw null; } + public ChunkEnumerator GetChunks() { throw null; } public System.Text.StringBuilder Remove(int startIndex, int length) { throw null; } public System.Text.StringBuilder Replace(char oldChar, char newChar) { throw null; } public System.Text.StringBuilder Replace(char oldChar, char newChar, int startIndex, int count) { throw null; } diff --git a/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt b/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt index e69de29bb2d1..09fe0101d505 100644 --- a/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt +++ b/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt @@ -0,0 +1,4 @@ +Compat issues with assembly System.Runtime: +MembersMustExist : Member 'System.Text.StringBuilder.GetChunks()' does not exist in the implementation but it does exist in the contract. +TypesMustExist : Type 'System.Text.StringBuilder.ChunkEnumerator' does not exist in the implementation but it does exist in the contract. +Total Issues: 12 diff --git a/src/System.Runtime/tests/System/Text/StringBuilderTests.netcoreapp.cs b/src/System.Runtime/tests/System/Text/StringBuilderTests.netcoreapp.cs index 848cd2888be6..2bc17afcf592 100644 --- a/src/System.Runtime/tests/System/Text/StringBuilderTests.netcoreapp.cs +++ b/src/System.Runtime/tests/System/Text/StringBuilderTests.netcoreapp.cs @@ -388,5 +388,34 @@ public static void Equals(StringBuilder sb1, string value, bool expected) { Assert.Equal(expected, sb1.Equals(value.AsSpan())); } + + [Fact] + public static void ForEach() + { + // Test on a variety of lengths, at least up to the point of 9 8K chunks = 72K because this is where + // we start using a different technique for creating the ChunkEnumerator. 200 * 500 = 100K which hits this. + for (int i = 0; i < 200; i++) + { + StringBuilder inBuilder = new StringBuilder(); + for (int j = 0; j < i; j++) + { + // Make some unique strings that are at least 500 bytes long. + inBuilder.Append(j); + inBuilder.Append("_abcdefghijklmnopqrstuvwxyz01234567890__Abcdefghijklmnopqrstuvwxyz01234567890__ABcdefghijklmnopqrstuvwxyz01_"); + inBuilder.Append("_abcdefghijklmnopqrstuvwxyz01234567890__Abcdefghijklmnopqrstuvwxyz01234567890__ABcdefghijklmnopqrstuvwxyz0123_"); + inBuilder.Append("_abcdefghijklmnopqrstuvwxyz01234567890__Abcdefghijklmnopqrstuvwxyz01234567890__ABcdefghijklmnopqrstuvwxyz012345_"); + inBuilder.Append("_abcdefghijklmnopqrstuvwxyz01234567890__Abcdefghijklmnopqrstuvwxyz01234567890__ABcdefghijklmnopqrstuvwxyz012345678_"); + inBuilder.Append("_abcdefghijklmnopqrstuvwxyz01234567890__Abcdefghijklmnopqrstuvwxyz01234567890__ABcdefghijklmnopqrstuvwxyz01234567890_"); + } + + // Copy the string out (not using StringBuilder). + string outStr = ""; + foreach (ReadOnlyMemory chunk in inBuilder.GetChunks()) + outStr += new string(chunk.Span); + + // The strings formed by concatenating the chunks should be the same as the value in the StringBuilder. + Assert.Equal(outStr, inBuilder.ToString()); + } + } } }