diff --git a/internal/app/languages.go b/internal/app/languages.go index 61ca72e..e45caef 100644 --- a/internal/app/languages.go +++ b/internal/app/languages.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "reflect" + "slices" + "strings" gherkin "github.com/cucumber/gherkin/go/v28" "github.com/hedhyw/semerr/pkg/v1/semerr" @@ -15,6 +17,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) + }) +}