public void TrimRemovesLeadingAndTrailingWhiteSpace(InterningTestData.TestDatum datum) { SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum); stringBuilder.Trim(); new InternableString(stringBuilder).ExpensiveConvertToString().ShouldBe(datum.ToString().Trim()); }
public void ClearRemovesAllCharacters(InterningTestData.TestDatum datum) { SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum); stringBuilder.Clear(); stringBuilder.Length.ShouldBe(0); stringBuilder.GetEnumerator().MoveNext().ShouldBeFalse(); }
public void EnumeratorEnumeratesCharacters(InterningTestData.TestDatum datum) { SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum); int index = 0; foreach (char ch in stringBuilder) { ch.ShouldBe(datum[index]); index++; } }
public void EqualsReturnsExpectedValue(InterningTestData.TestDatum datum) { InternableString internableString = new InternableString(MakeSpanBasedStringBuilder(datum)); internableString.Equals(string.Empty).ShouldBe(internableString.Length == 0); string substr = datum.Fragments[0] ?? string.Empty; internableString.Equals(substr).ShouldBe(substr.Length == internableString.Length); if (datum.Fragments.Length > 1) { substr += datum.Fragments[1]; internableString.Equals(substr).ShouldBe(substr.Length == internableString.Length); internableString.Equals(datum.ToString()).ShouldBeTrue(); } internableString.Equals("Things").ShouldBeFalse(); }
private SpanBasedStringBuilder MakeSpanBasedStringBuilder(InterningTestData.TestDatum datum, bool appendSubStrings = false) { bool wrapFirstFragment = datum.Fragments.Length > 0 && datum.Fragments[0] != null; SpanBasedStringBuilder stringBuilder = wrapFirstFragment ? new SpanBasedStringBuilder(datum.Fragments[0]) : new SpanBasedStringBuilder(); for (int i = 1; i < datum.Fragments.Length; i++) { if (appendSubStrings) { int index = datum.Fragments[i].Length / 2; stringBuilder.Append(datum.Fragments[i], 0, index); stringBuilder.Append(datum.Fragments[i], index, datum.Fragments[i].Length - index); } else { stringBuilder.Append(datum.Fragments[i]); } } return(stringBuilder); }
public void LengthReturnsLength(InterningTestData.TestDatum datum) { MakeSpanBasedStringBuilder(datum).Length.ShouldBe(datum.Length); }
public void AppendAppendsSubstring(InterningTestData.TestDatum datum) { SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum, true); new InternableString(stringBuilder).ExpensiveConvertToString().ShouldBe(datum.ToString()); }