Skip to content

Commit

Permalink
refactor: moved not gofmt-ed code to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrukowski committed Mar 2, 2024
1 parent 54a7009 commit efe1a5c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ run:

issues:
exclude-rules:
- path: exporters_test.go
- path: exporters_ignore_gofmt_test.go
text: "File is not `gofumpt`-ed"
- path: exporters_test.go
- path: exporters_ignore_gofmt_test.go
text: "File is not `gofmt`-ed with `-s`"

linters:
Expand Down
62 changes: 62 additions & 0 deletions exporters_ignore_gofmt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2023–present Bartłomiej Krukowski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package exporter_test

import (
"testing"

"github.com/gontainer/exporter"
"github.com/stretchr/testify/assert"
)

//nolint:testifylint
func TestExport_multidimensionalArray(t *testing.T) {
t.Parallel()

scenarios := []struct {
name string
input any
output string
}{
{
name: "[][2][][]int{{{{1, 2}}, nil}}",
input: [][2][][]int{[2][][]int{[][]int{[]int{int(1), int(2)}}, ([][]int)(nil)}},
output: `[][2][][]int{[2][][]int{[][]int{[]int{int(1), int(2)}}, ([][]int)(nil)}}`,
},
{
name: "[]any{[][]int{{1, 2}, {3, 4}}, ([][][]any)(nil)}",
input: []interface{}{[][]int{[]int{int(1), int(2)}, []int{int(3), int(4)}}, ([][][]interface{})(nil)},
output: `[]interface{}{[][]int{[]int{int(1), int(2)}, []int{int(3), int(4)}}, ([][][]interface{})(nil)}`,
},
}

for _, s := range scenarios {
s := s

t.Run(s.name, func(t *testing.T) {
t.Parallel()

output, err := exporter.Export(s.input)
assert.NoError(t, err)
assert.Equal(t, s.output, output)
})
}
}
22 changes: 8 additions & 14 deletions exporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import (
"github.com/stretchr/testify/require"
)

type myString string
type aliasString = string
type myInt int
type aliasInt = int
type myBool bool
type aliasBool = bool
type (
myString string
aliasString = string
myInt int
aliasInt = int
myBool bool
aliasBool = bool
)

//nolint:testifylint
func TestChainExporter_Export(t *testing.T) {
Expand Down Expand Up @@ -113,10 +115,6 @@ func TestChainExporter_Export(t *testing.T) {
input: [][2][][]int{{{{1, 2}}, nil}},
output: `[][2][][]int{[2][][]int{[][]int{[]int{int(1), int(2)}}, ([][]int)(nil)}}`,
},
`[][2][][]int{{{{1, 2}}, nil}} #2`: {
input: [][2][][]int{[2][][]int{[][]int{[]int{int(1), int(2)}}, ([][]int)(nil)}},
output: `[][2][][]int{[2][][]int{[][]int{[]int{int(1), int(2)}}, ([][]int)(nil)}}`,
},
`[][]any{nil, nil, {(*int)(nil)}}`: {
input: [][]any{nil, nil, {(*int)(nil)}},
error: `cannot export ([][]interface{})[2]: cannot export ([]interface{})[0]: type *int is not supported`,
Expand All @@ -137,10 +135,6 @@ func TestChainExporter_Export(t *testing.T) {
input: []any{[][]int{{1, 2}, {3, 4}}, ([][][]any)(nil)},
output: `[]interface{}{[][]int{[]int{int(1), int(2)}, []int{int(3), int(4)}}, ([][][]interface{})(nil)}`,
},
`[]any{[][]int{{1, 2}, {3, 4}}, ([][][]any)(nil)} #2`: {
input: []interface{}{[][]int{[]int{int(1), int(2)}, []int{int(3), int(4)}}, ([][][]interface{})(nil)},
output: `[]interface{}{[][]int{[]int{int(1), int(2)}, []int{int(3), int(4)}}, ([][][]interface{})(nil)}`,
},
}

for k, s := range scenarios {
Expand Down

0 comments on commit efe1a5c

Please sign in to comment.