github.com/elves/elvish@v0.15.0/pkg/eval/vals/string_test.go (about)

     1  package vals
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	. "github.com/elves/elvish/pkg/tt"
     8  )
     9  
    10  func TestToString(t *testing.T) {
    11  	Test(t, Fn("ToString", ToString), Table{
    12  		// string
    13  		Args("a").Rets("a"),
    14  
    15  		// float64
    16  		Args(42.0).Rets("42"),
    17  		Args(0.1).Rets("0.1"),
    18  		// Whole numbers with more than 14 digits and trailing 0 are printed in
    19  		// scientific notation.
    20  		Args(1e13).Rets("10000000000000"),
    21  		Args(1e14).Rets("1e+14"),
    22  		Args(1e14 + 1).Rets("100000000000001"),
    23  		// Numbers smaller than 0.0001 are printed in scientific notation.
    24  		Args(0.0001).Rets("0.0001"),
    25  		Args(0.00001).Rets("1e-05"),
    26  		Args(0.00009).Rets("9e-05"),
    27  
    28  		// Stringer
    29  		Args(bytes.NewBufferString("buffer")).Rets("buffer"),
    30  		// None of the above: delegate to Repr
    31  		Args(true).Rets("$true"),
    32  	})
    33  }