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 19, 2024
1 parent 8fcf099 commit 42615b2
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"

gherkin "github.com/cucumber/gherkin/go/v28"
"github.com/hedhyw/semerr/pkg/v1/semerr"
Expand All @@ -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)
}
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 42615b2

Please sign in to comment.