Skip to content

Commit

Permalink
tests: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 24, 2022
1 parent d4f0d83 commit 02e2cff
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 44 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.18

require (
github.com/ettle/strcase v0.1.1
github.com/hexops/gotextdiff v1.0.3
github.com/stretchr/testify v1.7.4
)

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw=
github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
12 changes: 2 additions & 10 deletions mocktail_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package main

import (
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"

"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -53,12 +50,7 @@ func TestMocktail(t *testing.T) {
goldenBytes, err := os.ReadFile(path + ".golden")
require.NoError(t, err)

edits := myers.ComputeEdits(span.URIFromPath(d.Name()), string(genBytes), string(goldenBytes))

if len(edits) > 0 {
diff := fmt.Sprint(gotextdiff.ToUnified(d.Name(), d.Name()+".golden", string(genBytes), edits))
t.Error(diff)
}
assert.Equal(t, string(goldenBytes), string(genBytes))

return nil
})
Expand Down
62 changes: 31 additions & 31 deletions syrup.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,37 +220,6 @@ func (s Syrup) writeReturnsFnCaller(w *Writer, argNames []string, params, result
}
}

func (s Syrup) createFuncSignature(params, results *types.Tuple) string {
fnSign := "func("
for i := 0; i < params.Len(); i++ {
param := params.At(i)
if param.Type().String() == contextType {
continue
}

fnSign += s.getTypeName(param.Type(), i == params.Len()-1)

if i+1 < params.Len() {
fnSign += ", "
}
}
fnSign += ") "

if results != nil {
fnSign += "("
for i := 0; i < results.Len(); i++ {
rType := results.At(i).Type()
fnSign += s.getTypeName(rType, false)
if i+1 < results.Len() {
fnSign += ", "
}
}
fnSign += ")"
}

return fnSign
}

func (s Syrup) methodOn(writer io.Writer) error {
w := &Writer{writer: writer}

Expand Down Expand Up @@ -651,6 +620,37 @@ func (s Syrup) getTupleTypes(t *types.Tuple) []string {
return tupleTypes
}

func (s Syrup) createFuncSignature(params, results *types.Tuple) string {
fnSign := "func("
for i := 0; i < params.Len(); i++ {
param := params.At(i)
if param.Type().String() == contextType {
continue
}

fnSign += s.getTypeName(param.Type(), i == params.Len()-1)

if i+1 < params.Len() {
fnSign += ", "
}
}
fnSign += ") "

if results != nil {
fnSign += "("
for i := 0; i < results.Len(); i++ {
rType := results.At(i).Type()
fnSign += s.getTypeName(rType, false)
if i+1 < results.Len() {
fnSign += ", "
}
}
fnSign += ")"
}

return fnSign
}

func writeImports(writer io.Writer, descPkg PackageDesc) error {
base := template.New("templateImports")

Expand Down

0 comments on commit 02e2cff

Please sign in to comment.