Skip to content

Commit 1a96940

Browse files
authored
Specify and test that 0x is case-invariant in the Convert class (#101876)
* Specify that "0x" is case-invariant in the Convert class * Test that `0x` is case-invariant in the Convert class * Fix a typo in the Convert class
1 parent 04e9bc3 commit 1a96940

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

src/libraries/System.Private.CoreLib/src/System/Convert.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ public static string ToString(DateTime value, IFormatProvider? provider)
20462046
//
20472047
// Parses value in base base. base can only
20482048
// be 2, 8, 10, or 16. If base is 16, the number may be preceded
2049-
// by 0x; any other leading or trailing characters cause an error.
2049+
// by 0x or 0X; any other leading or trailing characters cause an error.
20502050
//
20512051
public static byte ToByte(string? value, int fromBase)
20522052
{
@@ -2068,7 +2068,7 @@ public static byte ToByte(string? value, int fromBase)
20682068

20692069
// Parses value in base fromBase. fromBase can only
20702070
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2071-
// by 0x; any other leading or trailing characters cause an error.
2071+
// by 0x or 0X; any other leading or trailing characters cause an error.
20722072
//
20732073
[CLSCompliant(false)]
20742074
public static sbyte ToSByte(string? value, int fromBase)
@@ -2094,7 +2094,7 @@ public static sbyte ToSByte(string? value, int fromBase)
20942094

20952095
// Parses value in base fromBase. fromBase can only
20962096
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2097-
// by 0x; any other leading or trailing characters cause an error.
2097+
// by 0x or 0X; any other leading or trailing characters cause an error.
20982098
//
20992099
public static short ToInt16(string? value, int fromBase)
21002100
{
@@ -2119,7 +2119,7 @@ public static short ToInt16(string? value, int fromBase)
21192119

21202120
// Parses value in base fromBase. fromBase can only
21212121
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2122-
// by 0x; any other leading or trailing characters cause an error.
2122+
// by 0x or 0X; any other leading or trailing characters cause an error.
21232123
//
21242124
[CLSCompliant(false)]
21252125
public static ushort ToUInt16(string? value, int fromBase)
@@ -2142,7 +2142,7 @@ public static ushort ToUInt16(string? value, int fromBase)
21422142

21432143
// Parses value in base fromBase. fromBase can only
21442144
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2145-
// by 0x; any other leading or trailing characters cause an error.
2145+
// by 0x or 0X; any other leading or trailing characters cause an error.
21462146
//
21472147
public static int ToInt32(string? value, int fromBase)
21482148
{
@@ -2157,7 +2157,7 @@ public static int ToInt32(string? value, int fromBase)
21572157

21582158
// Parses value in base fromBase. fromBase can only
21592159
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2160-
// by 0x; any other leading or trailing characters cause an error.
2160+
// by 0x or 0X; any other leading or trailing characters cause an error.
21612161
//
21622162
[CLSCompliant(false)]
21632163
public static uint ToUInt32(string? value, int fromBase)
@@ -2173,7 +2173,7 @@ public static uint ToUInt32(string? value, int fromBase)
21732173

21742174
// Parses value in base fromBase. fromBase can only
21752175
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2176-
// by 0x; any other leading or trailing characters cause an error.
2176+
// by 0x or 0X; any other leading or trailing characters cause an error.
21772177
//
21782178
public static long ToInt64(string? value, int fromBase)
21792179
{
@@ -2188,7 +2188,7 @@ public static long ToInt64(string? value, int fromBase)
21882188

21892189
// Parses value in base fromBase. fromBase can only
21902190
// be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
2191-
// by 0x; any other leading or trailing characters cause an error.
2191+
// by 0x or 0X; any other leading or trailing characters cause an error.
21922192
//
21932193
[CLSCompliant(false)]
21942194
public static ulong ToUInt64(string? value, int fromBase)
@@ -2202,11 +2202,11 @@ public static ulong ToUInt64(string? value, int fromBase)
22022202
0;
22032203
}
22042204

2205-
// Convert the byte value to a string in base fromBase
2205+
// Convert the byte value to a string in base toBase
22062206
public static string ToString(byte value, int toBase) =>
22072207
ToString((int)value, toBase);
22082208

2209-
// Convert the Int16 value to a string in base fromBase
2209+
// Convert the Int16 value to a string in base toBase
22102210
public static string ToString(short value, int toBase)
22112211
{
22122212
string format = "d";

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToByte.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public void FromString()
131131
[Fact]
132132
public void FromStringWithBase()
133133
{
134-
string[] testValues = { null, null, null, null, "10", "100", "1011", "ff", "0xff", "77", "11", "11111111" };
135-
int[] testBases = { 10, 2, 8, 16, 10, 10, 2, 16, 16, 8, 2, 2 };
136-
byte[] expectedValues = { 0, 0, 0, 0, 10, 100, 11, 255, 255, 63, 3, 255 };
134+
string[] testValues = { null, null, null, null, "10", "100", "1011", "ff", "0xff", "77", "11", "11111111", "0XFF" };
135+
int[] testBases = { 10, 2, 8, 16, 10, 10, 2, 16, 16, 8, 2, 2, 16 };
136+
byte[] expectedValues = { 0, 0, 0, 0, 10, 100, 11, 255, 255, 63, 3, 255, 255 };
137137
VerifyFromStringWithBase(Convert.ToByte, testValues, testBases, expectedValues);
138138

139139
string[] overflowValues = { "256", "111111111", "ffffe", "7777777", "-1" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToInt16.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public void FromString()
130130
[Fact]
131131
public void FromStringWithBase()
132132
{
133-
string[] testValues = { null, null, null, null, "7fff", "32767", "77777", "111111111111111", "8000", "-32768", "100000", "1000000000000000" };
134-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2 };
135-
short[] expectedValues = { 0, 0, 0, 0, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MinValue, short.MinValue, short.MinValue, short.MinValue };
133+
string[] testValues = { null, null, null, null, "7fff", "32767", "77777", "111111111111111", "8000", "-32768", "100000", "1000000000000000", "0x7fff", "0X7FFF" };
134+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 16, 16 };
135+
short[] expectedValues = { 0, 0, 0, 0, short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue, short.MinValue, short.MinValue, short.MinValue, short.MinValue, short.MaxValue, short.MaxValue };
136136
VerifyFromStringWithBase(Convert.ToInt16, testValues, testBases, expectedValues);
137137

138138
string[] overflowValues = { "32768", "-32769", "11111111111111111", "1FFFF", "777777" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToInt32.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public void FromString()
127127
[Fact]
128128
public void FromStringWithBase()
129129
{
130-
string[] testValues = { null, null, null, null, "7FFFFFFF", "2147483647", "17777777777", "1111111111111111111111111111111", "80000000", "-2147483648", "20000000000", "10000000000000000000000000000000", };
131-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, };
132-
int[] expectedValues = { 0, 0, 0, 0, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue, };
130+
string[] testValues = { null, null, null, null, "7FFFFFFF", "2147483647", "17777777777", "1111111111111111111111111111111", "80000000", "-2147483648", "20000000000", "10000000000000000000000000000000", "0x7fffffff", "0X7FFFFFFF" };
131+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 16, 16 };
132+
int[] expectedValues = { 0, 0, 0, 0, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MaxValue, int.MaxValue };
133133
VerifyFromStringWithBase(Convert.ToInt32, testValues, testBases, expectedValues);
134134

135135
string[] overflowValues = { "2147483648", "-2147483649", "111111111111111111111111111111111", "1FFFFffff", "777777777777" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToInt64.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ public void FromString()
124124
[Fact]
125125
public void FromStringWithBase()
126126
{
127-
string[] testValues = { null, null, null, null, "7FFFFFFFFFFFFFFF", "9223372036854775807", "777777777777777777777", "111111111111111111111111111111111111111111111111111111111111111", "8000000000000000", "-9223372036854775808", "1000000000000000000000", "1000000000000000000000000000000000000000000000000000000000000000" };
128-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2 };
129-
long[] expectedValues = { 0, 0, 0, 0, long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue, long.MinValue, long.MinValue, long.MinValue, long.MinValue };
127+
string[] testValues = { null, null, null, null, "7FFFFFFFFFFFFFFF", "9223372036854775807", "777777777777777777777", "111111111111111111111111111111111111111111111111111111111111111", "8000000000000000", "-9223372036854775808", "1000000000000000000000", "1000000000000000000000000000000000000000000000000000000000000000", "0x7fffffffffffffff", "0X7FFFFFFFFFFFFFFF" };
128+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 16, 16 };
129+
long[] expectedValues = { 0, 0, 0, 0, long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue, long.MinValue, long.MinValue, long.MinValue, long.MinValue, long.MaxValue, long.MaxValue };
130130
VerifyFromStringWithBase(Convert.ToInt64, testValues, testBases, expectedValues);
131131

132132
string[] overflowValues = { "9223372036854775808", "-9223372036854775809", "11111111111111111111111111111111111111111111111111111111111111111", "1FFFFffffFFFFffff", "7777777777777777777777777" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToSByte.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ public void FromString()
141141
[Fact]
142142
public void FromStringWithBase()
143143
{
144-
string[] testValues = { null, null, null, null, "7f", "127", "177", "1111111", "80", "-128", "200", "10000000" };
145-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2 };
146-
sbyte[] expectedValues = { 0, 0, 0, 0, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MinValue, sbyte.MinValue, sbyte.MinValue, sbyte.MinValue };
144+
string[] testValues = { null, null, null, null, "7f", "127", "177", "1111111", "80", "-128", "200", "10000000", "0x7f", "0X7F" };
145+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 16, 16 };
146+
sbyte[] expectedValues = { 0, 0, 0, 0, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MinValue, sbyte.MinValue, sbyte.MinValue, sbyte.MinValue, sbyte.MaxValue, sbyte.MaxValue };
147147
VerifyFromStringWithBase(Convert.ToSByte, testValues, testBases, expectedValues);
148148

149149
string[] overflowValues = { "128", "-129", "111111111", "1FF", "777" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToUInt16.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public void FromString()
136136
[Fact]
137137
public void FromStringWithBase()
138138
{
139-
string[] testValues = { null, null, null, null, "ffff", "65535", "177777", "1111111111111111", "0", "0", "0", "0" };
140-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2 };
141-
ushort[] expectedValues = { 0, 0, 0, 0, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MinValue, ushort.MinValue, ushort.MinValue, ushort.MinValue };
139+
string[] testValues = { null, null, null, null, "ffff", "65535", "177777", "1111111111111111", "0", "0", "0", "0", "0xffff", "0XFFFF" };
140+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 16, 16 };
141+
ushort[] expectedValues = { 0, 0, 0, 0, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MinValue, ushort.MinValue, ushort.MinValue, ushort.MinValue, ushort.MaxValue, ushort.MaxValue };
142142
VerifyFromStringWithBase(Convert.ToUInt16, testValues, testBases, expectedValues);
143143

144144
string[] overflowValues = { "65536", "-1", "11111111111111111", "1FFFF", "777777" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToUInt32.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public void FromString()
136136
[Fact]
137137
public void FromStringWithBase()
138138
{
139-
string[] testValues = { null, null, null, null, "ffffffff", "4294967295", "37777777777", "11111111111111111111111111111111", "0", "0", "0", "0", "2147483647", "2147483648", "2147483649" };
140-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 10, 10, 10 };
141-
uint[] expectedValues = { 0, 0, 0, 0, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MinValue, uint.MinValue, uint.MinValue, uint.MinValue, (uint)int.MaxValue, (uint)int.MaxValue + 1, (uint)int.MaxValue + 2 };
139+
string[] testValues = { null, null, null, null, "ffffffff", "4294967295", "37777777777", "11111111111111111111111111111111", "0", "0", "0", "0", "2147483647", "2147483648", "2147483649", "0xffffffff", "0XFFFFFFFF" };
140+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 10, 10, 10, 16, 16 };
141+
uint[] expectedValues = { 0, 0, 0, 0, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MinValue, uint.MinValue, uint.MinValue, uint.MinValue, (uint)int.MaxValue, (uint)int.MaxValue + 1, (uint)int.MaxValue + 2, uint.MaxValue, uint.MaxValue};
142142
VerifyFromStringWithBase(Convert.ToUInt32, testValues, testBases, expectedValues);
143143

144144
string[] overflowValues = { "18446744073709551616", "18446744073709551617", "18446744073709551618", "18446744073709551619", "18446744073709551620", "-4294967297", "11111111111111111111111111111111111111111111111111111111111111111", "1FFFFffffFFFFffff", "7777777777777777777777777" };

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Convert.ToUInt64.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public void FromString()
136136
[Fact]
137137
public void FromStringWithBase()
138138
{
139-
string[] testValues = { null, null, null, null, "ffffffffffffffff", "18446744073709551615", "1777777777777777777777", "1111111111111111111111111111111111111111111111111111111111111111", "0", "0", "0", "0", "9223372036854775807", "9223372036854775808" /*VSWhidbey #526568*/, "9223372036854775809", "9223372036854775810", "9223372036854775811" };
140-
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 10, 10, 10, 10, 10 };
141-
ulong[] expectedValues = { 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MinValue, ulong.MinValue, ulong.MinValue, ulong.MinValue, (ulong)long.MaxValue, (ulong)long.MaxValue + 1 /*VSWhidbey #526568*/, (ulong)long.MaxValue + 2, (ulong)long.MaxValue + 3, (ulong)long.MaxValue + 4 };
139+
string[] testValues = { null, null, null, null, "ffffffffffffffff", "18446744073709551615", "1777777777777777777777", "1111111111111111111111111111111111111111111111111111111111111111", "0", "0", "0", "0", "9223372036854775807", "9223372036854775808" /*VSWhidbey #526568*/, "9223372036854775809", "9223372036854775810", "9223372036854775811", "0xffffffffffffffff", "0XFFFFFFFFFFFFFFFF" };
140+
int[] testBases = { 10, 2, 8, 16, 16, 10, 8, 2, 16, 10, 8, 2, 10, 10, 10, 10, 10, 16, 16 };
141+
ulong[] expectedValues = { 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MinValue, ulong.MinValue, ulong.MinValue, ulong.MinValue, (ulong)long.MaxValue, (ulong)long.MaxValue + 1 /*VSWhidbey #526568*/, (ulong)long.MaxValue + 2, (ulong)long.MaxValue + 3, (ulong)long.MaxValue + 4, ulong.MaxValue, ulong.MaxValue };
142142
VerifyFromStringWithBase(Convert.ToUInt64, testValues, testBases, expectedValues);
143143

144144
string[] overflowValues = { "18446744073709551616", "18446744073709551617", "18446744073709551618", "18446744073709551619", "18446744073709551620", "-4294967297", "11111111111111111111111111111111111111111111111111111111111111111", "1FFFFffffFFFFffff", "7777777777777777777777777" };

0 commit comments

Comments
 (0)