public static void TryFind_Char_Ordinal(ustring source, char searchTerm, Range?expectedForwardMatch, Range?expectedBackwardMatch) { using BoundedUtf8Span boundedSpan = new BoundedUtf8Span(source.AsBytes()); Utf8Span searchSpan = boundedSpan.Span; source = null; // to avoid accidentally using this for the remainder of the test // First, search forward bool wasFound = searchSpan.TryFind(searchTerm, out Range actualForwardMatch); Assert.Equal(expectedForwardMatch.HasValue, wasFound); if (wasFound) { AssertRangesEqual(searchSpan.Length, expectedForwardMatch.Value, actualForwardMatch); } // Also check Contains / StartsWith / SplitOn Assert.Equal(wasFound, searchSpan.Contains(searchTerm)); Assert.Equal(wasFound && searchSpan.Bytes[..actualForwardMatch.Start].IsEmpty, searchSpan.StartsWith(searchTerm)); (var before, var after) = searchSpan.SplitOn(searchTerm); if (wasFound) { Assert.True(searchSpan.Bytes[..actualForwardMatch.Start] == before.Bytes); // check for referential equality