Skip to content

Commit

Permalink
sort list of languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrii Malinovskii committed Jun 17, 2024
1 parent 05282c6 commit 4630d94
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/app/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"io"
"reflect"
"slices"
"strings"

"github.com/cucumber/common/gherkin/go/v24"
)
Expand All @@ -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)
}
Expand Down
31 changes: 31 additions & 0 deletions internal/app/languages_private_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}

0 comments on commit 4630d94

Please sign in to comment.