Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c28df6

Browse files
committed
add tests
1 parent0692cf1 commit2c28df6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎src/libraries/System.Runtime/tests/System/EnumTests.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,31 @@ public static void Parse<T>(string value, bool ignoreCase, T expected) where T :
127127
Tresult;
128128
if(!ignoreCase)
129129
{
130+
Assert.True(Enum.TryParse(value.AsSpan(),outresult));
131+
Assert.Equal(expected,result);
132+
130133
Assert.True(Enum.TryParse(value,outresult));
131134
Assert.Equal(expected,result);
132135

136+
137+
Assert.Equal(expected,Enum.Parse(expected.GetType(),value.AsSpan()));
133138
Assert.Equal(expected,Enum.Parse(expected.GetType(),value));
139+
140+
Assert.Equal(expected,Enum.Parse<T>(value.AsSpan()));
134141
Assert.Equal(expected,Enum.Parse<T>(value));
135142
}
136143

144+
Assert.True(Enum.TryParse(value.AsSpan(),ignoreCase,outresult));
145+
Assert.Equal(expected,result);
146+
137147
Assert.True(Enum.TryParse(value,ignoreCase,outresult));
138148
Assert.Equal(expected,result);
139149

150+
151+
Assert.Equal(expected,Enum.Parse(expected.GetType(),value.AsSpan(),ignoreCase));
140152
Assert.Equal(expected,Enum.Parse(expected.GetType(),value,ignoreCase));
153+
154+
Assert.Equal(expected,Enum.Parse<T>(value.AsSpan(),ignoreCase));
141155
Assert.Equal(expected,Enum.Parse<T>(value,ignoreCase));
142156
}
143157

@@ -238,10 +252,16 @@ private static void Parse_Generic_Invalid<T>(Type enumType, string value, bool i
238252
Assert.False(Enum.TryParse(enumType,value,outresult));
239253
Assert.Equal(default(object),result);
240254

255+
if(value!=null)
256+
Assert.Throws(exceptionType,()=>Enum.Parse<T>(value.AsSpan()));
257+
241258
Assert.Throws(exceptionType,()=>Enum.Parse<T>(value));
242259
}
243260
else
244261
{
262+
if(value!=null)
263+
Assert.Throws(exceptionType,()=>Enum.TryParse(enumType,value.AsSpan(),outresult));
264+
245265
Assert.Throws(exceptionType,()=>Enum.TryParse(enumType,value,outresult));
246266
Assert.Equal(default(object),result);
247267
}
@@ -252,10 +272,16 @@ private static void Parse_Generic_Invalid<T>(Type enumType, string value, bool i
252272
Assert.False(Enum.TryParse(enumType,value,ignoreCase,outresult));
253273
Assert.Equal(default(object),result);
254274

275+
if(value!=null)
276+
Assert.Throws(exceptionType,()=>Enum.Parse<T>(value.AsSpan(),ignoreCase));
277+
255278
Assert.Throws(exceptionType,()=>Enum.Parse<T>(value,ignoreCase));
256279
}
257280
else
258281
{
282+
if(value!=null)
283+
Assert.Throws(exceptionType,()=>Enum.TryParse(enumType,value.AsSpan(),ignoreCase,outresult));
284+
259285
Assert.Throws(exceptionType,()=>Enum.TryParse(enumType,value,ignoreCase,outresult));
260286
Assert.Equal(default(object),result);
261287
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp