mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Fixup for #1354.
This commit is contained in:
parent
85c499f110
commit
d15218f11e
|
@ -10,23 +10,23 @@ import (
|
|||
|
||||
"src.elv.sh/pkg/env"
|
||||
"src.elv.sh/pkg/parse"
|
||||
"src.elv.sh/pkg/testutil"
|
||||
. "src.elv.sh/pkg/testutil"
|
||||
)
|
||||
|
||||
func TestExec_Argv0Argv(t *testing.T) {
|
||||
dir, cleanupFS := testutil.InTestDir()
|
||||
dir, cleanupFS := InTestDir()
|
||||
defer cleanupFS()
|
||||
testutil.ApplyDir(testutil.Dir{
|
||||
"bin": testutil.Dir{
|
||||
"elvish": testutil.File{Perm: 0755},
|
||||
"cat": testutil.File{Perm: 0755},
|
||||
ApplyDir(Dir{
|
||||
"bin": Dir{
|
||||
"elvish": File{Perm: 0755},
|
||||
"cat": File{Perm: 0755},
|
||||
},
|
||||
})
|
||||
|
||||
restorePATH := testutil.WithTempEnv("PATH", dir+"/bin")
|
||||
restorePATH := WithTempEnv("PATH", dir+"/bin")
|
||||
defer restorePATH()
|
||||
|
||||
restoreSHLVL := testutil.WithTempEnv(env.SHLVL, "1")
|
||||
restoreSHLVL := WithTempEnv(env.SHLVL, "1")
|
||||
defer restoreSHLVL()
|
||||
|
||||
var tests = []struct {
|
||||
|
@ -108,7 +108,7 @@ func TestDecSHLVL(t *testing.T) {
|
|||
|
||||
func testDecSHLVL(t *testing.T, oldValue, newValue string) {
|
||||
t.Helper()
|
||||
restore := testutil.WithTempEnv(env.SHLVL, oldValue)
|
||||
restore := WithTempEnv(env.SHLVL, oldValue)
|
||||
defer restore()
|
||||
|
||||
decSHLVL()
|
||||
|
|
|
@ -197,11 +197,16 @@ func ConvertToFloat64(num Num) float64 {
|
|||
case int:
|
||||
return float64(num)
|
||||
case *big.Int:
|
||||
if num.IsInt64() { // might fit in float64
|
||||
// TODO: Make this more robust so the "might fit" is "will fit".
|
||||
if num.IsInt64() {
|
||||
// Number can be converted losslessly to int64, so do that and then
|
||||
// rely on the builtin conversion. Numbers too large to fit in
|
||||
// float64 will be handled appropriately by the builtin conversion,
|
||||
// overflowing to +Inf or -Inf.
|
||||
return float64(num.Int64())
|
||||
}
|
||||
return math.Inf(num.Sign()) // definitely won't fit in float64
|
||||
// Number doesn't fit in int64, so definitely won't fit in float64;
|
||||
// handle this by overflowing.
|
||||
return math.Inf(num.Sign())
|
||||
case *big.Rat:
|
||||
f, _ := num.Float64()
|
||||
return f
|
||||
|
|
Loading…
Reference in New Issue
Block a user