public void EnsureCodeUnitsOfStringByEnumeratingBytes(byte[] expectedBytes, Utf8String utf8String) { Assert.Equal(expectedBytes.Length, utf8String.Length); Utf8String.Enumerator e = utf8String.GetEnumerator(); int i = 0; while (e.MoveNext()) { Assert.True(i < expectedBytes.Length); Assert.Equal(expectedBytes[i], (byte)e.Current); i++; } Assert.Equal(expectedBytes.Length, i); }
public void AsciiStringEnumerators(string s) { Utf8String u8s = new Utf8String(Encoding.UTF8.GetBytes(s)); Utf8String.Enumerator e = u8s.GetEnumerator(); Utf8String.CodePointEnumerator cpe = u8s.CodePoints.GetEnumerator(); Assert.Equal(s.Length, u8s.Length); for (int i = 0; i < s.Length; i++) { Assert.True(e.MoveNext()); Assert.True(cpe.MoveNext()); Assert.Equal((byte)s[i], (byte)u8s[i]); Assert.Equal(u8s[i], e.Current); Assert.Equal((byte)s[i], (byte)(uint)cpe.Current); } }