Skip to content

nao1215/diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinuxUnitTest MacUnitTest WindowsUnitTest Vuluncheck reviewdog Gosec Coverage

nao1215/diff package

This repository is forked from pmezard/go-difflib by Stein Fletcher. He was maintaining difflib within the apitest package.

When I forked the apitest package as the spectest package, I moved the nao1215/diff package to a separate repository. I do not have the intention to extend the functionality of nao1215/diff, but I will maintain it while maintaining the spectest package.

The difference from the original version is that the standard output ("+++", "---" output) is colored even in the Windows environment. In other words, there is no longer any functional difference from Linux or Mac even on Windows.

What is nao1215/diff package ?

The nao1215/diff is a partial port of python 3 difflib package. Its main goal was to make unified and context diff available in pure Go, mostly for testing purposes.

The following class and functions (and related tests) have be ported:

  • SequenceMatcher
  • unified_diff()
  • context_diff()

Installation

$ go get github.com/nao1215/diff

Supported OS

  • Linux
  • macOS
  • Windows

Quick Start

Diffs are configured with Unified (or ContextDiff) structures, and can be output to an io.Writer or returned as a string.

diff := diff.UnifiedDiff{
    A:        diff.SplitLines("foo\nbar\n"),
    B:        diff.SplitLines("foo\nbaz\n"),
    FromFile: "Original",
    ToFile:   "Current",
    Context:  3,
}
text, _ := diff.GetUnifiedDiffString(diff)
fmt.Printf(text)

would output:

--- Original
+++ Current
@@ -1,3 +1,3 @@
 foo
-bar
+baz

LICENSE

3 clause BSD license. See LICENSE file for details.