@@ -141,20 +141,34 @@ func TestParseDecimal128(t *testing.T) {
141
141
bigIntTestCase {s : "0.10000000000000000000000000000000000000000001" , remark : "parse fail" },
142
142
bigIntTestCase {s : ".125e1" , h : 0x303c000000000000 , l : 125 },
143
143
bigIntTestCase {s : ".125" , h : 0x303a000000000000 , l : 125 },
144
+ // Test that parsing negative zero returns negative zero with a zero exponent.
145
+ bigIntTestCase {s : "-0" , h : 0xb040000000000000 , l : 0 },
146
+ // Test that parsing negative zero with an in-range exponent returns negative zero and
147
+ // preserves the specified exponent value.
148
+ bigIntTestCase {s : "-0E999" , h : 0xb80e000000000000 , l : 0 },
149
+ // Test that parsing zero with an out-of-range positive exponent returns zero with the
150
+ // maximum positive exponent (i.e. 0e+6111).
151
+ bigIntTestCase {s : "0E2000000000000" , h : 0x5ffe000000000000 , l : 0 },
152
+ // Test that parsing zero with an out-of-range negative exponent returns zero with the
153
+ // minimum negative exponent (i.e. 0e-6176).
154
+ bigIntTestCase {s : "-0E2000000000000" , h : 0xdffe000000000000 , l : 0 },
144
155
bigIntTestCase {s : "" , remark : "parse fail" })
145
156
146
157
for _ , c := range cases {
147
158
t .Run (c .s , func (t * testing.T ) {
148
159
switch c .remark {
149
160
case "overflow" , "parse fail" :
150
161
_ , err := ParseDecimal128 (c .s )
151
- require .Error (t , err )
152
- case "" , "rounding" , "subnormal" , "clamped" , "NaN" , "Infinity" , "-Infinity" :
153
- d128 , err := ParseDecimal128 (c .s )
154
- require .NoError (t , err )
155
-
156
- require .Equal (t , c .h , d128 .h , "case %s" , c .s , d128 .l )
157
- require .Equal (t , c .l , d128 .l , "case %s" , c .s , d128 .h )
162
+ assert .Error (t , err , "ParseDecimal128(%q) should return an error" , c .s )
163
+ default :
164
+ got , err := ParseDecimal128 (c .s )
165
+ require .NoError (t , err , "ParseDecimal128(%q) error" , c .s )
166
+
167
+ want := Decimal128 {h : c .h , l : c .l }
168
+ // Decimal128 doesn't implement an equality function, so compare the expected
169
+ // low/high uint64 values directly. Also print the string representation of each
170
+ // number to make debugging failures easier.
171
+ assert .Equal (t , want , got , "ParseDecimal128(%q) = %s, want %s" , c .s , got , want )
158
172
}
159
173
})
160
174
}
0 commit comments