github.com/yandex/pandora@v0.5.32/lib/str/format_test.go (about)

     1  package str
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func BenchmarkFormatString(b *testing.B) {
     8  	n := 1000
     9  	b.ResetTimer()
    10  	for i := 0; i < b.N; i++ {
    11  		FormatString(n)
    12  	}
    13  }
    14  
    15  func TestFormatString(t *testing.T) {
    16  	n := 100.001
    17  	s := FormatString(n)
    18  	t.Log(s)
    19  	if s != "100.001" {
    20  		t.Errorf("%s", s)
    21  	}
    22  }
    23  
    24  func TestMultiFormatString(t *testing.T) {
    25  	list := map[string]interface{}{
    26  		"10":              10,
    27  		"100":             "100",
    28  		"100.001":         100.001,
    29  		"hello":           "hello",
    30  		"[1 2 3]":         []int{1, 2, 3},
    31  		"true":            true,
    32  		"map[name:jason]": map[string]interface{}{"name": "jason"},
    33  	}
    34  	for k, v := range list {
    35  		s := FormatString(v)
    36  		if s != k {
    37  			t.Errorf("Error: %v to %s,but %s", v, k, s)
    38  		}
    39  	}
    40  
    41  }