diff options
| author | Martin Atkins <mart@degeneration.co.uk> | 2019-09-09 16:08:19 -0700 |
|---|---|---|
| committer | Martin Atkins <mart@degeneration.co.uk> | 2019-09-09 16:08:19 -0700 |
| commit | 6c4344623b6ac528a57f9b80e4622acfab2fde40 (patch) | |
| tree | 83031084d3ab54abbe40e3fd749e439c8b28e9d1 /hclsyntax/public_test.go | |
| parent | 0f5ab3bd563c111077917020c0cbc8c211e1bff3 (diff) | |
Unfold the "hcl" directory up into the root
The main HCL package is more visible this way, and so it's easier than
having to pick it out from dozens of other package directories.
Diffstat (limited to 'hclsyntax/public_test.go')
| -rw-r--r-- | hclsyntax/public_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/hclsyntax/public_test.go b/hclsyntax/public_test.go new file mode 100644 index 0000000..6280998 --- /dev/null +++ b/hclsyntax/public_test.go @@ -0,0 +1,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) + } + }) + } +} |
