Skip to content

Commit

Permalink
Merge pull request #527 from corydoraspanda/fix/#525/sort-function-ar…
Browse files Browse the repository at this point in the history
…guments

Add arguments as second sort key for functions.
  • Loading branch information
k1LoW authored Oct 17, 2023
2 parents d60127c + 322e5a4 commit e2c1a63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ func (s *Schema) Sort() error {
return s.Relations[i].Table.Name < s.Relations[j].Table.Name
})
sort.SliceStable(s.Functions, func(i, j int) bool {
return s.Functions[i].Name < s.Functions[j].Name
if s.Functions[i].Name != s.Functions[j].Name {
return s.Functions[i].Name < s.Functions[j].Name
}
return s.Functions[i].Arguments < s.Functions[j].Arguments
})
sort.SliceStable(s.Viewpoints, func(i, j int) bool {
return s.Viewpoints[i].Name < s.Viewpoints[j].Name
Expand Down
15 changes: 15 additions & 0 deletions schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ func TestSchema_Sort(t *testing.T) {
},
},
},
Functions: []*Function{
&Function{
Name: "b",
Arguments: "arg b",
},
&Function{
Name: "b",
Arguments: "arg a",
},
},
}
if err := schema.Sort(); err != nil {
t.Error(err)
Expand All @@ -224,6 +234,11 @@ func TestSchema_Sort(t *testing.T) {
if got2 != want2 {
t.Errorf("got %v\nwant %v", got2, want2)
}
want3 := "arg a"
got3 := schema.Functions[0].Arguments
if got3 != want3 {
t.Errorf("got %v\nwant %v", got3, want3)
}
}

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

0 comments on commit e2c1a63

Please sign in to comment.