@@ -26,7 +26,7 @@ def test_more_than_17_significant_digits
2626 ]
2727
2828 test_cases . each do |input , expected |
29- result = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
29+ result = JSON . parse ( input )
3030 assert_in_delta ( expected , result , 1e-10 ,
3131 "Failed to parse #{ input } correctly (>17 digits, fallback path)" )
3232 end
@@ -37,12 +37,12 @@ def test_decimal_class_option
3737 input = "3.141"
3838
3939 # Without decimal_class: uses Ryu, returns Float
40- result_float = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
40+ result_float = JSON . parse ( input )
4141 assert_instance_of ( Float , result_float )
4242 assert_equal ( 3.141 , result_float )
4343
4444 # With decimal_class: uses fallback, returns BigDecimal
45- result_bigdecimal = JSON . parse ( "[ #{ input } ]" , decimal_class : BigDecimal ) [ 0 ]
45+ result_bigdecimal = JSON . parse ( input , decimal_class : BigDecimal )
4646 assert_instance_of ( BigDecimal , result_bigdecimal )
4747 assert_equal ( BigDecimal ( "3.141" ) , result_bigdecimal )
4848 end if defined? ( ::BigDecimal )
@@ -62,7 +62,7 @@ def test_ryu_optimization_used_for_normal_numbers
6262 ]
6363
6464 test_cases . each do |input , expected |
65- result = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
65+ result = JSON . parse ( input )
6666 assert_in_delta ( expected , result , expected . abs * 1e-15 ,
6767 "Failed to parse #{ input } correctly (<=17 digits, Ryu path)" )
6868 end
@@ -72,12 +72,12 @@ def test_ryu_optimization_used_for_normal_numbers
7272 def test_seventeen_digit_boundary
7373 # Exactly 17 significant digits should use Ryu
7474 input_17 = "12345678901234567.0" # Force it to be a float with .0
75- result = JSON . parse ( "[ #{ input_17 } ]" ) [ 0 ]
75+ result = JSON . parse ( input_17 )
7676 assert_in_delta ( 12345678901234567.0 , result , 1e-10 )
7777
7878 # 18 significant digits should use fallback
7979 input_18 = "123456789012345678.0"
80- result = JSON . parse ( "[ #{ input_18 } ]" ) [ 0 ]
80+ result = JSON . parse ( input_18 )
8181 # Note: This will be rounded to double precision
8282 assert_in_delta ( 123456789012345680.0 , result , 1e-10 )
8383 end
@@ -90,7 +90,7 @@ def test_leading_zeros_dont_count
9090 ]
9191
9292 test_cases . each do |input , expected |
93- result = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
93+ result = JSON . parse ( input )
9494 assert_in_delta ( expected , result , expected . abs * 1e-10 ,
9595 "Failed to parse #{ input } correctly" )
9696 end
@@ -104,17 +104,17 @@ def test_special_double_values
104104 ]
105105
106106 test_cases . each do |input , expected |
107- result = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
107+ result = JSON . parse ( input )
108108 assert_in_delta ( expected , result , expected . abs * 1e-10 ,
109109 "Failed to parse #{ input } correctly" )
110110 end
111111
112112 # Test zero separately
113- result_pos_zero = JSON . parse ( "[ 0.0]" ) [ 0 ]
113+ result_pos_zero = JSON . parse ( "0.0" )
114114 assert_equal ( 0.0 , result_pos_zero )
115115
116116 # Note: JSON.parse doesn't preserve -0.0 vs +0.0 distinction in standard mode
117- result_neg_zero = JSON . parse ( "[ -0.0]" ) [ 0 ]
117+ result_neg_zero = JSON . parse ( "-0.0" )
118118 assert_equal ( 0.0 , result_neg_zero . abs )
119119 end
120120
@@ -132,10 +132,10 @@ def test_subnormal_edge_cases_round_trip
132132
133133 test_cases . each do |input |
134134 # Parse the number
135- result = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
135+ result = JSON . parse ( input )
136136
137137 # Re-parse to verify round-trip
138- result2 = JSON . parse ( "[ #{ input } ]" ) [ 0 ]
138+ result2 = JSON . parse ( result . to_s )
139139
140140 # Should be bit-identical
141141 assert_equal ( result , result2 ,
@@ -161,7 +161,7 @@ def test_invalid_numbers_rejected
161161
162162 invalid_cases . each do |input |
163163 assert_raise ( JSON ::ParserError , "Should reject invalid number: #{ input } " ) do
164- JSON . parse ( "[ #{ input } ]" )
164+ JSON . parse ( input )
165165 end
166166 end
167167 end
0 commit comments