mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
This allows use of newer math/big (and later debug/pe) without maintaining a vendored copy somewhere in cmd. Use for math/big, deleting cmd/compile/internal/big. Change-Id: I2bffa7a9ef115015be29fafdb02acc3e7a665d11 Reviewed-on: https://go-review.googlesource.com/31010 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gc
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
)
|
|
|
|
func nodrune(r rune) *Node {
|
|
return nodlit(Val{&Mpint{Val: *big.NewInt(int64(r)), Rune: true}})
|
|
}
|
|
|
|
func nodflt(f float64) *Node {
|
|
return nodlit(Val{&Mpflt{Val: *big.NewFloat(f)}})
|
|
}
|
|
|
|
func TestCaseClauseByConstVal(t *testing.T) {
|
|
tests := []struct {
|
|
a, b *Node
|
|
}{
|
|
// CTFLT
|
|
{nodflt(0.1), nodflt(0.2)},
|
|
// CTINT
|
|
{nodintconst(0), nodintconst(1)},
|
|
// CTRUNE
|
|
{nodrune('a'), nodrune('b')},
|
|
// CTSTR
|
|
{nodlit(Val{"ab"}), nodlit(Val{"abc"})},
|
|
{nodlit(Val{"ab"}), nodlit(Val{"xyz"})},
|
|
{nodlit(Val{"abc"}), nodlit(Val{"xyz"})},
|
|
}
|
|
for i, test := range tests {
|
|
a := caseClause{node: nod(OXXX, test.a, nil)}
|
|
b := caseClause{node: nod(OXXX, test.b, nil)}
|
|
s := caseClauseByConstVal{a, b}
|
|
if less := s.Less(0, 1); !less {
|
|
t.Errorf("%d: caseClauseByConstVal(%v, %v) = false", i, test.a, test.b)
|
|
}
|
|
if less := s.Less(1, 0); less {
|
|
t.Errorf("%d: caseClauseByConstVal(%v, %v) = true", i, test.a, test.b)
|
|
}
|
|
}
|
|
}
|