github.com/elves/elvish@v0.15.0/pkg/eval/vals/repr_test.go (about) 1 package vals 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 . "github.com/elves/elvish/pkg/tt" 9 ) 10 11 type reprer struct{} 12 13 func (reprer) Repr(int) string { return "<reprer>" } 14 15 type nonReprer struct{} 16 17 func repr(a interface{}) string { return Repr(a, NoPretty) } 18 19 func TestRepr(t *testing.T) { 20 Test(t, Fn("repr", repr), Table{ 21 Args(nil).Rets("$nil"), 22 Args(false).Rets("$false"), 23 Args(true).Rets("$true"), 24 Args("foo").Rets("foo"), 25 Args(1.0).Rets("(float64 1)"), 26 Args(1e10).Rets("(float64 10000000000)"), 27 Args(os.Stdin).Rets( 28 fmt.Sprintf("<file{%s %d}>", os.Stdin.Name(), os.Stdin.Fd())), 29 Args(EmptyList).Rets("[]"), 30 Args(MakeList("foo", "bar")).Rets("[foo bar]"), 31 Args(EmptyMap).Rets("[&]"), 32 Args(MakeMap("foo", "bar")).Rets("[&foo=bar]"), 33 Args(reprer{}).Rets("<reprer>"), 34 Args(nonReprer{}).Rets("<unknown {}>"), 35 }) 36 }