github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/efmt/efmt_test.go (about)

     1  package efmt
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/stretchr/testify/assert"
     6  	"strconv"
     7  	"testing"
     8  )
     9  
    10  var (
    11  	tFormatStr = "hello: name=%s, no=%d, score=%.2f"
    12  	tFormatArg = []interface{}{"James", 10000, 123.456}
    13  )
    14  
    15  func TestSliceRef(t *testing.T) {
    16  	b := new(buffer)
    17  	b.writeString("hello")
    18  	b.writeString("world")
    19  	t.Log(string(*b))
    20  }
    21  
    22  func TestPrinter(t *testing.T) {
    23  	var p Printer
    24  
    25  	v1 := fmt.Sprintf(tFormatStr, tFormatArg...)
    26  	v2 := p.Sprintf(tFormatStr, tFormatArg...)
    27  
    28  	assert.True(t, v1 == string(v2))
    29  }
    30  
    31  // BenchmarkEfmtSprintf-12    	 3754678	       311.5 ns/op	       0 B/op	       0 allocs/op
    32  func BenchmarkEfmtSprintf(b *testing.B) {
    33  	var p Printer
    34  	b.ReportAllocs()
    35  	for i := 0; i < b.N; i++ {
    36  		_ = p.Sprintf(tFormatStr, tFormatArg...)
    37  	}
    38  }
    39  
    40  // BenchmarkStdSprintf-12     	 3251124	       359.8 ns/op	      48 B/op	       1 allocs/op
    41  func BenchmarkStdSprintf(b *testing.B) {
    42  	b.ReportAllocs()
    43  	for i := 0; i < b.N; i++ {
    44  		_ = fmt.Sprintf(tFormatStr, tFormatArg...)
    45  	}
    46  }
    47  
    48  func TestStrconv(t *testing.T) {
    49  	s := strconv.Itoa(1)
    50  	t.Log(s)
    51  }