From 4630d94bac42408b0b581d24e74706fea7337313 Mon Sep 17 00:00:00 2001 From: Dmitrii Malinovskii Date: Mon, 17 Jun 2024 19:54:01 +0400 Subject: [PATCH] sort list of languages --- internal/app/languages.go | 6 +++++ internal/app/languages_private_test.go | 31 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 internal/app/languages_private_test.go diff --git a/internal/app/languages.go b/internal/app/languages.go index 26119ab..d68830c 100644 --- a/internal/app/languages.go +++ b/internal/app/languages.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "reflect" + "slices" + "strings" "github.com/cucumber/common/gherkin/go/v24" ) @@ -14,6 +16,10 @@ func runListFeatureLanguages(out io.Writer) error { return fmt.Errorf("getting feature languages: %w", err) } + slices.SortFunc(languages, func(a, b *gherkin.Dialect) int { + return strings.Compare(a.Language, b.Language) + }) + for _, lang := range languages { fmt.Fprintf(out, "%s\t%s\t%s\n", lang.Language, lang.Name, lang.Native) } diff --git a/internal/app/languages_private_test.go b/internal/app/languages_private_test.go new file mode 100644 index 0000000..dd4303a --- /dev/null +++ b/internal/app/languages_private_test.go @@ -0,0 +1,31 @@ +package app + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRunListFeatureLanguages(t *testing.T) { + t.Parallel() + + t.Run("it produces a stable output", func(t *testing.T) { + t.Parallel() + + var buf bytes.Buffer + + require.NoError(t, runListFeatureLanguages(&buf)) + + out1 := buf.String() + + buf.Reset() + + require.NoError(t, runListFeatureLanguages(&buf)) + + out2 := buf.String() + + assert.Equal(t, out1, out2) + }) +}