File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 1+ using System . Globalization ;
2+ using Genbox . FastEnum . Tests . CodeGen . Code ;
3+ using Xunit ;
4+
5+ namespace Genbox . FastEnum . Tests . CodeGen ;
6+
7+ public class InvariantCultureTests
8+ {
9+ [ Fact ]
10+ public void ValueParseUsesInvariantCulture ( )
11+ {
12+ CultureInfo original = CultureInfo . CurrentCulture ;
13+ CultureInfo . CurrentCulture = new CultureInfo ( "ar-EG" ) ;
14+
15+ try
16+ {
17+ const string code = """
18+ [FastEnum]
19+ public enum TestEnum : long
20+ {
21+ Negative = -1234,
22+ Positive = 1234567890
23+ }
24+ """ ;
25+
26+ string output = TestHelper . GetGeneratedOutput < EnumGenerator > ( code ) ;
27+
28+ Assert . Contains ( "value.Equals(\" -1234\" " , output ) ;
29+ Assert . Contains ( "value.Equals(\" 1234567890\" " , output ) ;
30+ Assert . DoesNotContain ( '١' , output ) ; //Arabic-Indic digit one; indicates culture bleed
31+ }
32+ finally
33+ {
34+ CultureInfo . CurrentCulture = original ;
35+ }
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -231,7 +231,7 @@ string TryParse()
231231 {
232232 EnumMemberSpec em = members [ i ] ;
233233
234- string escapedValue = EscapeString ( em . Value . ToString ( ) ) ;
234+ string escapedValue = EscapeString ( FormatPrimitive ( em . Value , false ) ) ;
235235
236236 sb . Append ( $$ """
237237
Original file line number Diff line number Diff line change @@ -33,16 +33,16 @@ internal static string EscapeString(string value)
3333 return sb . ToString ( ) ;
3434 }
3535
36- internal static string FormatPrimitive ( object value ) => value switch
36+ internal static string FormatPrimitive ( object value , bool outputTypeLabel = true ) => value switch
3737 {
3838 sbyte sb => sb . ToString ( CultureInfo . InvariantCulture ) ,
3939 byte b => b . ToString ( CultureInfo . InvariantCulture ) ,
4040 short s => s . ToString ( CultureInfo . InvariantCulture ) ,
4141 ushort us => us . ToString ( CultureInfo . InvariantCulture ) ,
4242 int i => i . ToString ( CultureInfo . InvariantCulture ) ,
43- uint ui => ui . ToString ( CultureInfo . InvariantCulture ) + "U" ,
44- long l => l . ToString ( CultureInfo . InvariantCulture ) + "L" ,
45- ulong ul => ul . ToString ( CultureInfo . InvariantCulture ) + "UL" ,
43+ uint ui => ui . ToString ( CultureInfo . InvariantCulture ) + ( outputTypeLabel ? "U" : "" ) ,
44+ long l => l . ToString ( CultureInfo . InvariantCulture ) + ( outputTypeLabel ? "L" : "" ) ,
45+ ulong ul => ul . ToString ( CultureInfo . InvariantCulture ) + ( outputTypeLabel ? "UL" : "" ) ,
4646 _ => throw new InvalidOperationException ( "Unsupported literal type" )
4747 } ;
4848}
You can’t perform that action at this time.
0 commit comments