Exemplo n.º 1
0
        public unsafe void GuidParsingUtf8(string format)
        {
            var parsedFormat = ParsedFormat.Parse(format);
            var random       = new Random(1000);
            var guidBytes    = new byte[16];

            var expected = guidWithAllNonZeroDigits;

            for (int i = 0; i < 100; i++)
            {
                var expectedString = expected.ToString(format, CultureInfo.InvariantCulture);
                var utf8Bytes      = Text.Encoding.UTF8.GetBytes(expectedString);

                Assert.True(Utf8Parser.TryParseGuid(utf8Bytes, out Guid parsed, out int bytesConsumed, parsedFormat));
                Assert.Equal(expected, parsed);
                Assert.Equal(expectedString.Length, bytesConsumed);

                random.NextBytes(guidBytes);
                expected = new Guid(guidBytes);
            }
        }