File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
CSnakes.SourceGeneration/Parser/Types Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1
- namespace CSnakes . Parser . Types ;
1
+ using System . Globalization ;
2
+
3
+ namespace CSnakes . Parser . Types ;
2
4
3
5
public abstract class PythonConstant
4
6
{
@@ -23,7 +25,7 @@ public sealed class BinaryInteger(long value) : Integer(value)
23
25
public sealed class Float ( double value ) : PythonConstant
24
26
{
25
27
public double Value { get ; } = value ;
26
- public override string ToString ( ) => Value . ToString ( ) ;
28
+ public override string ToString ( ) => Value . ToString ( CultureInfo . InvariantCulture ) ;
27
29
}
28
30
29
31
public sealed class String ( string value ) : PythonConstant
Original file line number Diff line number Diff line change
1
+ using CSnakes . Parser . Types ;
2
+ using System . Globalization ;
3
+
4
+ namespace CSnakes . Tests ;
5
+ public class PythonConstantTests
6
+ {
7
+ public sealed class FloatTests
8
+ {
9
+ [ Fact ]
10
+ public void ToString_Is_Not_Culture_Specific ( )
11
+ {
12
+ var testCulture = ( CultureInfo ) CultureInfo . InvariantCulture . Clone ( ) ;
13
+ testCulture . NumberFormat . NumberDecimalSeparator = "," ;
14
+ testCulture . NumberFormat . NumberGroupSeparator = "." ;
15
+
16
+ var oldCulture = CultureInfo . CurrentCulture ;
17
+ CultureInfo . CurrentCulture = CultureInfo . ReadOnly ( testCulture ) ;
18
+
19
+ try
20
+ {
21
+ var n = new PythonConstant . Float ( 1_737.4 ) ;
22
+ Assert . Equal ( "1737.4" , n . ToString ( ) ) ;
23
+ }
24
+ finally
25
+ {
26
+ CultureInfo . CurrentCulture = oldCulture ;
27
+ }
28
+ }
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments