aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-toolsmith/astequal/diff.go
blob: cd69b4525055782590c7a229fe60857f2e51220c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package astequal

import (
	"bytes"
	"go/ast"
	"go/format"
	"go/token"

	"github.com/google/go-cmp/cmp"
)

func Diff(x, y ast.Node) string {
	var buf bytes.Buffer
	format.Node(&buf, token.NewFileSet(), x)
	s1 := buf.String()

	buf.Reset()
	format.Node(&buf, token.NewFileSet(), y)
	s2 := buf.String()

	// TODO(cristaloleg): replace with a more lightweight diff impl.
	return cmp.Diff(s1, s2)
}