public void StringReadonlyMemoryTest()
        {
            ReadOnlyMemory <string> sample = ExpectedString.Split(' ');

            var actual = PreInputted.ToStringBuilder();

            sample.AppendToStringBuilder(actual, CharSeparator);
            actual.Is(PreInputted, ExpectedString, " ", CharSeparator);

            actual = PreInputted.ToStringBuilder();
            sample.AppendToStringBuilder(actual, StringSeparator);
            actual.Is(PreInputted, ExpectedString, " ", StringSeparator);
        }
Example #2
0
 /// <summary>
 ///     Concatenates the string of the provided ReadonlyMemory,
 ///     using the specified separator between each string.
 ///     Then create the StringBuilder from it.
 /// </summary>
 /// <param name="source">An ReadonlyMemory that contains the string.</param>
 /// <param name="separator">Specify the separator.</param>
 /// <returns>A StringBuider that contain the concatenated the specified strings with specified separator.</returns>
 public static StringBuilder ToStringBuilder(this ReadOnlyMemory <string> source, string separator) =>
 source.AppendToStringBuilder(new StringBuilder(), separator);
Example #3
0
 /// <summary>
 ///     Concatenates the string of the provided string ReadOnlyMemory,
 ///     using the specified separator between each string.
 ///     Then appends the result and finally default line terminator to the designated StringBuilder.
 /// </summary>
 /// <param name="source">A string ReadOnlyMemory for concatenates.</param>
 /// <param name="stringBuilder">A StringBuilder to be appended.</param>
 /// <param name="separator">Specify the separator.</param>
 /// <returns>A reference to the designated instance after the append operation has completed.</returns>
 public static StringBuilder AppendToStringBuilderAsLine(this ReadOnlyMemory <string> source,
                                                         StringBuilder stringBuilder, string separator) =>
 source.AppendToStringBuilder(stringBuilder, separator).AppendLine();
        public void AppendToStringBuilderAsLineTest()
        {
            var bld = PreInputted.ToStringBuilder();

            StringBuilder reset()
            {
                return(bld.Clear().Append(PreInputted));
            }

            var array    = ExpectedString.Split(' ');
            var expected = PreInputted + ExpectedString.Replace(' ', '\t') + Environment.NewLine;

            array.AppendToStringBuilderAsLine(reset(), '\t').Is(expected);
            array.AppendToStringBuilder(reset(), "hoge").Is(PreInputted + ExpectedString.Replace(" ", "hoge"));

            Array.Empty <string>().AppendToStringBuilderAsLine(reset(), '\t').Is(PreInputted + Environment.NewLine);
            Array.Empty <string>().AppendToStringBuilderAsLine(reset(), "hoge").Is(PreInputted + Environment.NewLine);

            var span = new ReadOnlySpan <string>(array);

            span.AppendToStringBuilderAsLine(reset(), '\t').Is(expected);
            span.AppendToStringBuilderAsLine(reset(), "hoge").Is(PreInputted + ExpectedString.Replace(" ", "hoge") + Environment.NewLine);

            span = new ReadOnlySpan <string>(Array.Empty <string>());
            span.AppendToStringBuilderAsLine(reset(), '\t').Is(PreInputted + Environment.NewLine);
            span.AppendToStringBuilderAsLine(reset(), "hoge").Is(PreInputted + Environment.NewLine);


            var mem = new ReadOnlyMemory <string>(array);

            mem.AppendToStringBuilderAsLine(reset(), '\t').Is(expected);
            mem.AppendToStringBuilder(reset(), "hoge").Is(PreInputted + ExpectedString.Replace(" ", "hoge"));

            mem = new ReadOnlyMemory <string>(Array.Empty <string>());
            mem.AppendToStringBuilderAsLine(reset(), '\t').Is(PreInputted + Environment.NewLine);
            mem.AppendToStringBuilderAsLine(reset(), "hoge").Is(PreInputted + Environment.NewLine);

            var seq = array.Select(s => s.ToCharArray().Select(c => c));

            seq.AppendToStringBuilderAsLine(reset(), '\t').Is(expected);
            seq.AppendToStringBuilder(reset(), "hoge").Is(PreInputted + ExpectedString.Replace(" ", "hoge"));

            seq = Enumerable.Empty <string>();
            seq.AppendToStringBuilderAsLine(reset(), '\t').Is(PreInputted + Environment.NewLine);
            seq.AppendToStringBuilderAsLine(reset(), "hoge").Is(PreInputted + Environment.NewLine);

            var strArray = Enumerable.Range(0, 10).Select(i => i.ToString()).ToArray();

            strArray.AppendToStringBuilderAsLine(reset(), '\t')
            .Is(PreInputted + string.Join('\t', strArray) + Environment.NewLine);

            strArray.AppendToStringBuilderAsLine(reset(), "hoge")
            .Is(PreInputted + string.Join("hoge", strArray) + Environment.NewLine);

            object[] objArray = strArray;
            objArray.AppendToStringBuilderAsLine(reset(), '\t')
            .Is(PreInputted + string.Join('\t', objArray) + Environment.NewLine);

            objArray.AppendToStringBuilderAsLine(reset(), "hoge")
            .Is(PreInputted + string.Join("hoge", objArray) + Environment.NewLine);

            var intSeq = Enumerable.Range(0, 10);

            intSeq.AppendToStringBuilderAsLine(reset(), '\t')
            .Is(PreInputted + string.Join('\t', intSeq) + Environment.NewLine);

            intSeq.AppendToStringBuilderAsLine(reset(), "hoge")
            .Is(PreInputted + string.Join("hoge", intSeq) + Environment.NewLine);
        }