public static void Split_Char_NullInput() { // First, make sure that <null>.Split(',') yields a single-element [ <null> ]. Utf8Span source = Utf8Span.Empty; var enumerator = source.Split(',').GetEnumerator(); Assert.True(enumerator.MoveNext()); Assert.True(source.Bytes == enumerator.Current.Bytes); // referential equality Assert.False(enumerator.MoveNext()); // Next, make sure that if "remove empty entries" is specified, yields the empty set [ ]. enumerator = source.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries).GetEnumerator(); Assert.False(enumerator.MoveNext()); }
public static void Split_Deconstruct() { using BoundedUtf8Span boundedSpan = new BoundedUtf8Span("a,b,c,d,e"); Utf8Span span = boundedSpan.Span; // Note referential equality checks below (since we want to know exact slices // into the original buffer), not deep (textual) equality checks. { (Utf8Span a, Utf8Span b) = span.Split('x'); // not found Assert.True(a.Bytes == span.Bytes, "Expected referential equality of input."); Assert.True(b.Bytes == default); } { (Utf8Span a, Utf8Span b) = span.Split(','); Assert.True(a.Bytes == span.Bytes[..1]); // "a" Assert.True(b.Bytes == span.Bytes[2..]); // "b,c,d,e" } { (Utf8Span a, Utf8Span b, Utf8Span c, Utf8Span d, Utf8Span e) = span.Split(','); Assert.True(a.Bytes == span.Bytes[0..1]); // "a" Assert.True(b.Bytes == span.Bytes[2..3]); // "b" Assert.True(c.Bytes == span.Bytes[4..5]); // "c" Assert.True(d.Bytes == span.Bytes[6..7]); // "d" Assert.True(e.Bytes == span.Bytes[8..9]); // "e" } { (Utf8Span a, Utf8Span b, Utf8Span c, Utf8Span d, Utf8Span e, Utf8Span f, Utf8Span g, Utf8Span h) = span.Split(','); Assert.True(a.Bytes == span.Bytes[0..1]); // "a" Assert.True(b.Bytes == span.Bytes[2..3]); // "b" Assert.True(c.Bytes == span.Bytes[4..5]); // "c" Assert.True(d.Bytes == span.Bytes[6..7]); // "d" Assert.True(e.Bytes == span.Bytes[8..9]); // "e" Assert.True(f.Bytes == default); Assert.True(g.Bytes == default); Assert.True(h.Bytes == default); } }
public static void Split_Deconstruct_WithOptions() { using BoundedUtf8Span boundedSpan = new BoundedUtf8Span("a, , b, c,, d, e"); Utf8Span span = boundedSpan.Span; // Note referential equality checks below (since we want to know exact slices // into the original buffer), not deep (textual) equality checks. { (Utf8Span a, Utf8Span b) = span.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries); Assert.True(a.Bytes == span.Bytes[..1]); // "a" Assert.True(b.Bytes == span.Bytes[2..]); // " , b, c,, d, e" } { (Utf8Span a, Utf8Span x, Utf8Span b, Utf8Span c, Utf8Span d, Utf8Span e) = span.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries); Assert.True(a.Bytes == span.Bytes[0..1]); // "a" Assert.True(x.Bytes == span.Bytes[2..3]); // " " Assert.True(b.Bytes == span.Bytes[4..6]); // " b" Assert.True(c.Bytes == span.Bytes[7..9]); // " c" Assert.True(d.Bytes == span.Bytes[11..13]); // " d" Assert.True(e.Bytes == span.Bytes[14..]); // " e" } { (Utf8Span a, Utf8Span b, Utf8Span c, Utf8Span d, Utf8Span e, Utf8Span f, Utf8Span g, Utf8Span h) = span.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries | Utf8StringSplitOptions.TrimEntries); Assert.True(a.Bytes == span.Bytes[0..1]); // "a" Assert.True(b.Bytes == span.Bytes[5..6]); // "b" Assert.True(c.Bytes == span.Bytes[8..9]); // "c" Assert.True(d.Bytes == span.Bytes[12..13]); // "d" Assert.True(e.Bytes == span.Bytes[15..]); // "e" Assert.True(f.Bytes == default); Assert.True(g.Bytes == default); Assert.True(h.Bytes == default); } }