Skip to content

Commit

Permalink
utter: code clean up
Browse files Browse the repository at this point in the history
Remove dead code and simplify expressions.
  • Loading branch information
kortschak committed Aug 23, 2021
1 parent fb743d0 commit 4308090
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
4 changes: 2 additions & 2 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
d.w.Write(openParenBytes)
}
typeBytes := []byte(v.Type().String())
d.w.Write(bytes.Replace(typeBytes, interfaceTypeBytes, interfaceBytes, -1))
d.w.Write(bytes.ReplaceAll(typeBytes, interfaceTypeBytes, interfaceBytes))
switch {
case bufferedChan:
switch len := v.Len(); len {
Expand Down Expand Up @@ -350,7 +350,7 @@ func (d *dumpState) dump(v reflect.Value, wasPtr, static bool, addr uintptr) {
d.w.Write(openParenBytes)
}
typeBytes := []byte(v.Type().String())
d.w.Write(bytes.Replace(typeBytes, interfaceTypeBytes, interfaceBytes, -1))
d.w.Write(bytes.ReplaceAll(typeBytes, interfaceTypeBytes, interfaceBytes))
if bufferedChan {
switch len := v.Len(); len {
case 0:
Expand Down
7 changes: 1 addition & 6 deletions internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ type dummyFmtState struct {
}

func (dfs *dummyFmtState) Flag(f int) bool {
if f == int('+') {
return true
}
return false
return f == int('+')
}

func (dfs *dummyFmtState) Precision() (int, bool) {
Expand Down Expand Up @@ -69,7 +66,6 @@ func TestInvalidReflectValue(t *testing.T) {
if s != want {
t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want)
}
i++
}

// changeKind uses unsafe to intentionally change the kind of a reflect.Value to
Expand Down Expand Up @@ -114,7 +110,6 @@ func TestAddedReflectValue(t *testing.T) {
if s != want {
t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
}
i++
}

// SortMapByKeyVals makes the internal sortMapByKeyVals function available
Expand Down
30 changes: 0 additions & 30 deletions spew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package utter_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/kortschak/utter"
Expand Down Expand Up @@ -68,25 +66,6 @@ type utterTest struct {
// tests are handled in the dump and format tests.
var utterTests []utterTest

// redirStdout is a helper function to return the standard output from f as a
// byte slice.
func redirStdout(f func()) ([]byte, error) {
tempFile, err := ioutil.TempFile("", "ss-test")
if err != nil {
return nil, err
}
fileName := tempFile.Name()
defer os.Remove(fileName) // Ignore error

origStdout := os.Stdout
os.Stdout = tempFile
f()
os.Stdout = origStdout
tempFile.Close()

return ioutil.ReadFile(fileName)
}

func initSpewTests() {
// Config states with various settings.
scsDefault := utter.NewDefaultConfig()
Expand Down Expand Up @@ -127,15 +106,6 @@ func initSpewTests() {
elideTypeDefault := utter.NewDefaultConfig()
elideTypeDefault.ElideType = true

// depthTester is used to test max depth handling for structs, array, slices
// and maps.
type depthTester struct {
ic indirCir1
arr [1]string
slice []string
m map[string]int
}

var (
np *int
nip = new(interface{})
Expand Down

0 comments on commit 4308090

Please sign in to comment.