Save the "t" name for the token package

This commit is contained in:
Nigel Tao committed 2017-12-28 11:42:09 +11:00
1 parent 8b0c63df09
commit bdc47bd6e2
3 files changed
+37 -37

No files matched your search

+4 -4
View File
@@ -21,7 +21,7 @@ import (
"github.com/google/wuffs/lang/token" "github.com/google/wuffs/lang/token"
) )
func TestString(t *testing.T) { func TestString(tt *testing.T) {
const filename = "test.wuffs" const filename = "test.wuffs"
testCases := []string{ testCases := []string{
"1", "1",
@@ -74,17 +74,17 @@ func TestString(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
tokens, _, err := token.Tokenize(tm, filename, []byte(tc)) tokens, _, err := token.Tokenize(tm, filename, []byte(tc))
if err != nil { if err != nil {
t.Errorf("Tokenize(%q): %v", tc, err) tt.Errorf("Tokenize(%q): %v", tc, err)
continue continue
} }
expr, err := parse.ParseExpr(tm, filename, tokens, nil) expr, err := parse.ParseExpr(tm, filename, tokens, nil)
if err != nil { if err != nil {
t.Errorf("ParseExpr(%q): %v", tc, err) tt.Errorf("ParseExpr(%q): %v", tc, err)
continue continue
} }
got := expr.Str(tm) got := expr.Str(tm)
if got != tc { if got != tc {
t.Errorf("got %q, want %q", got, tc) tt.Errorf("got %q, want %q", got, tc)
continue continue
} }
} }
+11 -11
View File
@@ -18,25 +18,25 @@ import (
"testing" "testing"
) )
func TestMax(t *testing.T) { func TestMax(tt *testing.T) {
if Max == 38*38*38*38-1 { if Max == 38*38*38*38-1 {
return return
} }
t.Fatal("Max does not satisfy its definition") tt.Fatal("Max does not satisfy its definition")
} }
func TestMaxBits(t *testing.T) { func TestMaxBits(tt *testing.T) {
if (1<<(MaxBits-1) <= Max) && (Max < 1<<MaxBits) { if (1<<(MaxBits-1) <= Max) && (Max < 1<<MaxBits) {
return return
} }
t.Fatal("MaxBits does not satisfy its definition") tt.Fatal("MaxBits does not satisfy its definition")
} }
func mk(a, b, c, d uint32) uint32 { func mk(a, b, c, d uint32) uint32 {
return a*38*38*38 + b*38*38 + c*38 + d return a*38*38*38 + b*38*38 + c*38 + d
} }
func TestValid(t *testing.T) { func TestValid(tt *testing.T) {
testCases := []struct { testCases := []struct {
s string s string
want uint32 want uint32
@@ -64,25 +64,25 @@ func TestValid(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
got, gotOK := Encode(tc.s) got, gotOK := Encode(tc.s)
if !gotOK { if !gotOK {
t.Errorf("%q: ok: got %t, want %t", tc.s, gotOK, true) tt.Errorf("%q: ok: got %t, want %t", tc.s, gotOK, true)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("%q: got %d, want %d", tc.s, got, tc.want) tt.Errorf("%q: got %d, want %d", tc.s, got, tc.want)
continue continue
} }
if got > Max || got > 1<<MaxBits-1 { if got > Max || got > 1<<MaxBits-1 {
t.Errorf("%q: got %d, want <= %d and <= %d", tc.s, got, Max, 1<<MaxBits-1) tt.Errorf("%q: got %d, want <= %d and <= %d", tc.s, got, Max, 1<<MaxBits-1)
continue continue
} }
maxSeen = maxSeen || (got == Max) maxSeen = maxSeen || (got == Max)
} }
if !maxSeen { if !maxSeen {
t.Error("Max was not seen") tt.Error("Max was not seen")
} }
} }
func TestInvalid(t *testing.T) { func TestInvalid(tt *testing.T) {
testCases := []string{ testCases := []string{
"", "",
" ", " ",
@@ -99,7 +99,7 @@ func TestInvalid(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
if _, gotOK := Encode(tc); gotOK { if _, gotOK := Encode(tc); gotOK {
t.Errorf("%q: ok: got %t, want %t", tc, gotOK, false) tt.Errorf("%q: ok: got %t, want %t", tc, gotOK, false)
continue continue
} }
} }
+22 -22
View File
@@ -55,7 +55,7 @@ func compareToWuffsfmt(tm *token.Map, tokens []token.Token, comments []string, s
return nil return nil
} }
func TestCheck(t *testing.T) { func TestCheck(tt *testing.T) {
const filename = "test.wuffs" const filename = "test.wuffs"
src := strings.TrimSpace(` src := strings.TrimSpace(`
packageid "test" packageid "test"
@@ -99,26 +99,26 @@ func TestCheck(t *testing.T) {
tokens, comments, err := token.Tokenize(tm, filename, []byte(src)) tokens, comments, err := token.Tokenize(tm, filename, []byte(src))
if err != nil { if err != nil {
t.Fatalf("Tokenize: %v", err) tt.Fatalf("Tokenize: %v", err)
} }
file, err := parse.Parse(tm, filename, tokens, nil) file, err := parse.Parse(tm, filename, tokens, nil)
if err != nil { if err != nil {
t.Fatalf("Parse: %v", err) tt.Fatalf("Parse: %v", err)
} }
if err := compareToWuffsfmt(tm, tokens, comments, src); err != nil { if err := compareToWuffsfmt(tm, tokens, comments, src); err != nil {
t.Fatalf("compareToWuffsfmt: %v", err) tt.Fatalf("compareToWuffsfmt: %v", err)
} }
c, err := Check(tm, []*ast.File{file}, nil) c, err := Check(tm, []*ast.File{file}, nil)
if err != nil { if err != nil {
t.Fatalf("Check: %v", err) tt.Fatalf("Check: %v", err)
} }
funcs := c.Funcs() funcs := c.Funcs()
if len(funcs) != 1 { if len(funcs) != 1 {
t.Fatalf("Funcs: got %d elements, want 1", len(funcs)) tt.Fatalf("Funcs: got %d elements, want 1", len(funcs))
} }
fooBar := Func{} fooBar := Func{}
for _, f := range funcs { for _, f := range funcs {
@@ -127,7 +127,7 @@ func TestCheck(t *testing.T) {
} }
if got, want := fooBar.QID.Str(tm), "foo.bar"; got != want { if got, want := fooBar.QID.Str(tm), "foo.bar"; got != want {
t.Fatalf("Funcs[0] name: got %q, want %q", got, want) tt.Fatalf("Funcs[0] name: got %q, want %q", got, want)
} }
got := [][2]string(nil) got := [][2]string(nil)
@@ -154,11 +154,11 @@ func TestCheck(t *testing.T) {
{"z", "u64[..123]"}, {"z", "u64[..123]"},
} }
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Fatalf("\ngot %v\nwant %v", got, want) tt.Fatalf("\ngot %v\nwant %v", got, want)
} }
} }
func TestConstValues(t *testing.T) { func TestConstValues(tt *testing.T) {
const filename = "test.wuffs" const filename = "test.wuffs"
testCases := map[string]int64{ testCases := map[string]int64{
"var i i32 = 42": 42, "var i i32 = 42": 42,
@@ -198,25 +198,25 @@ func TestConstValues(t *testing.T) {
tokens, _, err := token.Tokenize(tm, filename, []byte(src)) tokens, _, err := token.Tokenize(tm, filename, []byte(src))
if err != nil { if err != nil {
t.Errorf("%q: Tokenize: %v", s, err) tt.Errorf("%q: Tokenize: %v", s, err)
continue continue
} }
file, err := parse.Parse(tm, filename, tokens, nil) file, err := parse.Parse(tm, filename, tokens, nil)
if err != nil { if err != nil {
t.Errorf("%q: Parse: %v", s, err) tt.Errorf("%q: Parse: %v", s, err)
continue continue
} }
c, err := Check(tm, []*ast.File{file}, nil) c, err := Check(tm, []*ast.File{file}, nil)
if err != nil { if err != nil {
t.Errorf("%q: Check: %v", s, err) tt.Errorf("%q: Check: %v", s, err)
continue continue
} }
funcs := c.Funcs() funcs := c.Funcs()
if len(funcs) != 1 { if len(funcs) != 1 {
t.Errorf("%q: Funcs: got %d elements, want 1", s, len(funcs)) tt.Errorf("%q: Funcs: got %d elements, want 1", s, len(funcs))
continue continue
} }
foo := Func{} foo := Func{}
@@ -226,24 +226,24 @@ func TestConstValues(t *testing.T) {
} }
body := foo.Func.Body() body := foo.Func.Body()
if len(body) != 1 { if len(body) != 1 {
t.Errorf("%q: Body: got %d elements, want 1", s, len(body)) tt.Errorf("%q: Body: got %d elements, want 1", s, len(body))
continue continue
} }
if body[0].Kind() != ast.KVar { if body[0].Kind() != ast.KVar {
t.Errorf("%q: Body[0]: got %s, want %s", s, body[0].Kind(), ast.KVar) tt.Errorf("%q: Body[0]: got %s, want %s", s, body[0].Kind(), ast.KVar)
continue continue
} }
got := body[0].Var().Value().ConstValue() got := body[0].Var().Value().ConstValue()
want := big.NewInt(wantInt64) want := big.NewInt(wantInt64)
if got == nil || want == nil || got.Cmp(want) != 0 { if got == nil || want == nil || got.Cmp(want) != 0 {
t.Errorf("%q: got %v, want %v", s, got, want) tt.Errorf("%q: got %v, want %v", s, got, want)
continue continue
} }
} }
} }
func TestBitMask(t *testing.T) { func TestBitMask(tt *testing.T) {
testCases := [][2]uint64{ testCases := [][2]uint64{
{0, 0}, {0, 0},
{1, 1}, {1, 1},
@@ -276,23 +276,23 @@ func TestBitMask(t *testing.T) {
got := bitMask(big.NewInt(0).SetUint64(tc[0]).BitLen()) got := bitMask(big.NewInt(0).SetUint64(tc[0]).BitLen())
want := big.NewInt(0).SetUint64(tc[1]) want := big.NewInt(0).SetUint64(tc[1])
if got.Cmp(want) != 0 { if got.Cmp(want) != 0 {
t.Errorf("roundUpToPowerOf2Minus1(%v): got %v, want %v", tc[0], got, tc[1]) tt.Errorf("roundUpToPowerOf2Minus1(%v): got %v, want %v", tc[0], got, tc[1])
} }
} }
} }
func TestBuiltInTypeMap(t *testing.T) { func TestBuiltInTypeMap(tt *testing.T) {
if got, want := len(builtInTypeMap), len(builtin.Types); got != want { if got, want := len(builtInTypeMap), len(builtin.Types); got != want {
t.Fatalf("lengths: got %d, want %d", got, want) tt.Fatalf("lengths: got %d, want %d", got, want)
} }
tm := token.Map{} tm := token.Map{}
for _, s := range builtin.Types { for _, s := range builtin.Types {
id := tm.ByName(s) id := tm.ByName(s)
if id == 0 { if id == 0 {
t.Fatalf("ID(%q): got 0, want non-0", s) tt.Fatalf("ID(%q): got 0, want non-0", s)
} }
if _, ok := builtInTypeMap[id]; !ok { if _, ok := builtInTypeMap[id]; !ok {
t.Fatalf("no builtInTypeMap entry for %q", s) tt.Fatalf("no builtInTypeMap entry for %q", s)
} }
} }
} }