public unsafe void DecimalPositiveTests(string text, int length, decimal expectedValue, int expectedConsumed) { byte[] byteBuffer = Text.Encoding.UTF8.GetBytes(text); ReadOnlySpan <byte> byteSpan = new ReadOnlySpan <byte>(byteBuffer); char[] charBuffer = text.ToCharArray(); ReadOnlySpan <char> charSpan = new ReadOnlySpan <char>(charBuffer); bool result; decimal actualValue; int actualConsumed; result = CustomParser.TryParseDecimal(byteSpan, out actualValue, out actualConsumed, SymbolTable.InvariantUtf8); Assert.True(result); Assert.Equal(expectedValue, actualValue); Assert.Equal(expectedConsumed, actualConsumed); //fixed (byte* bytePointer = byteBuffer) //{ // result = Parsers.Utf8.TryParseDecimal(bytePointer, length, out actualValue); // Assert.True(result); // Assert.Equal(expectedValue, actualValue); // result = Parsers.Utf8.TryParseDecimal(bytePointer, length, out actualValue, out actualConsumed); // Assert.True(result); // Assert.Equal(expectedValue, actualValue); // Assert.Equal(expectedConsumed, actualConsumed); //} result = Utf8Parser.TryParseDecimal(byteSpan, out actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); result = Utf8Parser.TryParseDecimal(byteSpan, out actualValue, out actualConsumed); Assert.True(result); Assert.Equal(expectedValue, actualValue); Assert.Equal(expectedConsumed, actualConsumed); ReadOnlySpan <byte> utf16ByteSpan = charSpan.AsBytes(); result = CustomParser.TryParseDecimal(utf16ByteSpan, out actualValue, out actualConsumed, SymbolTable.InvariantUtf16); Assert.True(result); Assert.Equal(expectedValue, actualValue); Assert.Equal(expectedConsumed, actualConsumed / 2); //fixed (char* charPointer = charBuffer) //{ // result = Parsers.Utf16.TryParseDecimal(charPointer, length, out actualValue); // Assert.True(result); // Assert.Equal(expectedValue, actualValue); // result = Parsers.Utf16.TryParseDecimal(charPointer, length, out actualValue, out actualConsumed); // Assert.True(result); // Assert.Equal(expectedValue, actualValue); // Assert.Equal(expectedConsumed, actualConsumed); //} result = Utf16Parser.TryParseDecimal(charSpan, out actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); result = Utf16Parser.TryParseDecimal(charSpan, out actualValue, out actualConsumed); Assert.True(result); Assert.Equal(expectedValue, actualValue); Assert.Equal(expectedConsumed, actualConsumed); }