MCPcopy
hub / github.com/tdewolff/minify / TestDecimalTruncate

Function TestDecimalTruncate

common_test.go:106–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestDecimalTruncate(t *testing.T) {
107 numberTests := []struct {
108 number string
109 truncate int
110 expected string
111 }{
112 {"0.1", 1, ".1"},
113 {"0.0001", 1, ".0001"},
114 {"0.111", 1, ".1"},
115 {"0.111", 0, ".111"},
116 {"1.111", 1, "1"},
117 {"0.075", 1, ".08"},
118 {"0.025", 1, ".03"},
119 {"0.105", 2, ".11"},
120 {"0.104", 2, ".1"},
121 {"9.99", 2, "10"},
122 {"9.99", 1, "10"},
123 {"8.88", 2, "8.9"},
124 {"8.88", 1, "9"},
125 {"8.00", 1, "8"},
126 {".88", 1, ".9"},
127 {"1.234", 2, "1.2"},
128 {"33.33", 2, "33"},
129 {"29.666", 2, "30"},
130 {"1.51", 2, "1.5"},
131 {"1.01", 2, "1"},
132 {".99", 1, "1"},
133 {"-16.400000000000006", 3, "-16.4"}, // #233
134 {"1.00000000000001", 15, "1.00000000000001"},
135 {"1.000000000000001", 15, "1"},
136 {"1.000000000000009", 15, "1.00000000000001"},
137 {"100000000000009", 15, "100000000000009"},
138 {"1000000000000009", 15, "1000000000000009"},
139 {"10000000000000009", 15, "10000000000000009"},
140 {"139.99999999", 8, "140"},
141 }
142 for _, tt := range numberTests {
143 t.Run(tt.number, func(t *testing.T) {
144 number := Decimal([]byte(tt.number), tt.truncate)
145 test.Minify(t, tt.number, nil, string(number), tt.expected, "truncate to", tt.truncate)
146 })
147 }
148}
149
150func TestNumber(t *testing.T) {
151 numberTests := []struct {

Callers

nothing calls this directly

Calls 4

DecimalFunction · 0.85
RunMethod · 0.80
MinifyMethod · 0.65
stringFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…