MCPcopy
hub / github.com/shopspring/decimal / TestNewFromFormattedString

Function TestNewFromFormattedString

decimal_test.go:244–271  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

242}
243
244func TestNewFromFormattedString(t *testing.T) {
245 for _, testCase := range []struct {
246 Formatted string
247 Expected string
248 ReplRegex *regexp.Regexp
249 }{
250 {"$10.99", "10.99", regexp.MustCompile("[$]")},
251 {"$ 12.1", "12.1", regexp.MustCompile("[$\\s]")},
252 {"$61,690.99", "61690.99", regexp.MustCompile("[$,]")},
253 {"1_000_000.00", "1000000.00", regexp.MustCompile("[_]")},
254 {"41,410.00", "41410.00", regexp.MustCompile("[,]")},
255 {"5200 USD", "5200", regexp.MustCompile("[USD\\s]")},
256 } {
257 dFormatted, err := NewFromFormattedString(testCase.Formatted, testCase.ReplRegex)
258 if err != nil {
259 t.Fatal(err)
260 }
261
262 dExact, err := NewFromString(testCase.Expected)
263 if err != nil {
264 t.Fatal(err)
265 }
266
267 if !dFormatted.Equal(dExact) {
268 t.Errorf("expect %s, got %s", dExact, dFormatted)
269 }
270 }
271}
272
273func TestFloat64(t *testing.T) {
274 for _, x := range testTable {

Callers

nothing calls this directly

Calls 3

NewFromFormattedStringFunction · 0.85
NewFromStringFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…