From 322e5a422b59729130ad32812c5282c06815f36b Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 17 Oct 2023 17:48:30 +0900 Subject: [PATCH] Add arguments as second sort key for functions. --- schema/schema.go | 5 ++++- schema/schema_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/schema/schema.go b/schema/schema.go index 2b9f6f0d..6097e76d 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -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 diff --git a/schema/schema_test.go b/schema/schema_test.go index ab4c0fde..6678e6df 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -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) @@ -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) {