public void CanEnumerateReadonlySpan() { // Test example taken from. // https://docs.microsoft.com/en-us/dotnet/api/system.text.rune?view=net-5.0#when-to-use-the-rune-type const string text = "𐓏𐓘𐓻𐓘𐓻𐓟 𐒻𐓟"; int letterCount = 0; foreach (CodePoint codePoint in text.AsSpan().EnumerateCodePoints()) { if (CodePoint.IsLetter(codePoint)) { letterCount++; } } Assert.Equal(8, letterCount); }
public void CanEnumerateInvalidReadonlySpan() { // The string below contains 2 combining characters then // a single high surrogate code unit, then 2 more sets or combining characters. // 'ā̈' 'b' '�' 'ç' const string text = "a\u0304\u0308b\ud800c\u0327"; int letterCount = 0; int codePointCount = 0; foreach (CodePoint codePoint in text.AsSpan().EnumerateCodePoints()) { if (CodePoint.IsLetter(codePoint)) { letterCount++; } codePointCount++; } Assert.Equal(3, letterCount); Assert.Equal(7, codePointCount); }
public static void CodePointIsLetter(UnicodeInfoTestData testData) => Assert.Equal(testData.IsLetter, CodePoint.IsLetter(testData.ScalarValue));