Skip to content

Commit 0819d37

Browse files
committed
Update tests to reflect issue #1244 fix: remove unnecessary braces in switch cases
Update all existing Select Case tests to reflect the new output format (no block braces when no local variable is declared). Add two new tests: one verifying no blocks are emitted for cases without local declarations, and one verifying blocks are still emitted when local variables are present. https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent 0a7c2a2 commit 0819d37

File tree

9 files changed

+252
-355
lines changed

9 files changed

+252
-355
lines changed

Tests/CSharp/ExpressionTests/ExpressionTests.cs

Lines changed: 111 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -421,17 +421,13 @@ public void Main()
421421
switch (e1)
422422
{
423423
case 0:
424-
{
425-
break;
426-
}
424+
break;
427425
}
428426
429427
switch (e2)
430428
{
431429
case (int)E.A:
432-
{
433-
break;
434-
}
430+
break;
435431
}
436432
437433
}
@@ -464,16 +460,12 @@ public static void Main()
464460
switch (1)
465461
{
466462
case 1:
467-
{
468-
Console.WriteLine(""a"");
469-
break;
470-
}
463+
Console.WriteLine(""a"");
464+
break;
471465
472466
case var @case when @case == 1:
473-
{
474-
Console.WriteLine(""b"");
475-
break;
476-
}
467+
Console.WriteLine(""b"");
468+
break;
477469
478470
}
479471
@@ -2039,10 +2031,8 @@ public static void Main()
20392031
switch (x)
20402032
{
20412033
case (int)E.A:
2042-
{
2043-
Console.WriteLine(""z"");
2044-
break;
2045-
}
2034+
Console.WriteLine(""z"");
2035+
break;
20462036
}
20472037
}
20482038
}");
@@ -2088,26 +2078,18 @@ public void OnLoad(UserInterface? ui)
20882078
switch (ui)
20892079
{
20902080
case object _ when ui is null:
2091-
{
2092-
activity = 1;
2093-
break;
2094-
}
2081+
activity = 1;
2082+
break;
20952083
case UserInterface.Spectrum:
2096-
{
2097-
activity = 2;
2098-
break;
2099-
}
2084+
activity = 2;
2085+
break;
21002086
case UserInterface.Wisdom:
2101-
{
2102-
activity = 3;
2103-
break;
2104-
}
2087+
activity = 3;
2088+
break;
21052089
21062090
default:
2107-
{
2108-
activity = 4;
2109-
break;
2110-
}
2091+
activity = 4;
2092+
break;
21112093
}
21122094
}
21132095
}");
@@ -2206,160 +2188,128 @@ public int OnLoad()
22062188
switch (x)
22072189
{
22082190
case 0:
2209-
{
2210-
continue;
2211-
}
2191+
continue;
22122192
case 1:
2193+
x = 1;
2194+
break;
2195+
case 2:
2196+
return 2;
2197+
case 3:
2198+
throw new Exception();
2199+
case 4:
2200+
if (true)
22132201
{
2214-
x = 1;
2215-
break;
2202+
x = 4;
22162203
}
2217-
case 2:
2204+
else
22182205
{
2219-
return 2;
2206+
return x;
22202207
}
2221-
case 3:
2208+
2209+
break;
2210+
case 5:
2211+
if (true)
22222212
{
2223-
throw new Exception();
2213+
return x;
22242214
}
2225-
case 4:
2215+
else
22262216
{
2227-
if (true)
2228-
{
2229-
x = 4;
2230-
}
2231-
else
2232-
{
2233-
return x;
2234-
}
2217+
x = 5;
2218+
}
22352219
2236-
break;
2220+
break;
2221+
case 6:
2222+
if (true)
2223+
{
2224+
return x;
22372225
}
2238-
case 5:
2226+
else if (false)
22392227
{
2240-
if (true)
2241-
{
2242-
return x;
2243-
}
2244-
else
2245-
{
2246-
x = 5;
2247-
}
2248-
2249-
break;
2228+
x = 6;
22502229
}
2251-
case 6:
2230+
else
22522231
{
2253-
if (true)
2254-
{
2255-
return x;
2256-
}
2257-
else if (false)
2258-
{
2259-
x = 6;
2260-
}
2261-
else
2262-
{
2263-
return x;
2264-
}
2265-
2266-
break;
2232+
return x;
22672233
}
2234+
2235+
break;
22682236
case 7:
2237+
if (true)
22692238
{
2270-
if (true)
2271-
{
2272-
return x;
2273-
}
2274-
2275-
break;
2239+
return x;
22762240
}
2241+
2242+
break;
22772243
case 8:
2244+
if (true)
2245+
return x;
2246+
break;
2247+
case 9:
2248+
if (true)
2249+
x = 9;
2250+
break;
2251+
case 10:
2252+
if (true)
2253+
return x;
2254+
else
2255+
x = 10;
2256+
break;
2257+
case 11:
2258+
if (true)
2259+
x = 11;
2260+
else
2261+
return x;
2262+
break;
2263+
case 12:
2264+
if (true)
2265+
return x;
2266+
else
2267+
return x;
2268+
case 13:
2269+
if (true)
22782270
{
2279-
if (true)
2280-
return x;
2281-
break;
2271+
return x;
22822272
}
2283-
case 9:
2273+
else if (false)
22842274
{
2285-
if (true)
2286-
x = 9;
2287-
break;
2275+
continue;
22882276
}
2289-
case 10:
2277+
else if (false)
22902278
{
2291-
if (true)
2292-
return x;
2293-
else
2294-
x = 10;
2295-
break;
2279+
throw new Exception();
22962280
}
2297-
case 11:
2281+
else if (false)
22982282
{
2299-
if (true)
2300-
x = 11;
2301-
else
2302-
return x;
23032283
break;
23042284
}
2305-
case 12:
2285+
else
23062286
{
2307-
if (true)
2308-
return x;
2309-
else
2310-
return x;
2287+
return x;
23112288
}
2312-
case 13:
2289+
case 14:
2290+
if (true)
23132291
{
2314-
if (true)
2315-
{
2316-
return x;
2317-
}
2318-
else if (false)
2319-
{
2320-
continue;
2321-
}
2322-
else if (false)
2323-
{
2324-
throw new Exception();
2325-
}
2326-
else if (false)
2327-
{
2328-
break;
2329-
}
2330-
else
2331-
{
2332-
return x;
2333-
}
2292+
return x;
23342293
}
2335-
case 14:
2294+
else if (false)
2295+
{
2296+
return x;
2297+
}
2298+
else if (false)
23362299
{
2337-
if (true)
2338-
{
2339-
return x;
2340-
}
2341-
else if (false)
2342-
{
2343-
return x;
2344-
}
2345-
else if (false)
2346-
{
2347-
break;
2348-
}
2349-
23502300
break;
23512301
}
23522302
2303+
break;
2304+
23532305
default:
2306+
if (true)
2307+
{
2308+
return x;
2309+
}
2310+
else
23542311
{
2355-
if (true)
2356-
{
2357-
return x;
2358-
}
2359-
else
2360-
{
2361-
return x;
2362-
}
2312+
return x;
23632313
}
23642314
}
23652315
}
@@ -2402,31 +2352,21 @@ public void S()
24022352
switch (o)
24032353
{
24042354
case var @case when Operators.ConditionalCompareObjectEqual(@case, 1, false):
2405-
{
2406-
j = 1;
2407-
break;
2408-
}
2355+
j = 1;
2356+
break;
24092357
case var case1 when Operators.ConditionalCompareObjectEqual(case1, 2, false):
2410-
{
2411-
j = 2;
2412-
break;
2413-
}
2358+
j = 2;
2359+
break;
24142360
case var case2 when Operators.ConditionalCompareObjectLessEqual(3, case2, false) && Operators.ConditionalCompareObjectLessEqual(case2, 4, false):
2415-
{
2416-
j = 3;
2417-
break;
2418-
}
2361+
j = 3;
2362+
break;
24192363
case var case3 when Operators.ConditionalCompareObjectGreater(case3, 4, false):
2420-
{
2421-
j = 4;
2422-
break;
2423-
}
2364+
j = 4;
2365+
break;
24242366
24252367
default:
2426-
{
2427-
j = -1;
2428-
break;
2429-
}
2368+
j = -1;
2369+
break;
24302370
}
24312371
}
24322372
}

Tests/CSharp/MemberTests/PropertyMemberTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,12 @@ public void ReturnWhatever(MyEnum m)
323323
switch (m)
324324
{
325325
case (MyEnum)(-1):
326-
{
327-
return;
328-
}
326+
return;
329327
case MyEnum.First:
330-
{
331-
return;
332-
}
328+
return;
333329
case (MyEnum)3:
334-
{
335-
set_MyProp(4, enumerableThing.ToArray()[(int)m]);
336-
return;
337-
}
330+
set_MyProp(4, enumerableThing.ToArray()[(int)m]);
331+
return;
338332
}
339333
}
340334
}");

0 commit comments

Comments
 (0)