Skip to content

Commit

Permalink
Update tokens.Name to match what's actually in the service (#9163)
Browse files Browse the repository at this point in the history
* Update tokens.Name to match what's actually in the service

* typo
  • Loading branch information
Frassle committed Mar 11, 2022
1 parent b698ed3 commit 17c652b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions sdk/go/common/tokens/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var nameRestCharRegexp = regexp.MustCompile("^" + nameRestCharRegexpPattern + "$

var NameRegexpPattern = nameFirstCharRegexpPattern + nameRestCharRegexpPattern

const nameFirstCharRegexpPattern = "[A-Za-z_.]"
const nameRestCharRegexpPattern = `[A-Za-z0-9_.-]*`
const nameFirstCharRegexpPattern = "[A-Za-z0-9_.-]"
const nameRestCharRegexpPattern = "[A-Za-z0-9_.-]*"

// IsName checks whether a string is a legal Name.
func IsName(s string) bool {
Expand All @@ -61,7 +61,7 @@ const QNameDelimiter = "/"
var QNameRegexp = regexp.MustCompile(QNameRegexpPattern)
var QNameRegexpPattern = "(" + NameRegexpPattern + "\\" + QNameDelimiter + ")*" + NameRegexpPattern

// IsQName checks whether a string is a legal Name.
// IsQName checks whether a string is a legal QName.
func IsQName(s string) bool {
return s != "" && QNameRegexp.FindString(s) == s
}
Expand Down
29 changes: 15 additions & 14 deletions sdk/go/common/tokens/names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ func TestIsAsName(t *testing.T) {
t.Parallel()

var goodNames = []string{
"simple", // all alpha.
"SiMplE", // mixed-case alpha.
"simple0", // alphanumeric.
"SiMpLe0", // mixed-case alphanumeric.
"_", // permit underscore.
"s1MPl3_", // mixed-case alphanumeric/underscore.
"_s1MPl3", // ditto.
"hy-phy", // permit hyphens.
"simple", // all alpha.
"SiMplE", // mixed-case alpha.
"simple0", // alphanumeric.
"SiMpLe0", // mixed-case alphanumeric.
"_", // permit underscore.
"s1MPl3_", // mixed-case alphanumeric/underscore.
"_s1MPl3", // ditto.
"hy-phy", // permit hyphens.
".dotstart", // start with .
"-hyphenstart", // start with -
"0num", // start with numbers
"9num", // start with numbers
}
for _, nm := range goodNames {
assert.True(t, IsName(nm), "IsName expected to be true: %v", nm)
Expand All @@ -50,12 +54,9 @@ func TestIsAsName(t *testing.T) {
}

var badNames = []string{
"0_s1MPl3", // cannot start with a number.
"namespace/0complex", // ditto.
"namespace/morenamespace/0complex", // ditto.
"s!mple", // bad characters.
"namesp@ce/complex", // ditto.
"namespace/morenamespace/compl#x", // ditto.
"s!mple", // bad characters.
"namesp@ce/complex", // ditto.
"namespace/morenamespace/compl#x", // ditto.
}
for _, nm := range badNames {
assert.False(t, IsName(nm), "IsName expected to be false: %v", nm)
Expand Down

0 comments on commit 17c652b

Please sign in to comment.