Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #202 from juanjux/fix/unique_roles
Browse files Browse the repository at this point in the history
Do the duplicate removal on all node roles, not only the new ones.
  • Loading branch information
juanjux authored Nov 7, 2017
2 parents 02f578d + d424c2d commit 92df1df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions uast/ann/ann.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ func AddRoles(roles ...uast.Role) Action {
func appendUniqueRoles(n *uast.Node, roles ...uast.Role) {
addedRoles := make(map[string]bool)

for _, role := range n.Roles {
if _, ok := addedRoles[role.String()]; !ok {
addedRoles[role.String()] = true
}
}

for _, role := range roles {
if _, ok := addedRoles[role.String()]; !ok {
n.Roles = append(n.Roles, role)
Expand Down Expand Up @@ -480,3 +486,4 @@ func matchSuffixPredicates(path uast.Path, preds []Predicate) bool {

return true
}

2 changes: 2 additions & 0 deletions uast/ann/ann_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func TestAddDuplicatedRoles(t *testing.T) {
err := a.Do(input)
require.NoError(err)
require.Equal(expected, input)
err = a.Do(input)
require.Equal(expected, input)
}

func TestRuleOnApply(t *testing.T) {
Expand Down

0 comments on commit 92df1df

Please sign in to comment.