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

Function TestNumberTruncate

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

Source from the content-addressed store, hash-verified

231}
232
233func TestNumberTruncate(t *testing.T) {
234 numberTests := []struct {
235 number string
236 truncate int
237 expected string
238 }{
239 {"0.1", 1, ".1"},
240 {"0.01", 1, ".01"},
241 {"0.001", 1, ".001"},
242 {"0.0001", 1, "1e-4"},
243 {"1000", 0, "1e3"},
244 {"1234", 0, "1234"},
245 {"0.111", 1, ".1"},
246 {"0.111", 0, ".111"},
247 {"0.075", 1, ".08"},
248 {"0.025", 1, ".03"},
249 {"0.105", 2, ".11"},
250 {"0.104", 2, ".1"},
251 {"9.99", 2, "10"},
252 {"9.99", 1, "10"},
253 {"99", 1, "99"},
254 {"999", 1, "1e3"},
255 {"99e1", 1, "1e3"},
256 {"99.9", 1, "100"},
257 {"999.9", 1, "1e3"},
258 {"999.99", 1, "1e3"},
259 {"111.99", 4, "112"},
260 {"8.88", 2, "8.9"},
261 {"8.88", 1, "9"},
262 {"8.00", 1, "8"},
263 {".88", 1, ".9"},
264 {"1.234", 2, "1.2"},
265 {"33.33", 2, "33"},
266 {"29.666", 2, "30"},
267 {"1.51", 2, "1.5"},
268 {"1.51", 1, "2"},
269 {"1.01", 2, "1"},
270 {"1.01", 3, "1.01"},
271 {"1.01", 4, "1.01"},
272 {".99", 1, "1"},
273 {"-16.400000000000006", 3, "-16.4"}, // #233
274 {"1.00000000000001", 15, "1.00000000000001"},
275 {"1.000000000000001", 15, "1"},
276 {"1.000000000000009", 15, "1.00000000000001"},
277 {"100000000000009", 15, "100000000000009"},
278 {"1000000000000009", 15, "1000000000000009"},
279 {"10000000000000009", 15, "1e16"},
280 {"0.0000100000000000009", 15, ".100000000000009e-4"},
281 {".000333336", 0, "333336e-9"},
282 {".0003333337", 0, ".0003333337"},
283 {".000033335", 0, "33335e-9"},
284 {".0000333336", 0, ".333336e-4"},
285 {".00003333337", 0, ".3333337e-4"},
286 {".0000000003333337", 0, ".3333337e-9"},
287 {".00000000003333338", 0, "3333338e-17"},
288 {".333336e-3", 0, "333336e-9"},
289 {".3333337e-3", 0, ".0003333337"},
290 {".33335e-4", 0, "33335e-9"},

Callers

nothing calls this directly

Calls 4

NumberFunction · 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…