示例#1
0
        public void AsSpan_FromUtf8String()
        {
            Assert.True(((Utf8String)null).AsSpan().Bytes == default); // referential equality check

            Utf8String theString = u8("Hello");

            Assert.True(Unsafe.AreSame(ref Unsafe.AsRef(in theString.GetPinnableReference()), ref Unsafe.AsRef(in theString.AsSpan().GetPinnableReference())));
            Assert.Equal(5, theString.AsSpan().Bytes.Length);
        }
        public static void AreEquivalent_Tests(string utf8Input, string utf16Input, bool expected)
        {
            Utf8String asUtf8 = u8(utf8Input);

            // Call all three overloads

            Assert.Equal(expected, Utf8String.AreEquivalent(asUtf8, utf16Input));
            Assert.Equal(expected, Utf8String.AreEquivalent(asUtf8.AsSpan(), utf16Input.AsSpan()));
            Assert.Equal(expected, Utf8String.AreEquivalent(asUtf8.AsBytes(), utf16Input.AsSpan()));
        }
        public void AsSpan_FromUtf8String()
        {
            Assert.True(default(ReadOnlySpan <Char8>) == ((Utf8String)null).AsSpan());

            Utf8String theString = u8("Hello");

            Assert.True(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As <byte, Char8>(ref Unsafe.AsRef(in theString.GetPinnableReference())), 5) == theString.AsSpan());
        }