示例#1
0
        public void TrimRemovesLeadingAndTrailingWhiteSpace(InterningTestData.TestDatum datum)
        {
            SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum);

            stringBuilder.Trim();
            new InternableString(stringBuilder).ExpensiveConvertToString().ShouldBe(datum.ToString().Trim());
        }
示例#2
0
        public void ClearRemovesAllCharacters(InterningTestData.TestDatum datum)
        {
            SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum);

            stringBuilder.Clear();
            stringBuilder.Length.ShouldBe(0);
            stringBuilder.GetEnumerator().MoveNext().ShouldBeFalse();
        }
示例#3
0
        public void EnumeratorEnumeratesCharacters(InterningTestData.TestDatum datum)
        {
            SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum);
            int index = 0;

            foreach (char ch in stringBuilder)
            {
                ch.ShouldBe(datum[index]);
                index++;
            }
        }
示例#4
0
        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();
        }
示例#5
0
        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);
        }
示例#6
0
 public void LengthReturnsLength(InterningTestData.TestDatum datum)
 {
     MakeSpanBasedStringBuilder(datum).Length.ShouldBe(datum.Length);
 }
示例#7
0
        public void AppendAppendsSubstring(InterningTestData.TestDatum datum)
        {
            SpanBasedStringBuilder stringBuilder = MakeSpanBasedStringBuilder(datum, true);

            new InternableString(stringBuilder).ExpensiveConvertToString().ShouldBe(datum.ToString());
        }