github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/go-difflib/README.md (about) 1 go-difflib 2 ========== 3 4 [![Build Status](https://travis-ci.org/pmezard/go-difflib.png?branch=master)](https://travis-ci.org/pmezard/go-difflib) 5 [![GoDoc](https://godoc.org/github.com/pmezard/go-difflib/difflib?status.svg)](https://godoc.org/github.com/pmezard/go-difflib/difflib) 6 7 Go-difflib is a partial port of python 3 difflib package. Its main goal 8 was to make unified and context diff available in pure Go, mostly for 9 testing purposes. 10 11 The following class and functions (and related tests) have be ported: 12 13 * `SequenceMatcher` 14 * `unified_diff()` 15 * `context_diff()` 16 17 ## Installation 18 19 ```bash 20 $ go get github.com/pmezard/go-difflib/difflib 21 ``` 22 23 ### Quick Start 24 25 Diffs are configured with Unified (or ContextDiff) structures, and can 26 be output to an io.Writer or returned as a string. 27 28 ```Go 29 diff := UnifiedDiff{ 30 A: difflib.SplitLines("foo\nbar\n"), 31 B: difflib.SplitLines("foo\nbaz\n"), 32 FromFile: "Original", 33 ToFile: "Current", 34 Context: 3, 35 } 36 text, _ := GetUnifiedDiffString(diff) 37 fmt.Printf(text) 38 ``` 39 40 would output: 41 42 ``` 43 --- Original 44 +++ Current 45 @@ -1,3 +1,3 @@ 46 foo 47 -bar 48 +baz 49 ``` 50