forked from hashicorp/hcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
public_test.go
46 lines (43 loc) · 991 Bytes
/
public_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package hclsyntax
import (
"testing"
)
func TestValidIdentifier(t *testing.T) {
tests := []struct {
Input string
Want bool
}{
{"", false},
{"hello", true},
{"hello.world", false},
{"hello ", false},
{" hello", false},
{"hello\n", false},
{"hello world", false},
{"aws_instance", true},
{"aws.instance", false},
{"foo-bar", true},
{"foo--bar", true},
{"foo_", true},
{"foo-", true},
{"_foobar", true},
{"-foobar", false},
{"blah1", true},
{"blah1blah", true},
{"1blah1blah", false},
{"héllo", true}, // combining acute accent
{"Χαίρετε", true},
{"звать", true},
{"今日は", true},
{"\x80", false}, // UTF-8 continuation without an introducer
{"a\x80", false}, // UTF-8 continuation after a non-introducer
}
for _, test := range tests {
t.Run(test.Input, func(t *testing.T) {
got := ValidIdentifier(test.Input)
if got != test.Want {
t.Errorf("wrong result %#v; want %#v", got, test.Want)
}
})
}
}