Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better string list for supporting case-sensitive lists #226

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ func (p *Permissions) Validate(vr *ValidationResults) {
// StringList is a wrapper for an array of strings
type StringList []string

func (u *StringList) Equals(other *StringList) bool {
if len(*u) != len(*other) {
return false
}
for _, v := range *u {
if other.find(v) == -1 {
return false
}
}
return true
}

func (u *StringList) find(p string) int {
for idx, t := range *u {
if p == t {
return idx
}
}
return -1
}

// Contains returns true if the list contains the string
func (u *StringList) Contains(p string) bool {
for _, t := range *u {
Expand Down
13 changes: 13 additions & 0 deletions v2/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ func TestStringList(t *testing.T) {
AssertEquals(true, slist.Contains("ONE"), t)
}

func TestStringListEquals(t *testing.T) {
a := &StringList{"a", "B", "c"}
b := &StringList{"a", "B", "c"}
AssertTrue(a.Equals(b), t)

a = &StringList{"a", "B", "c"}
b = &StringList{"a", "b", "c"}
AssertFalse(a.Equals(b), t)

AssertEquals(a.find("b"), -1, t)
AssertEquals(a.find("B"), 1, t)
}

func TestSubjectValid(t *testing.T) {
var s Subject

Expand Down
Loading