github.com/Aoi-hosizora/ahlib-more@v1.5.1-0.20230404072844-256112befaf6/xdiff/xdiff_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "github.com/pmezard/go-difflib/difflib" 6 "testing" 7 ) 8 9 func TestDiff(t *testing.T) { 10 ud := difflib.UnifiedDiff{ 11 A: difflib.SplitLines("0 a\n1 b\n2 c\n\n\n3 d \n4 e\n5 f\n6 g"), 12 B: difflib.SplitLines("1 b\n\n2 c\n\n3 d\n5 f\n7 h\n6 g\n8 ii"), 13 FromFile: "A", 14 FromDate: "date_a", 15 ToFile: "B", 16 ToDate: "date_b", 17 Context: 2, 18 } 19 text, _ := difflib.GetUnifiedDiffString(ud) 20 // fmt.Println(text) 21 // fmt.Print("=============================================\n\n") 22 text = UnifiedDiffString(&ud) 23 fmt.Println(text) 24 fmt.Print("=============================================\n\n") 25 26 cd := difflib.ContextDiff(ud) 27 text, _ = difflib.GetContextDiffString(cd) 28 // fmt.Println(text) 29 // fmt.Print("=============================================\n\n") 30 text = ContextDiffString(&cd) 31 fmt.Println(text) 32 fmt.Print("=============================================\n\n") 33 }