elvish/pkg/eval/vals/repr_test.go

46 lines
910 B
Go
Raw Normal View History

package vals
import (
"fmt"
2021-04-05 08:50:22 +08:00
"math/big"
"os"
"testing"
"src.elv.sh/pkg/tt"
)
type reprer struct{}
func (reprer) Repr(int) string { return "<reprer>" }
type nonReprer struct{}
func TestReprPlain(t *testing.T) {
tt.Test(t, tt.Fn("ReprPlain", ReprPlain), tt.Table{
Args(nil).Rets("$nil"),
2021-04-05 08:50:22 +08:00
Args(false).Rets("$false"),
Args(true).Rets("$true"),
2021-04-05 08:50:22 +08:00
Args("foo").Rets("foo"),
2021-04-05 08:50:22 +08:00
Args(1).Rets("(num 1)"),
Args(bigInt(z)).Rets("(num " + z + ")"),
Args(big.NewRat(1, 2)).Rets("(num 1/2)"),
Args(1.0).Rets("(num 1.0)"),
Args(1e10).Rets("(num 10000000000.0)"),
2021-04-05 08:50:22 +08:00
Args(os.Stdin).Rets(
fmt.Sprintf("<file{%s %d}>", os.Stdin.Name(), os.Stdin.Fd())),
2021-04-05 08:50:22 +08:00
Args(EmptyList).Rets("[]"),
Args(MakeList("foo", "bar")).Rets("[foo bar]"),
2021-04-05 08:50:22 +08:00
Args(EmptyMap).Rets("[&]"),
Args(MakeMap("foo", "bar")).Rets("[&foo=bar]"),
2021-04-05 08:50:22 +08:00
Args(reprer{}).Rets("<reprer>"),
Args(nonReprer{}).Rets("<unknown {}>"),
})
}