Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Adding test for StringBuilder.Clear() making sure Capacity wont grow unboundedly#28038

Merged
maryamariyan merged 3 commits into
dotnet:masterfrom
maryamariyan:improve-sbuilder
Mar 28, 2018
Merged

Adding test for StringBuilder.Clear() making sure Capacity wont grow unboundedly#28038
maryamariyan merged 3 commits into
dotnet:masterfrom
maryamariyan:improve-sbuilder

Conversation

@maryamariyan
Copy link
Copy Markdown

@maryamariyan maryamariyan commented Mar 14, 2018

Fixes #27625

Tests for PR dotnet/coreclr#16926

[Theory]
[InlineData(1)]
[InlineData(10000)]
public static void Clear_AppendAndInsertBeforeClearManyTimes_CapacityStaysWithinRange(int times)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to disable this for .NET Framework

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a note of the issue # fixing it, and that on NETFX you end up with 100042

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I would also add cases for the other possible outcomes of Clear (where we don't end up with ~1.2*Length of the original string)

@danmoseley
Copy link
Copy Markdown
Member

Please include link to CoreCLR fix in top comment

@danmoseley
Copy link
Copy Markdown
Member

Consider checking there is a test for this not throwing.

var sb = new StringBuilder(14, 14);
sb.Append("Hello world!!!");
sb.Clear();

}

[Theory]
[InlineData(14)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a Theory with only one value? That would normally be a fact, or you could add more data.

@maryamariyan maryamariyan force-pushed the improve-sbuilder branch 2 times, most recently from 2d225f3 to ac36217 Compare March 22, 2018 08:13
@maryamariyan maryamariyan changed the title Adding test for StringBuilder.Clear making sure Capacity wont grow unboundedly Adding test for StringBuilder.Clear() making sure Capacity wont grow unboundedly Mar 22, 2018
@maryamariyan maryamariyan reopened this Mar 24, 2018
@karelz karelz added this to the 2.1.0 milestone Mar 27, 2018
@maryamariyan maryamariyan reopened this Mar 27, 2018
@maryamariyan maryamariyan merged commit 87dac23 into dotnet:master Mar 28, 2018
@maryamariyan maryamariyan deleted the improve-sbuilder branch March 28, 2018 01:30
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…unboundedly (dotnet/corefx#28038)

* Adding test for StringBuilder.Clear making sure Capacity wont grow unboundedly. Fixes dotnet/corefx#27625

* Adding test for special case where the capacity corresponds to exactly chunk array size


Commit migrated from dotnet/corefx@87dac23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants