Skip to content

Commit

Permalink
go 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Mar 17, 2022
1 parent ad6e326 commit 53b9bab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/domonda/go-pretty

go 1.14
go 1.18
8 changes: 4 additions & 4 deletions print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestSprint(t *testing.T) {

tests := []struct {
name string
value interface{}
value any
want string
}{
{name: "nil", value: nil, want: `nil`},
Expand Down Expand Up @@ -161,12 +161,12 @@ func TestCircularData(t *testing.T) {

circStructsNotNested := [...]*Struct{circStruct, circStruct}

circSlice := make([]interface{}, 1)
circSlice := make([]any, 1)
circSlice[0] = circSlice

tests := []struct {
name string
value interface{}
value any
want string
}{
{
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestCircularData(t *testing.T) {
func TestSpecialTypes(t *testing.T) {
tests := []struct {
name string
value interface{}
value any
want string
}{
{
Expand Down
14 changes: 7 additions & 7 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,33 @@ type Printer struct {
}

// Println pretty prints a value to os.Stdout followed by a newline
func (p *Printer) Println(value interface{}, indent ...string) {
func (p *Printer) Println(value any, indent ...string) {
endsWithNewLine := p.fprintIndent(os.Stdout, value, indent)
if !endsWithNewLine {
os.Stdout.Write([]byte{'\n'}) //#nosec G104
}
}

// Print pretty prints a value to os.Stdout
func (p *Printer) Print(value interface{}, indent ...string) {
func (p *Printer) Print(value any, indent ...string) {
p.fprintIndent(os.Stdout, value, indent)
}

// Fprint pretty prints a value to a io.Writer
func (p *Printer) Fprint(w io.Writer, value interface{}, indent ...string) {
func (p *Printer) Fprint(w io.Writer, value any, indent ...string) {
p.fprintIndent(w, value, indent)
}

// Fprint pretty prints a value to a io.Writer followed by a newline
func (p *Printer) Fprintln(w io.Writer, value interface{}, indent ...string) {
func (p *Printer) Fprintln(w io.Writer, value any, indent ...string) {
endsWithNewLine := p.fprintIndent(w, value, indent)
if !endsWithNewLine {
os.Stdout.Write([]byte{'\n'}) //#nosec G104
}
}

// Sprint pretty prints a value to a string
func (p *Printer) Sprint(value interface{}, indent ...string) string {
func (p *Printer) Sprint(value any, indent ...string) string {
var b strings.Builder
p.fprintIndent(&b, value, indent)
return b.String()
Expand All @@ -87,7 +87,7 @@ func (v visitedPtrs) visit(ptr uintptr) (visited bool) {
return false
}

func (p *Printer) fprintIndent(w io.Writer, value interface{}, indent []string) (endsWithNewLine bool) {
func (p *Printer) fprintIndent(w io.Writer, value any, indent []string) (endsWithNewLine bool) {
switch {
case value == nil:
if len(indent) > 1 {
Expand Down Expand Up @@ -397,7 +397,7 @@ func (p *Printer) sortReflectValues(vals []reflect.Value, valType reflect.Type,
})
}

func quoteString(s interface{}, maxLen int) string {
func quoteString(s any, maxLen int) string {
q := fmt.Sprintf("%#q", s)
if maxLen > 0 && len(q)-2 > maxLen {
// Compare byte length as first approximation,
Expand Down

0 comments on commit 53b9bab

Please # to comment.