github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/compile/internal/gc/swt_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gc 6 7 import ( 8 "math/big" 9 "testing" 10 ) 11 12 func nodrune(r rune) *Node { 13 return nodlit(Val{&Mpint{Val: *big.NewInt(int64(r)), Rune: true}}) 14 } 15 16 func nodflt(f float64) *Node { 17 return nodlit(Val{&Mpflt{Val: *big.NewFloat(f)}}) 18 } 19 20 func TestCaseClauseByConstVal(t *testing.T) { 21 tests := []struct { 22 a, b *Node 23 }{ 24 // CTFLT 25 {nodflt(0.1), nodflt(0.2)}, 26 // CTINT 27 {nodintconst(0), nodintconst(1)}, 28 // CTRUNE 29 {nodrune('a'), nodrune('b')}, 30 // CTSTR 31 {nodlit(Val{"ab"}), nodlit(Val{"abc"})}, 32 {nodlit(Val{"ab"}), nodlit(Val{"xyz"})}, 33 {nodlit(Val{"abc"}), nodlit(Val{"xyz"})}, 34 } 35 for i, test := range tests { 36 a := caseClause{node: nod(OXXX, test.a, nil)} 37 b := caseClause{node: nod(OXXX, test.b, nil)} 38 s := caseClauseByConstVal{a, b} 39 if less := s.Less(0, 1); !less { 40 t.Errorf("%d: caseClauseByConstVal(%v, %v) = false", i, test.a, test.b) 41 } 42 if less := s.Less(1, 0); less { 43 t.Errorf("%d: caseClauseByConstVal(%v, %v) = true", i, test.a, test.b) 44 } 45 } 46 }