File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,16 @@ extension EnumCaseParameterSyntax {
68
68
}
69
69
}
70
70
71
+ extension FloatLiteralExprSyntax {
72
+ public var floatingValue : Double ? {
73
+ let floatingDigitsWithoutUnderscores = literal. text. filter {
74
+ $0 != " _ "
75
+ }
76
+
77
+ return Double ( floatingDigitsWithoutUnderscores)
78
+ }
79
+ }
80
+
71
81
extension IntegerLiteralExprSyntax {
72
82
public enum Radix {
73
83
case binary
Original file line number Diff line number Diff line change @@ -190,4 +190,17 @@ class SyntaxTests: XCTestCase {
190
190
XCTAssertEqual ( expr. integerValue, expected, line: line)
191
191
}
192
192
}
193
+
194
+ func testFloatLiteralExprSyntax( ) {
195
+ let testCases : [ UInt : ( String , Double ? ) ] = [
196
+ #line: ( " 2 " , 2 ) ,
197
+ #line: ( " 2_00_00.001 " , 20000.001 ) ,
198
+ ]
199
+
200
+ for (line, testCase) in testCases {
201
+ let ( value, expected) = testCase
202
+ let expr = FloatLiteralExprSyntax ( literal: . floatLiteral( value) )
203
+ XCTAssertEqual ( expr. floatingValue, expected, line: line)
204
+ }
205
+ }
193
206
}
You can’t perform that action at this time.
0 commit comments