File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ package astequal
2+
3+ import (
4+ "bytes"
5+ "go/ast"
6+ "go/format"
7+ "go/token"
8+
9+ "github.com/google/go-cmp/cmp"
10+ )
11+
12+ func Diff (x , y ast.Node ) string {
13+ var buf bytes.Buffer
14+ format .Node (& buf , token .NewFileSet (), x )
15+ s1 := buf .String ()
16+
17+ buf .Reset ()
18+ format .Node (& buf , token .NewFileSet (), y )
19+ s2 := buf .String ()
20+
21+ // TODO(cristaloleg): replace with a more lightweight diff impl.
22+ return cmp .Diff (s1 , s2 )
23+ }
Original file line number Diff line number Diff line change 44
55require (
66 github.com/go-toolsmith/strparse v1.1.0
7+ github.com/google/go-cmp v0.6.0
78 golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9
89)
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ github.com/go-toolsmith/astequal v1.0.3/go.mod h1:9Ai4UglvtR+4up+bAD4+hCj7iTo4m/
22github.com/go-toolsmith/strparse v1.0.0 /go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8 =
33github.com/go-toolsmith/strparse v1.1.0 h1:GAioeZUK9TGxnLS+qfdqNbA4z0SSm5zVNtCQiyP2Bvw =
44github.com/go-toolsmith/strparse v1.1.0 /go.mod h1:7ksGy58fsaQkGQlY8WVoBFNyEPMGuJin1rfoPS4lBSQ =
5+ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI =
6+ github.com/google/go-cmp v0.6.0 /go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY =
57golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171 /go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk =
68golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9 h1:6WHiuFL9FNjg8RljAaT7FNUuKDbvMqS1i5cr2OE2sLQ =
79golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9 /go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk =
You can’t perform that action at this time.
0 commit comments