| 1 |
// Copyright 2013 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 |
// This file checks invariants of token.Token ordering that we rely on |
| 6 |
// since package go/token doesn't provide any guarantees at the moment. |
| 7 |
|
| 8 |
package types |
| 9 |
|
| 10 |
import ( |
| 11 |
"go/token" |
| 12 |
"testing" |
| 13 |
) |
| 14 |
|
| 15 |
var assignOps = map[token.Token]token.Token{ |
| 16 |
token.ADD_ASSIGN: token.ADD, |
| 17 |
token.SUB_ASSIGN: token.SUB, |
| 18 |
token.MUL_ASSIGN: token.MUL, |
| 19 |
token.QUO_ASSIGN: token.QUO, |
| 20 |
token.REM_ASSIGN: token.REM, |
| 21 |
token.AND_ASSIGN: token.AND, |
| 22 |
token.OR_ASSIGN: token.OR, |
| 23 |
token.XOR_ASSIGN: token.XOR, |
| 24 |
token.SHL_ASSIGN: token.SHL, |
| 25 |
token.SHR_ASSIGN: token.SHR, |
| 26 |
token.AND_NOT_ASSIGN: token.AND_NOT, |
| 27 |
} |
| 28 |
|
| 29 |
func TestZeroTok(t *testing.T) { |
| 30 |
// zero value for token.Token must be token.ILLEGAL |
| 31 |
var zero token.Token |
| 32 |
if token.ILLEGAL != zero { |
| 33 |
t.Errorf("%s == %d; want 0", token.ILLEGAL, zero) |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
func TestAssignOp(t *testing.T) { |
| 38 |
// there are fewer than 256 tokens |
| 39 |
for i := 0; i < 256; i++ { |
| 40 |
tok := token.Token(i) |
| 41 |
got := assignOp(tok) |
| 42 |
want := assignOps[tok] |
| 43 |
if got != want { |
| 44 |
t.Errorf("for assignOp(%s): got %s; want %s", tok, got, want) |
| 45 |
} |
| 46 |
} |
| 47 |
} |