Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libraries/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ public static partial class Utf8Formatter
public static bool TryFormat(short value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
public static bool TryFormat(int value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
public static bool TryFormat(long value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
public static bool TryFormat(Int128 value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
[System.CLSCompliantAttribute(false)]
public static bool TryFormat(sbyte value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
public static bool TryFormat(float value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
Expand All @@ -634,6 +635,9 @@ public static partial class Utf8Formatter
public static bool TryFormat(uint value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
[System.CLSCompliantAttribute(false)]
public static bool TryFormat(ulong value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }
[System.CLSCompliantAttribute(false)]
public static bool TryFormat(UInt128 value, System.Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default(System.Buffers.StandardFormat)) { throw null; }

}
public static partial class Utf8Parser
{
Expand All @@ -647,6 +651,7 @@ public static partial class Utf8Parser
public static bool TryParse(System.ReadOnlySpan<byte> source, out short value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
public static bool TryParse(System.ReadOnlySpan<byte> source, out int value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
public static bool TryParse(System.ReadOnlySpan<byte> source, out long value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
public static bool TryParse(System.ReadOnlySpan<byte> source, out Int128 value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
[System.CLSCompliantAttribute(false)]
public static bool TryParse(System.ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
public static bool TryParse(System.ReadOnlySpan<byte> source, out float value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
Expand All @@ -657,6 +662,8 @@ public static partial class Utf8Parser
public static bool TryParse(System.ReadOnlySpan<byte> source, out uint value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
[System.CLSCompliantAttribute(false)]
public static bool TryParse(System.ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
[System.CLSCompliantAttribute(false)]
public static bool TryParse(System.ReadOnlySpan<byte> source, out UInt128 value, out int bytesConsumed, char standardFormat = '\0') { throw null; }
}
}
namespace System.Runtime.InteropServices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ public static void TestFormatterUInt64(FormatterTestData<ulong> testData)
ValidateFormatter(testData);
}

[Theory]
[MemberData(nameof(TestData.Int128FormatterTheoryData), MemberType = typeof(TestData))]
public static void TestFormatterInt128(FormatterTestData<Int128> testData)
{
ValidateFormatter(testData);
}

[Theory]
[MemberData(nameof(TestData.UInt128FormatterTheoryData), MemberType = typeof(TestData))]
public static void TestFormatterUInt128(FormatterTestData<UInt128> testData)
{
ValidateFormatter(testData);
}

[Theory]
[MemberData(nameof(TestData.DecimalFormatterTheoryData), MemberType = typeof(TestData))]
public static void TestFormatterDecimal(FormatterTestData<decimal> testData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static IEnumerable<object[]> TypesThatCanBeFormatted
public static IEnumerable<object[]> UInt32FormatterTheoryData => UInt32FormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> Int64FormatterTheoryData => Int64FormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> UInt64FormatterTheoryData => UInt64FormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> Int128FormatterTheoryData => Int128FormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> UInt128FormatterTheoryData => UInt128FormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> DecimalFormatterTheoryData => DecimalFormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> DoubleFormatterTheoryData => DoubleFormatterTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> SingleFormatterTheoryData => SingleFormatterTestData.Select(td => new object[] { td });
Expand All @@ -58,6 +60,8 @@ public static IEnumerable<object[]> TypesThatCanBeFormatted
public static IEnumerable<FormatterTestData<uint>> UInt32FormatterTestData => CreateFormatterTestData(UInt32TestData, IntegerFormats);
public static IEnumerable<FormatterTestData<long>> Int64FormatterTestData => CreateFormatterTestData(Int64TestData, IntegerFormats);
public static IEnumerable<FormatterTestData<ulong>> UInt64FormatterTestData => CreateFormatterTestData(UInt64TestData, IntegerFormats);
public static IEnumerable<FormatterTestData<Int128>> Int128FormatterTestData => CreateFormatterTestData(Int128TestData, IntegerFormats);
public static IEnumerable<FormatterTestData<UInt128>> UInt128FormatterTestData => CreateFormatterTestData(UInt128TestData, IntegerFormats);
public static IEnumerable<FormatterTestData<decimal>> DecimalFormatterTestData => CreateFormatterTestData(DecimalTestData, DecimalFormats);
public static IEnumerable<FormatterTestData<double>> DoubleFormatterTestData => CreateFormatterTestData(DoubleTestData, FloatingPointFormats);
public static IEnumerable<FormatterTestData<float>> SingleFormatterTestData => CreateFormatterTestData(SingleTestData, FloatingPointFormats);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,15 @@ private static bool TryFormatUtf8<T>(T value, Span<byte> buffer, out int bytesWr
if (typeof(T) == typeof(long))
return Utf8Formatter.TryFormat((long)(object)value, buffer, out bytesWritten, format);

if (typeof(T) == typeof(Int128))
return Utf8Formatter.TryFormat((Int128)(object)value, buffer, out bytesWritten, format);

if (typeof(T) == typeof(ulong))
return Utf8Formatter.TryFormat((ulong)(object)value, buffer, out bytesWritten, format);

if (typeof(T) == typeof(UInt128))
return Utf8Formatter.TryFormat((UInt128)(object)value, buffer, out bytesWritten, format);

if (typeof(T) == typeof(decimal))
return Utf8Formatter.TryFormat((decimal)(object)value, buffer, out bytesWritten, format);

Expand All @@ -173,59 +179,5 @@ private static bool TryFormatUtf8<T>(T value, Span<byte> buffer, out int bytesWr

throw new Exception("No formatter for type " + typeof(T));
}

private static bool TryFormatUtf8(object value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default)
{
Type t = value.GetType();
if (t == typeof(bool))
return Utf8Formatter.TryFormat((bool)value, buffer, out bytesWritten, format);

if (t == typeof(byte))
return Utf8Formatter.TryFormat((byte)value, buffer, out bytesWritten, format);

if (t == typeof(sbyte))
return Utf8Formatter.TryFormat((sbyte)value, buffer, out bytesWritten, format);

if (t == typeof(short))
return Utf8Formatter.TryFormat((short)value, buffer, out bytesWritten, format);

if (t == typeof(ushort))
return Utf8Formatter.TryFormat((ushort)value, buffer, out bytesWritten, format);

if (t == typeof(int))
return Utf8Formatter.TryFormat((int)value, buffer, out bytesWritten, format);

if (t == typeof(uint))
return Utf8Formatter.TryFormat((uint)value, buffer, out bytesWritten, format);

if (t == typeof(long))
return Utf8Formatter.TryFormat((long)value, buffer, out bytesWritten, format);

if (t == typeof(ulong))
return Utf8Formatter.TryFormat((ulong)value, buffer, out bytesWritten, format);

if (t == typeof(decimal))
return Utf8Formatter.TryFormat((decimal)value, buffer, out bytesWritten, format);

if (t == typeof(double))
return Utf8Formatter.TryFormat((double)value, buffer, out bytesWritten, format);

if (t == typeof(float))
return Utf8Formatter.TryFormat((float)value, buffer, out bytesWritten, format);

if (t == typeof(Guid))
return Utf8Formatter.TryFormat((Guid)value, buffer, out bytesWritten, format);

if (t == typeof(DateTime))
return Utf8Formatter.TryFormat((DateTime)value, buffer, out bytesWritten, format);

if (t == typeof(DateTimeOffset))
return Utf8Formatter.TryFormat((DateTimeOffset)value, buffer, out bytesWritten, format);

if (t == typeof(TimeSpan))
return Utf8Formatter.TryFormat((TimeSpan)value, buffer, out bytesWritten, format);

throw new Exception("No formatter for type " + t);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ public static void TestParserUInt64(ParserTestData<ulong> testData)
ValidateParser(testData);
}

[Theory]
[MemberData(nameof(TestData.Int128ParserTheoryData), MemberType = typeof(TestData))]
public static void TestParserInt128(ParserTestData<Int128> testData)
{
ValidateParser(testData);
}

[Theory]
[MemberData(nameof(TestData.UInt128ParserTheoryData), MemberType = typeof(TestData))]
public static void TestParserUInt128(ParserTestData<UInt128> testData)
{
ValidateParser(testData);
}

[Theory]
[MemberData(nameof(TestData.DecimalParserTheoryData), MemberType = typeof(TestData))]
public static void TestParserDecimal(ParserTestData<decimal> testData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,48 @@ public static IEnumerable<ParserTestData<ulong>> UInt64ParserTestData
}
}

public static IEnumerable<ParserTestData<Int128>> Int128ParserTestData
{
get
{
foreach (ParserTestData<Int128> testData in Int128FormatterTestData.ToParserTheoryDataCollection())
{
yield return testData;
}

foreach (ParserTestData<Int128> testData in GeneralIntegerParserTestData<Int128>())
{
yield return testData;
}

// Code coverage
yield return new ParserTestData<Int128>("5$", 5, 'D', expectedSuccess: true) { ExpectedBytesConsumed = 1 };
yield return new ParserTestData<Int128>("5$", 5, 'x', expectedSuccess: true) { ExpectedBytesConsumed = 1 };
yield return new ParserTestData<Int128>("5faaccbb11223344f", 0, 'x', expectedSuccess: false);
}
}

public static IEnumerable<ParserTestData<UInt128>> UInt128ParserTestData
{
get
{
foreach (ParserTestData<UInt128> testData in UInt128FormatterTestData.ToParserTheoryDataCollection())
{
yield return testData;
}

foreach (ParserTestData<UInt128> testData in GeneralIntegerParserTestData<UInt128>())
{
yield return testData;
}

// Code coverage
yield return new ParserTestData<UInt128>("5$", 5, 'D', expectedSuccess: true) { ExpectedBytesConsumed = 1 };
yield return new ParserTestData<UInt128>("5$", 5, 'x', expectedSuccess: true) { ExpectedBytesConsumed = 1 };
yield return new ParserTestData<UInt128>("5faaccbb11223344f", 0, 'x', expectedSuccess: false);
}
}

private static IEnumerable<ParserTestData<T>> GeneralIntegerParserTestData<T>()
{
string[] GeneralIntegerNegativeInputs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static IEnumerable<object[]> TypesThatCanBeParsed
public static IEnumerable<object[]> UInt32ParserTheoryData => UInt32ParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> Int64ParserTheoryData => Int64ParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> UInt64ParserTheoryData => UInt64ParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> Int128ParserTheoryData => Int128ParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> UInt128ParserTheoryData => UInt128ParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> DecimalParserTheoryData => DecimalParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> DoubleParserTheoryData => DoubleParserTestData.Select(td => new object[] { td });
public static IEnumerable<object[]> SingleParserTheoryData => SingleParserTestData.Select(td => new object[] { td });
Expand Down
28 changes: 28 additions & 0 deletions src/libraries/System.Memory/tests/ParsersAndFormatters/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,34 @@ public static IEnumerable<ulong> UInt64TestData
}
}

public static IEnumerable<Int128> Int128TestData
{
get
{
foreach (long l in Int64TestData)
{
yield return l;
}

yield return Int128.MaxValue;
yield return Int128.MinValue;
}
}

public static IEnumerable<UInt128> UInt128TestData
{
get
{
foreach (ulong l in UInt64TestData)
{
yield return l;
}

yield return UInt128.MaxValue;
yield return UInt128.MinValue;
}
}

public static IEnumerable<decimal> DecimalTestData
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ public static BigInteger GetMinValue<T>()
if (typeof(T) == typeof(long))
return long.MinValue;

if (typeof(T) == typeof(Int128))
return Int128.MinValue;

if (typeof(T) == typeof(ulong))
return ulong.MinValue;

if (typeof(T) == typeof(UInt128))
return UInt128.MinValue;

if (typeof(T) == typeof(decimal))
return new BigInteger(decimal.MinValue);

Expand Down Expand Up @@ -126,9 +132,15 @@ public static BigInteger GetMaxValue<T>()
if (typeof(T) == typeof(long))
return long.MaxValue;

if (typeof(T) == typeof(Int128))
return Int128.MaxValue;

if (typeof(T) == typeof(ulong))
return ulong.MaxValue;

if (typeof(T) == typeof(UInt128))
return UInt128.MaxValue;

if (typeof(T) == typeof(decimal))
return new BigInteger(decimal.MaxValue);

Expand Down
Loading