2019-04-20 00:40:45 +08:00
|
|
|
package vals
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
. "src.elv.sh/pkg/tt"
|
2019-04-20 00:40:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type reprer struct{}
|
|
|
|
|
|
|
|
func (reprer) Repr(int) string { return "<reprer>" }
|
|
|
|
|
|
|
|
type nonReprer struct{}
|
|
|
|
|
|
|
|
func repr(a interface{}) string { return Repr(a, NoPretty) }
|
|
|
|
|
|
|
|
func TestRepr(t *testing.T) {
|
2020-01-07 07:14:51 +08:00
|
|
|
Test(t, Fn("repr", repr), Table{
|
2019-04-20 00:40:45 +08:00
|
|
|
Args(nil).Rets("$nil"),
|
|
|
|
Args(false).Rets("$false"),
|
|
|
|
Args(true).Rets("$true"),
|
|
|
|
Args("foo").Rets("foo"),
|
2021-04-04 07:58:53 +08:00
|
|
|
Args(1.0).Rets("(num 1.0)"),
|
|
|
|
Args(1e10).Rets("(num 10000000000.0)"),
|
2019-04-20 00:40:45 +08:00
|
|
|
Args(os.Stdin).Rets(
|
|
|
|
fmt.Sprintf("<file{%s %d}>", os.Stdin.Name(), os.Stdin.Fd())),
|
|
|
|
Args(EmptyList).Rets("[]"),
|
|
|
|
Args(MakeList("foo", "bar")).Rets("[foo bar]"),
|
|
|
|
Args(EmptyMap).Rets("[&]"),
|
2019-04-20 01:26:27 +08:00
|
|
|
Args(MakeMap("foo", "bar")).Rets("[&foo=bar]"),
|
2019-04-20 00:40:45 +08:00
|
|
|
Args(reprer{}).Rets("<reprer>"),
|
|
|
|
Args(nonReprer{}).Rets("<unknown {}>"),
|
|
|
|
})
|
|
|
|
}
|