protected void _RunGetIndexOfFirstCharacterToEncodeUtf16_BmpExtendedValidCharsOnly(char bmpAllowedChar) { // Loop from 96 elements all the way down to 0 elements, which tests that we're // not overrunning our read buffers. var span = _boundedChars.Span; _boundedChars.MakeWriteable(); span.Fill(bmpAllowedChar); // make buffer all-valid _boundedChars.MakeReadonly(); for (int i = 96; i >= 0; i--) { Assert.Equal(-1, _encoder.FindFirstCharacterToEncodeUtf16(span.Slice(span.Length - i))); } // Also check from the beginning of the buffer just in case there's some alignment weirdness // in the SIMD-optimized code that causes us to read past where we should. _boundedChars.MakeWriteable(); for (int i = 96; i >= 0; i--) { span[i] = _disallowedChar; // make this char invalid (ASCII) Assert.Equal(-1, _encoder.FindFirstCharacterToEncodeUtf16(span.Slice(0, i))); } }