forked from po3rin/gofmtmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gofmtmd_test.go
57 lines (53 loc) · 1.24 KB
/
gofmtmd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gofmtmd_test
import (
"bytes"
"fmt"
"io/ioutil"
"testing"
"github.com/po3rin/gofmtmd"
"github.com/sergi/go-diff/diffmatchpatch"
)
func TestFmtGoCodeInMarkdown(t *testing.T) {
tests := []struct {
name string
inputfile string
goldenfile string
}{
{
name: "with golden file",
inputfile: "./testdata/testdata.md",
goldenfile: "./testdata/golden.md",
},
{
name: "no code should be formatted",
inputfile: "./testdata/golden.md",
goldenfile: "./testdata/golden.md",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
md, err := ioutil.ReadFile(tt.inputfile)
if err != nil {
t.Fatalf("failed to read bytes from %v: ", tt.inputfile)
}
want, err := ioutil.ReadFile(tt.goldenfile)
if err != nil {
t.Fatalf("failed to read bytes from %v: ", tt.inputfile)
}
got, err := gofmtmd.FmtGoCodeInMarkdown(md)
if err != nil {
t.Fatalf("got unexpected error: %v", err)
}
if !bytes.Equal(want, got) {
if !bytes.Equal(got, want) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(want), string(got), false)
fmt.Println(dmp.DiffPrettyText(diffs))
t.Error("unexpected result")
}
}
})
}
}