This commit is contained in:
Qi Xiao 2021-06-27 16:41:07 +01:00
parent 3da541c719
commit 4afab8804b
4 changed files with 12 additions and 9 deletions

View File

@ -658,8 +658,12 @@ func fromLines(fm *Frame) error {
// ```
//
// Takes bytes stdin, parses it as JSON and puts the result on structured stdout.
// The input can contain multiple JSONs, which can, but do not have to, be
// separated with whitespaces.
// The input can contain multiple JSONs, and whitespace between them are ignored.
//
// Note that JSON's only number type corresponds to Elvish's floating-point
// number type, and is always considered [inexact](language.html#exactness).
// It may be necessary to coerce JSON numbers to exact numbers using
// [exact-num](#exact-num).
//
// Examples:
//
@ -715,7 +719,6 @@ func fromJSONInterface(v interface{}) (interface{}, error) {
case nil, bool, string:
return v, nil
case float64:
// TODO: Decide if we want to normalize ints here.
return v, nil
case []interface{}:
vec := vals.EmptyList

View File

@ -69,9 +69,9 @@ func TestStyledConcat(t *testing.T) {
// segment+text
That("print (styled-segment abc &underlined=$true)(styled abc bright-cyan)").Prints("\033[4mabc\033[m\033[96mabc\033[m"),
// segment+num
That("print (float64 99)(styled-segment abc &blink)").Prints("99.0\033[5mabc\033[m"),
That("print (num 99.0)(styled-segment abc &blink)").Prints("99.0\033[5mabc\033[m"),
That("print (num 66)(styled-segment abc &blink)").Prints("66\033[5mabc\033[m"),
That("print (num 33)(styled-segment abc &blink)").Prints("33\033[5mabc\033[m"),
That("print (num 3/2)(styled-segment abc &blink)").Prints("3/2\033[5mabc\033[m"),
// num+segment
That("print (styled-segment abc &blink)(float64 88)").Prints("\033[5mabc\033[m88.0"),
That("print (styled-segment abc &blink)(num 44/3)").Prints("\033[5mabc\033[m44/3"),

View File

@ -27,8 +27,9 @@ func TestEqual(t *testing.T) {
Args("1.0", 1.0).Rets(false),
Args(1, 1.0).Rets(false),
Args(1, 1).Rets(true),
Args(big.NewInt(1), big.NewInt(1)).Rets(true),
Args(big.NewInt(1), 1).Rets(false),
Args(bigInt(z), bigInt(z)).Rets(true),
Args(bigInt(z), 1).Rets(false),
Args(bigInt(z), bigInt(z1)).Rets(false),
Args(big.NewRat(1, 2), big.NewRat(1, 2)).Rets(true),
Args(big.NewRat(1, 2), 0.5).Rets(false),

View File

@ -20,9 +20,8 @@ func ToString(v interface{}) string {
case int:
return strconv.Itoa(v)
case float64:
// Float64 is special-cased for historical reasons. The other number types are handled by
// the Stringer interface.
return formatFloat64(v)
// Other number types handled by "case Stringer"
case string:
return v
case Stringer: