File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,30 @@ def pretty_print(q)
313
313
end
314
314
end
315
315
316
+ class FloatNode < Node
317
+ def value
318
+ Float ( slice )
319
+ end
320
+ end
321
+
322
+ class ImaginaryNode < Node
323
+ def value
324
+ Complex ( 0 , numeric . value )
325
+ end
326
+ end
327
+
328
+ class IntegerNode < Node
329
+ def value
330
+ Integer ( slice )
331
+ end
332
+ end
333
+
334
+ class RationalNode < Node
335
+ def value
336
+ Rational ( numeric . value )
337
+ end
338
+ end
339
+
316
340
# Load the serialized AST using the source as a reference into a tree.
317
341
def self . load ( source , serialized )
318
342
Serialize . load ( source , serialized )
Original file line number Diff line number Diff line change @@ -19,4 +19,15 @@ def test_ruby_api
19
19
assert_equal_nodes ast1 , ast2
20
20
assert_equal_nodes ast2 , ast3
21
21
end
22
+
23
+ def test_literal_value_method
24
+ assert_equal 123 , YARP . parse ( "123" ) . value . statements . body . first . value
25
+ assert_equal 3.14 , YARP . parse ( "3.14" ) . value . statements . body . first . value
26
+ assert_equal 42 i, YARP . parse ( "42i" ) . value . statements . body . first . value
27
+ assert_equal 3.14 i, YARP . parse ( "3.14i" ) . value . statements . body . first . value
28
+ assert_equal 42 r, YARP . parse ( "42r" ) . value . statements . body . first . value
29
+ assert_equal 0.5 r, YARP . parse ( "0.5r" ) . value . statements . body . first . value
30
+ assert_equal 42 ri, YARP . parse ( "42ri" ) . value . statements . body . first . value
31
+ assert_equal 0.5 ri, YARP . parse ( "0.5ri" ) . value . statements . body . first . value
32
+ end
22
33
end
You can’t perform that action at this time.
0 commit comments