in process commit changing computers
							parent
							
								
									be57bab963
								
							
						
					
					
						commit
						c45e5cc948
					
				@ -0,0 +1,5 @@
 | 
			
		||||
module github.com/RageCage64/pretty-diff-reporter
 | 
			
		||||
 | 
			
		||||
go 1.18
 | 
			
		||||
 | 
			
		||||
require github.com/google/go-cmp v0.5.9 // indirect
 | 
			
		||||
@ -0,0 +1,2 @@
 | 
			
		||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
 | 
			
		||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 | 
			
		||||
@ -0,0 +1,54 @@
 | 
			
		||||
package prettyreporter
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/google/go-cmp/cmp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Reporter struct {
 | 
			
		||||
	path      cmp.Path
 | 
			
		||||
	old       []string
 | 
			
		||||
	new       []string
 | 
			
		||||
	diffCount int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Reporter) PushStep(ps cmp.PathStep) {
 | 
			
		||||
	r.path = append(r.path, ps)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Reporter) Report(rs cmp.Result) {
 | 
			
		||||
	vOld, vNew := r.path.Last().Values()
 | 
			
		||||
	if !rs.Equal() {
 | 
			
		||||
		r.diffCount++
 | 
			
		||||
		if vOld.IsValid() {
 | 
			
		||||
			r.old = append(r.old, fmt.Sprintf("%+v", vOld))
 | 
			
		||||
		}
 | 
			
		||||
		if vNew.IsValid() {
 | 
			
		||||
			r.new = append(r.new, fmt.Sprintf("%+v", vNew))
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		r.old = append(r.old, "")
 | 
			
		||||
		r.new = append(r.new, fmt.Sprintf("%+v", vOld))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Reporter) PopStep() {
 | 
			
		||||
	r.path = r.path[:len(r.path)-1]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Reporter) String() string {
 | 
			
		||||
 | 
			
		||||
	return strings.Join(r.lines, "\n")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func maxLen(strs []string) int {
 | 
			
		||||
	max := 0
 | 
			
		||||
	for _, s := range strs {
 | 
			
		||||
		if len(s) > max {
 | 
			
		||||
			max = len(s)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return max
 | 
			
		||||
}
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue