Skip to content

Commit

Permalink
better string list for supporting case-sensitive lists
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Sep 16, 2024
1 parent 2d9ece2 commit 622eb66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit 622eb66

Please sign in to comment.