Make the kind of int, *big.Int and *big.Rat "number".

This commit is contained in:
Qi Xiao 2021-06-15 19:22:38 +01:00
parent 3f0e89d223
commit 2e9e0289cc
3 changed files with 7 additions and 2 deletions

View File

@ -51,7 +51,7 @@ func TestConcat(t *testing.T) {
Args(concatter{}, "bar").Rets("concatter bar", nil),
// LHS implements Concatter but returns ErrConcatNotImplemented; RHS
// does not implement RConcatter
Args(concatter{}, 12).Rets(nil, cannotConcat{"!!vals.concatter", "!!int"}),
Args(concatter{}, 12).Rets(nil, cannotConcat{"!!vals.concatter", "number"}),
// LHS implements Concatter but returns another error
Args(concatter{}, 12.0).Rets(nil, errBadFloat64),

View File

@ -2,6 +2,7 @@ package vals
import (
"fmt"
"math/big"
)
// Kinder wraps the Kind method.
@ -27,7 +28,7 @@ func Kind(v interface{}) string {
return "bool"
case string:
return "string"
case float64:
case int, *big.Int, *big.Rat, float64:
return "number"
case Kinder:
return v.Kind()

View File

@ -1,6 +1,7 @@
package vals
import (
"math/big"
"os"
"testing"
@ -14,6 +15,9 @@ func TestKind(t *testing.T) {
Args(nil).Rets("nil"),
Args(true).Rets("bool"),
Args("").Rets("string"),
Args(1).Rets("number"),
Args(bigInt(z)).Rets("number"),
Args(big.NewRat(1, 2)).Rets("number"),
Args(1.0).Rets("number"),
Args(os.Stdin).Rets("file"),
Args(EmptyList).Rets("list"),