| 1 |
// Copyright 2019 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 token |
| 6 |
|
| 7 |
import "testing" |
| 8 |
|
| 9 |
func TestIsIdentifier(t *testing.T) { |
| 10 |
tests := []struct { |
| 11 |
name string |
| 12 |
in string |
| 13 |
want bool |
| 14 |
}{ |
| 15 |
{"Empty", "", false}, |
| 16 |
{"Space", " ", false}, |
| 17 |
{"SpaceSuffix", "foo ", false}, |
| 18 |
{"Number", "123", false}, |
| 19 |
{"Keyword", "func", false}, |
| 20 |
|
| 21 |
{"LettersASCII", "foo", true}, |
| 22 |
{"MixedASCII", "_bar123", true}, |
| 23 |
{"UppercaseKeyword", "Func", true}, |
| 24 |
{"LettersUnicode", "fóö", true}, |
| 25 |
} |
| 26 |
for _, test := range tests { |
| 27 |
t.Run(test.name, func(t *testing.T) { |
| 28 |
if got := IsIdentifier(test.in); got != test.want { |
| 29 |
t.Fatalf("IsIdentifier(%q) = %t, want %v", test.in, got, test.want) |
| 30 |
} |
| 31 |
}) |
| 32 |
} |
| 33 |
} |