forked from mirror/go-ethereum
all: make logs a bit easier on the eye to digest (#22665)
* all: add thousandths separators for big numbers on log messages * p2p/sentry: drop accidental file * common, log: add fast number formatter * common, eth/protocols/snap: simplifty fancy num types * log: handle nil big intsrevert-23120-drop-eth-65
parent
d8ff53dfb8
commit
1e207342b5
@ -0,0 +1,75 @@ |
|||||||
|
package log |
||||||
|
|
||||||
|
import ( |
||||||
|
"math" |
||||||
|
"math/rand" |
||||||
|
"testing" |
||||||
|
) |
||||||
|
|
||||||
|
func TestPrettyInt64(t *testing.T) { |
||||||
|
tests := []struct { |
||||||
|
n int64 |
||||||
|
s string |
||||||
|
}{ |
||||||
|
{0, "0"}, |
||||||
|
{10, "10"}, |
||||||
|
{-10, "-10"}, |
||||||
|
{100, "100"}, |
||||||
|
{-100, "-100"}, |
||||||
|
{1000, "1000"}, |
||||||
|
{-1000, "-1000"}, |
||||||
|
{10000, "10000"}, |
||||||
|
{-10000, "-10000"}, |
||||||
|
{99999, "99999"}, |
||||||
|
{-99999, "-99999"}, |
||||||
|
{100000, "100,000"}, |
||||||
|
{-100000, "-100,000"}, |
||||||
|
{1000000, "1,000,000"}, |
||||||
|
{-1000000, "-1,000,000"}, |
||||||
|
{math.MaxInt64, "9,223,372,036,854,775,807"}, |
||||||
|
{math.MinInt64, "-9,223,372,036,854,775,808"}, |
||||||
|
} |
||||||
|
for i, tt := range tests { |
||||||
|
if have := FormatLogfmtInt64(tt.n); have != tt.s { |
||||||
|
t.Errorf("test %d: format mismatch: have %s, want %s", i, have, tt.s) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func TestPrettyUint64(t *testing.T) { |
||||||
|
tests := []struct { |
||||||
|
n uint64 |
||||||
|
s string |
||||||
|
}{ |
||||||
|
{0, "0"}, |
||||||
|
{10, "10"}, |
||||||
|
{100, "100"}, |
||||||
|
{1000, "1000"}, |
||||||
|
{10000, "10000"}, |
||||||
|
{99999, "99999"}, |
||||||
|
{100000, "100,000"}, |
||||||
|
{1000000, "1,000,000"}, |
||||||
|
{math.MaxUint64, "18,446,744,073,709,551,615"}, |
||||||
|
} |
||||||
|
for i, tt := range tests { |
||||||
|
if have := FormatLogfmtUint64(tt.n); have != tt.s { |
||||||
|
t.Errorf("test %d: format mismatch: have %s, want %s", i, have, tt.s) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var sink string |
||||||
|
|
||||||
|
func BenchmarkPrettyInt64Logfmt(b *testing.B) { |
||||||
|
b.ReportAllocs() |
||||||
|
for i := 0; i < b.N; i++ { |
||||||
|
sink = FormatLogfmtInt64(rand.Int63()) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func BenchmarkPrettyUint64Logfmt(b *testing.B) { |
||||||
|
b.ReportAllocs() |
||||||
|
for i := 0; i < b.N; i++ { |
||||||
|
sink = FormatLogfmtUint64(rand.Uint64()) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue