Merge pull request #53 from sergi/43-refactor

Refactor everything
diff --git a/diffmatchpatch/benchutil_test.go b/diffmatchpatch/benchutil_test.go
new file mode 100644
index 0000000..b8e404d
--- /dev/null
+++ b/diffmatchpatch/benchutil_test.go
@@ -0,0 +1,28 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"io/ioutil"
+)
+
+const testdataPath = "../testdata/"
+
+func speedtestTexts() (s1 string, s2 string) {
+	d1, err := ioutil.ReadFile(testdataPath + "speedtest1.txt")
+	if err != nil {
+		panic(err)
+	}
+	d2, err := ioutil.ReadFile(testdataPath + "speedtest2.txt")
+	if err != nil {
+		panic(err)
+	}
+
+	return string(d1), string(d2)
+}
diff --git a/diffmatchpatch/diff.go b/diffmatchpatch/diff.go
new file mode 100644
index 0000000..3b39e08
--- /dev/null
+++ b/diffmatchpatch/diff.go
@@ -0,0 +1,1336 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"bytes"
+	"errors"
+	"fmt"
+	"html"
+	"math"
+	"net/url"
+	"regexp"
+	"strconv"
+	"strings"
+	"time"
+	"unicode/utf8"
+)
+
+// Operation defines the operation of a diff item.
+type Operation int8
+
+const (
+	// DiffDelete item represents a delete diff.
+	DiffDelete Operation = -1
+	// DiffInsert item represents an insert diff.
+	DiffInsert Operation = 1
+	// DiffEqual item represents an equal diff.
+	DiffEqual Operation = 0
+)
+
+// Diff represents one diff operation
+type Diff struct {
+	Type Operation
+	Text string
+}
+
+func splice(slice []Diff, index int, amount int, elements ...Diff) []Diff {
+	return append(slice[:index], append(elements, slice[index+amount:]...)...)
+}
+
+// DiffMain finds the differences between two texts.
+func (dmp *DiffMatchPatch) DiffMain(text1, text2 string, checklines bool) []Diff {
+	return dmp.DiffMainRunes([]rune(text1), []rune(text2), checklines)
+}
+
+// DiffMainRunes finds the differences between two rune sequences.
+func (dmp *DiffMatchPatch) DiffMainRunes(text1, text2 []rune, checklines bool) []Diff {
+	var deadline time.Time
+	if dmp.DiffTimeout > 0 {
+		deadline = time.Now().Add(dmp.DiffTimeout)
+	}
+	return dmp.diffMainRunes(text1, text2, checklines, deadline)
+}
+
+func (dmp *DiffMatchPatch) diffMainRunes(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {
+	if runesEqual(text1, text2) {
+		var diffs []Diff
+		if len(text1) > 0 {
+			diffs = append(diffs, Diff{DiffEqual, string(text1)})
+		}
+		return diffs
+	}
+	// Trim off common prefix (speedup).
+	commonlength := commonPrefixLength(text1, text2)
+	commonprefix := text1[:commonlength]
+	text1 = text1[commonlength:]
+	text2 = text2[commonlength:]
+
+	// Trim off common suffix (speedup).
+	commonlength = commonSuffixLength(text1, text2)
+	commonsuffix := text1[len(text1)-commonlength:]
+	text1 = text1[:len(text1)-commonlength]
+	text2 = text2[:len(text2)-commonlength]
+
+	// Compute the diff on the middle block.
+	diffs := dmp.diffCompute(text1, text2, checklines, deadline)
+
+	// Restore the prefix and suffix.
+	if len(commonprefix) != 0 {
+		diffs = append([]Diff{Diff{DiffEqual, string(commonprefix)}}, diffs...)
+	}
+	if len(commonsuffix) != 0 {
+		diffs = append(diffs, Diff{DiffEqual, string(commonsuffix)})
+	}
+
+	return dmp.DiffCleanupMerge(diffs)
+}
+
+// diffCompute finds the differences between two rune slices.  Assumes that the texts do not have any common prefix or suffix.
+func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {
+	diffs := []Diff{}
+	if len(text1) == 0 {
+		// Just add some text (speedup).
+		return append(diffs, Diff{DiffInsert, string(text2)})
+	} else if len(text2) == 0 {
+		// Just delete some text (speedup).
+		return append(diffs, Diff{DiffDelete, string(text1)})
+	}
+
+	var longtext, shorttext []rune
+	if len(text1) > len(text2) {
+		longtext = text1
+		shorttext = text2
+	} else {
+		longtext = text2
+		shorttext = text1
+	}
+
+	if i := runesIndex(longtext, shorttext); i != -1 {
+		op := DiffInsert
+		// Swap insertions for deletions if diff is reversed.
+		if len(text1) > len(text2) {
+			op = DiffDelete
+		}
+		// Shorter text is inside the longer text (speedup).
+		return []Diff{
+			Diff{op, string(longtext[:i])},
+			Diff{DiffEqual, string(shorttext)},
+			Diff{op, string(longtext[i+len(shorttext):])},
+		}
+	} else if len(shorttext) == 1 {
+		// Single character string.
+		// After the previous speedup, the character can't be an equality.
+		return []Diff{
+			Diff{DiffDelete, string(text1)},
+			Diff{DiffInsert, string(text2)},
+		}
+		// Check to see if the problem can be split in two.
+	} else if hm := dmp.diffHalfMatch(text1, text2); hm != nil {
+		// A half-match was found, sort out the return data.
+		text1A := hm[0]
+		text1B := hm[1]
+		text2A := hm[2]
+		text2B := hm[3]
+		midCommon := hm[4]
+		// Send both pairs off for separate processing.
+		diffsA := dmp.diffMainRunes(text1A, text2A, checklines, deadline)
+		diffsB := dmp.diffMainRunes(text1B, text2B, checklines, deadline)
+		// Merge the results.
+		return append(diffsA, append([]Diff{Diff{DiffEqual, string(midCommon)}}, diffsB...)...)
+	} else if checklines && len(text1) > 100 && len(text2) > 100 {
+		return dmp.diffLineMode(text1, text2, deadline)
+	}
+	return dmp.diffBisect(text1, text2, deadline)
+}
+
+// diffLineMode does a quick line-level diff on both []runes, then rediff the parts for greater accuracy. This speedup can produce non-minimal diffs.
+func (dmp *DiffMatchPatch) diffLineMode(text1, text2 []rune, deadline time.Time) []Diff {
+	// Scan the text on a line-by-line basis first.
+	text1, text2, linearray := dmp.diffLinesToRunes(text1, text2)
+
+	diffs := dmp.diffMainRunes(text1, text2, false, deadline)
+
+	// Convert the diff back to original text.
+	diffs = dmp.DiffCharsToLines(diffs, linearray)
+	// Eliminate freak matches (e.g. blank lines)
+	diffs = dmp.DiffCleanupSemantic(diffs)
+
+	// Rediff any replacement blocks, this time character-by-character.
+	// Add a dummy entry at the end.
+	diffs = append(diffs, Diff{DiffEqual, ""})
+
+	pointer := 0
+	countDelete := 0
+	countInsert := 0
+
+	// NOTE: Rune slices are slower than using strings in this case.
+	textDelete := ""
+	textInsert := ""
+
+	for pointer < len(diffs) {
+		switch diffs[pointer].Type {
+		case DiffInsert:
+			countInsert++
+			textInsert += diffs[pointer].Text
+		case DiffDelete:
+			countDelete++
+			textDelete += diffs[pointer].Text
+		case DiffEqual:
+			// Upon reaching an equality, check for prior redundancies.
+			if countDelete >= 1 && countInsert >= 1 {
+				// Delete the offending records and add the merged ones.
+				diffs = splice(diffs, pointer-countDelete-countInsert,
+					countDelete+countInsert)
+
+				pointer = pointer - countDelete - countInsert
+				a := dmp.diffMainRunes([]rune(textDelete), []rune(textInsert), false, deadline)
+				for j := len(a) - 1; j >= 0; j-- {
+					diffs = splice(diffs, pointer, 0, a[j])
+				}
+				pointer = pointer + len(a)
+			}
+
+			countInsert = 0
+			countDelete = 0
+			textDelete = ""
+			textInsert = ""
+		}
+		pointer++
+	}
+
+	return diffs[:len(diffs)-1] // Remove the dummy entry at the end.
+}
+
+// DiffBisect finds the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff.
+// See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
+func (dmp *DiffMatchPatch) DiffBisect(text1, text2 string, deadline time.Time) []Diff {
+	// Unused in this code, but retained for interface compatibility.
+	return dmp.diffBisect([]rune(text1), []rune(text2), deadline)
+}
+
+// diffBisect finds the 'middle snake' of a diff, splits the problem in two and returns the recursively constructed diff.
+// See Myers's 1986 paper: An O(ND) Difference Algorithm and Its Variations.
+func (dmp *DiffMatchPatch) diffBisect(runes1, runes2 []rune, deadline time.Time) []Diff {
+	// Cache the text lengths to prevent multiple calls.
+	runes1Len, runes2Len := len(runes1), len(runes2)
+
+	maxD := (runes1Len + runes2Len + 1) / 2
+	vOffset := maxD
+	vLength := 2 * maxD
+
+	v1 := make([]int, vLength)
+	v2 := make([]int, vLength)
+	for i := range v1 {
+		v1[i] = -1
+		v2[i] = -1
+	}
+	v1[vOffset+1] = 0
+	v2[vOffset+1] = 0
+
+	delta := runes1Len - runes2Len
+	// If the total number of characters is odd, then the front path will collide with the reverse path.
+	front := (delta%2 != 0)
+	// Offsets for start and end of k loop. Prevents mapping of space beyond the grid.
+	k1start := 0
+	k1end := 0
+	k2start := 0
+	k2end := 0
+	for d := 0; d < maxD; d++ {
+		// Bail out if deadline is reached.
+		if !deadline.IsZero() && time.Now().After(deadline) {
+			break
+		}
+
+		// Walk the front path one step.
+		for k1 := -d + k1start; k1 <= d-k1end; k1 += 2 {
+			k1Offset := vOffset + k1
+			var x1 int
+
+			if k1 == -d || (k1 != d && v1[k1Offset-1] < v1[k1Offset+1]) {
+				x1 = v1[k1Offset+1]
+			} else {
+				x1 = v1[k1Offset-1] + 1
+			}
+
+			y1 := x1 - k1
+			for x1 < runes1Len && y1 < runes2Len {
+				if runes1[x1] != runes2[y1] {
+					break
+				}
+				x1++
+				y1++
+			}
+			v1[k1Offset] = x1
+			if x1 > runes1Len {
+				// Ran off the right of the graph.
+				k1end += 2
+			} else if y1 > runes2Len {
+				// Ran off the bottom of the graph.
+				k1start += 2
+			} else if front {
+				k2Offset := vOffset + delta - k1
+				if k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] != -1 {
+					// Mirror x2 onto top-left coordinate system.
+					x2 := runes1Len - v2[k2Offset]
+					if x1 >= x2 {
+						// Overlap detected.
+						return dmp.diffBisectSplit(runes1, runes2, x1, y1, deadline)
+					}
+				}
+			}
+		}
+		// Walk the reverse path one step.
+		for k2 := -d + k2start; k2 <= d-k2end; k2 += 2 {
+			k2Offset := vOffset + k2
+			var x2 int
+			if k2 == -d || (k2 != d && v2[k2Offset-1] < v2[k2Offset+1]) {
+				x2 = v2[k2Offset+1]
+			} else {
+				x2 = v2[k2Offset-1] + 1
+			}
+			var y2 = x2 - k2
+			for x2 < runes1Len && y2 < runes2Len {
+				if runes1[runes1Len-x2-1] != runes2[runes2Len-y2-1] {
+					break
+				}
+				x2++
+				y2++
+			}
+			v2[k2Offset] = x2
+			if x2 > runes1Len {
+				// Ran off the left of the graph.
+				k2end += 2
+			} else if y2 > runes2Len {
+				// Ran off the top of the graph.
+				k2start += 2
+			} else if !front {
+				k1Offset := vOffset + delta - k2
+				if k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] != -1 {
+					x1 := v1[k1Offset]
+					y1 := vOffset + x1 - k1Offset
+					// Mirror x2 onto top-left coordinate system.
+					x2 = runes1Len - x2
+					if x1 >= x2 {
+						// Overlap detected.
+						return dmp.diffBisectSplit(runes1, runes2, x1, y1, deadline)
+					}
+				}
+			}
+		}
+	}
+	// Diff took too long and hit the deadline or number of diffs equals number of characters, no commonality at all.
+	return []Diff{
+		Diff{DiffDelete, string(runes1)},
+		Diff{DiffInsert, string(runes2)},
+	}
+}
+
+func (dmp *DiffMatchPatch) diffBisectSplit(runes1, runes2 []rune, x, y int,
+	deadline time.Time) []Diff {
+	runes1a := runes1[:x]
+	runes2a := runes2[:y]
+	runes1b := runes1[x:]
+	runes2b := runes2[y:]
+
+	// Compute both diffs serially.
+	diffs := dmp.diffMainRunes(runes1a, runes2a, false, deadline)
+	diffsb := dmp.diffMainRunes(runes1b, runes2b, false, deadline)
+
+	return append(diffs, diffsb...)
+}
+
+// DiffLinesToChars splits two texts into a list of strings, and educes the texts to a string of hashes where each Unicode character represents one line.
+// It's slightly faster to call DiffLinesToRunes first, followed by DiffMainRunes.
+func (dmp *DiffMatchPatch) DiffLinesToChars(text1, text2 string) (string, string, []string) {
+	chars1, chars2, lineArray := dmp.DiffLinesToRunes(text1, text2)
+	return string(chars1), string(chars2), lineArray
+}
+
+// DiffLinesToRunes splits two texts into a list of runes.  Each rune represents one line.
+func (dmp *DiffMatchPatch) DiffLinesToRunes(text1, text2 string) ([]rune, []rune, []string) {
+	// '\x00' is a valid character, but various debuggers don't like it. So we'll insert a junk entry to avoid generating a null character.
+	lineArray := []string{""}    // e.g. lineArray[4] == 'Hello\n'
+	lineHash := map[string]int{} // e.g. lineHash['Hello\n'] == 4
+
+	chars1 := dmp.diffLinesToRunesMunge(text1, &lineArray, lineHash)
+	chars2 := dmp.diffLinesToRunesMunge(text2, &lineArray, lineHash)
+
+	return chars1, chars2, lineArray
+}
+
+func (dmp *DiffMatchPatch) diffLinesToRunes(text1, text2 []rune) ([]rune, []rune, []string) {
+	return dmp.DiffLinesToRunes(string(text1), string(text2))
+}
+
+// diffLinesToRunesMunge splits a text into an array of strings, and reduces the texts to a []rune where each Unicode character represents one line.
+// We use strings instead of []runes as input mainly because you can't use []rune as a map key.
+func (dmp *DiffMatchPatch) diffLinesToRunesMunge(text string, lineArray *[]string, lineHash map[string]int) []rune {
+	// Walk the text, pulling out a substring for each line. text.split('\n') would would temporarily double our memory footprint. Modifying text would create many large strings to garbage collect.
+	lineStart := 0
+	lineEnd := -1
+	runes := []rune{}
+
+	for lineEnd < len(text)-1 {
+		lineEnd = indexOf(text, "\n", lineStart)
+
+		if lineEnd == -1 {
+			lineEnd = len(text) - 1
+		}
+
+		line := text[lineStart : lineEnd+1]
+		lineStart = lineEnd + 1
+		lineValue, ok := lineHash[line]
+
+		if ok {
+			runes = append(runes, rune(lineValue))
+		} else {
+			*lineArray = append(*lineArray, line)
+			lineHash[line] = len(*lineArray) - 1
+			runes = append(runes, rune(len(*lineArray)-1))
+		}
+	}
+
+	return runes
+}
+
+// DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of text.
+func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []Diff {
+	hydrated := make([]Diff, 0, len(diffs))
+	for _, aDiff := range diffs {
+		chars := aDiff.Text
+		text := make([]string, len(chars))
+
+		for i, r := range chars {
+			text[i] = lineArray[r]
+		}
+
+		aDiff.Text = strings.Join(text, "")
+		hydrated = append(hydrated, aDiff)
+	}
+	return hydrated
+}
+
+// DiffCommonPrefix determines the common prefix length of two strings.
+func (dmp *DiffMatchPatch) DiffCommonPrefix(text1, text2 string) int {
+	// Unused in this code, but retained for interface compatibility.
+	return commonPrefixLength([]rune(text1), []rune(text2))
+}
+
+// DiffCommonSuffix determines the common suffix length of two strings.
+func (dmp *DiffMatchPatch) DiffCommonSuffix(text1, text2 string) int {
+	// Unused in this code, but retained for interface compatibility.
+	return commonSuffixLength([]rune(text1), []rune(text2))
+}
+
+// commonPrefixLength returns the length of the common prefix of two rune slices.
+func commonPrefixLength(text1, text2 []rune) int {
+	short, long := text1, text2
+	if len(short) > len(long) {
+		short, long = long, short
+	}
+	for i, r := range short {
+		if r != long[i] {
+			return i
+		}
+	}
+	return len(short)
+}
+
+// commonSuffixLength returns the length of the common suffix of two rune slices.
+func commonSuffixLength(text1, text2 []rune) int {
+	n := min(len(text1), len(text2))
+	for i := 0; i < n; i++ {
+		if text1[len(text1)-i-1] != text2[len(text2)-i-1] {
+			return i
+		}
+	}
+	return n
+
+	// TODO research and benchmark this, why is it not activated? https://github.com/sergi/go-diff/issues/54
+	// Binary search.
+	// Performance analysis: http://neil.fraser.name/news/2007/10/09/
+	/*
+	   pointermin := 0
+	   pointermax := math.Min(len(text1), len(text2))
+	   pointermid := pointermax
+	   pointerend := 0
+	   for pointermin < pointermid {
+	       if text1[len(text1)-pointermid:len(text1)-pointerend] ==
+	           text2[len(text2)-pointermid:len(text2)-pointerend] {
+	           pointermin = pointermid
+	           pointerend = pointermin
+	       } else {
+	           pointermax = pointermid
+	       }
+	       pointermid = math.Floor((pointermax-pointermin)/2 + pointermin)
+	   }
+	   return pointermid
+	*/
+}
+
+// DiffCommonOverlap determines if the suffix of one string is the prefix of another.
+func (dmp *DiffMatchPatch) DiffCommonOverlap(text1 string, text2 string) int {
+	// Cache the text lengths to prevent multiple calls.
+	text1Length := len(text1)
+	text2Length := len(text2)
+	// Eliminate the null case.
+	if text1Length == 0 || text2Length == 0 {
+		return 0
+	}
+	// Truncate the longer string.
+	if text1Length > text2Length {
+		text1 = text1[text1Length-text2Length:]
+	} else if text1Length < text2Length {
+		text2 = text2[0:text1Length]
+	}
+	textLength := int(math.Min(float64(text1Length), float64(text2Length)))
+	// Quick check for the worst case.
+	if text1 == text2 {
+		return textLength
+	}
+
+	// Start by looking for a single character match and increase length until no match is found. Performance analysis: http://neil.fraser.name/news/2010/11/04/
+	best := 0
+	length := 1
+	for {
+		pattern := text1[textLength-length:]
+		found := strings.Index(text2, pattern)
+		if found == -1 {
+			break
+		}
+		length += found
+		if found == 0 || text1[textLength-length:] == text2[0:length] {
+			best = length
+			length++
+		}
+	}
+
+	return best
+}
+
+// DiffHalfMatch checks whether the two texts share a substring which is at least half the length of the longer text. This speedup can produce non-minimal diffs.
+func (dmp *DiffMatchPatch) DiffHalfMatch(text1, text2 string) []string {
+	// Unused in this code, but retained for interface compatibility.
+	runeSlices := dmp.diffHalfMatch([]rune(text1), []rune(text2))
+	if runeSlices == nil {
+		return nil
+	}
+
+	result := make([]string, len(runeSlices))
+	for i, r := range runeSlices {
+		result[i] = string(r)
+	}
+	return result
+}
+
+func (dmp *DiffMatchPatch) diffHalfMatch(text1, text2 []rune) [][]rune {
+	if dmp.DiffTimeout <= 0 {
+		// Don't risk returning a non-optimal diff if we have unlimited time.
+		return nil
+	}
+
+	var longtext, shorttext []rune
+	if len(text1) > len(text2) {
+		longtext = text1
+		shorttext = text2
+	} else {
+		longtext = text2
+		shorttext = text1
+	}
+
+	if len(longtext) < 4 || len(shorttext)*2 < len(longtext) {
+		return nil // Pointless.
+	}
+
+	// First check if the second quarter is the seed for a half-match.
+	hm1 := dmp.diffHalfMatchI(longtext, shorttext, int(float64(len(longtext)+3)/4))
+
+	// Check again based on the third quarter.
+	hm2 := dmp.diffHalfMatchI(longtext, shorttext, int(float64(len(longtext)+1)/2))
+
+	hm := [][]rune{}
+	if hm1 == nil && hm2 == nil {
+		return nil
+	} else if hm2 == nil {
+		hm = hm1
+	} else if hm1 == nil {
+		hm = hm2
+	} else {
+		// Both matched.  Select the longest.
+		if len(hm1[4]) > len(hm2[4]) {
+			hm = hm1
+		} else {
+			hm = hm2
+		}
+	}
+
+	// A half-match was found, sort out the return data.
+	if len(text1) > len(text2) {
+		return hm
+	}
+
+	return [][]rune{hm[2], hm[3], hm[0], hm[1], hm[4]}
+}
+
+// diffHalfMatchI checks if a substring of shorttext exist within longtext such that the substring is at least half the length of longtext?
+// Returns a slice containing the prefix of longtext, the suffix of longtext, the prefix of shorttext, the suffix of shorttext and the common middle, or null if there was no match.
+func (dmp *DiffMatchPatch) diffHalfMatchI(l, s []rune, i int) [][]rune {
+	var bestCommonA []rune
+	var bestCommonB []rune
+	var bestCommonLen int
+	var bestLongtextA []rune
+	var bestLongtextB []rune
+	var bestShorttextA []rune
+	var bestShorttextB []rune
+
+	// Start with a 1/4 length substring at position i as a seed.
+	seed := l[i : i+len(l)/4]
+
+	for j := runesIndexOf(s, seed, 0); j != -1; j = runesIndexOf(s, seed, j+1) {
+		prefixLength := commonPrefixLength(l[i:], s[j:])
+		suffixLength := commonSuffixLength(l[:i], s[:j])
+
+		if bestCommonLen < suffixLength+prefixLength {
+			bestCommonA = s[j-suffixLength : j]
+			bestCommonB = s[j : j+prefixLength]
+			bestCommonLen = len(bestCommonA) + len(bestCommonB)
+			bestLongtextA = l[:i-suffixLength]
+			bestLongtextB = l[i+prefixLength:]
+			bestShorttextA = s[:j-suffixLength]
+			bestShorttextB = s[j+prefixLength:]
+		}
+	}
+
+	if bestCommonLen*2 < len(l) {
+		return nil
+	}
+
+	return [][]rune{
+		bestLongtextA,
+		bestLongtextB,
+		bestShorttextA,
+		bestShorttextB,
+		append(bestCommonA, bestCommonB...),
+	}
+}
+
+// DiffCleanupSemantic reduces the number of edits by eliminating semantically trivial equalities.
+func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
+	changes := false
+	// Stack of indices where equalities are found.
+	type equality struct {
+		data int
+		next *equality
+	}
+	var equalities *equality
+
+	var lastequality string
+	// Always equal to diffs[equalities[equalitiesLength - 1]][1]
+	var pointer int // Index of current position.
+	// Number of characters that changed prior to the equality.
+	var lengthInsertions1, lengthDeletions1 int
+	// Number of characters that changed after the equality.
+	var lengthInsertions2, lengthDeletions2 int
+
+	for pointer < len(diffs) {
+		if diffs[pointer].Type == DiffEqual {
+			// Equality found.
+
+			equalities = &equality{
+				data: pointer,
+				next: equalities,
+			}
+			lengthInsertions1 = lengthInsertions2
+			lengthDeletions1 = lengthDeletions2
+			lengthInsertions2 = 0
+			lengthDeletions2 = 0
+			lastequality = diffs[pointer].Text
+		} else {
+			// An insertion or deletion.
+
+			if diffs[pointer].Type == DiffInsert {
+				lengthInsertions2 += len(diffs[pointer].Text)
+			} else {
+				lengthDeletions2 += len(diffs[pointer].Text)
+			}
+			// Eliminate an equality that is smaller or equal to the edits on both sides of it.
+			difference1 := int(math.Max(float64(lengthInsertions1), float64(lengthDeletions1)))
+			difference2 := int(math.Max(float64(lengthInsertions2), float64(lengthDeletions2)))
+			if len(lastequality) > 0 &&
+				(len(lastequality) <= difference1) &&
+				(len(lastequality) <= difference2) {
+				// Duplicate record.
+				insPoint := equalities.data
+				diffs = append(
+					diffs[:insPoint],
+					append([]Diff{Diff{DiffDelete, lastequality}}, diffs[insPoint:]...)...)
+
+				// Change second copy to insert.
+				diffs[insPoint+1].Type = DiffInsert
+				// Throw away the equality we just deleted.
+				equalities = equalities.next
+
+				if equalities != nil {
+					equalities = equalities.next
+				}
+				if equalities != nil {
+					pointer = equalities.data
+				} else {
+					pointer = -1
+				}
+
+				lengthInsertions1 = 0 // Reset the counters.
+				lengthDeletions1 = 0
+				lengthInsertions2 = 0
+				lengthDeletions2 = 0
+				lastequality = ""
+				changes = true
+			}
+		}
+		pointer++
+	}
+
+	// Normalize the diff.
+	if changes {
+		diffs = dmp.DiffCleanupMerge(diffs)
+	}
+	diffs = dmp.DiffCleanupSemanticLossless(diffs)
+	// Find any overlaps between deletions and insertions.
+	// e.g: <del>abcxxx</del><ins>xxxdef</ins>
+	//   -> <del>abc</del>xxx<ins>def</ins>
+	// e.g: <del>xxxabc</del><ins>defxxx</ins>
+	//   -> <ins>def</ins>xxx<del>abc</del>
+	// Only extract an overlap if it is as big as the edit ahead or behind it.
+	pointer = 1
+	for pointer < len(diffs) {
+		if diffs[pointer-1].Type == DiffDelete &&
+			diffs[pointer].Type == DiffInsert {
+			deletion := diffs[pointer-1].Text
+			insertion := diffs[pointer].Text
+			overlapLength1 := dmp.DiffCommonOverlap(deletion, insertion)
+			overlapLength2 := dmp.DiffCommonOverlap(insertion, deletion)
+			if overlapLength1 >= overlapLength2 {
+				if float64(overlapLength1) >= float64(len(deletion))/2 ||
+					float64(overlapLength1) >= float64(len(insertion))/2 {
+
+					// Overlap found. Insert an equality and trim the surrounding edits.
+					diffs = append(
+						diffs[:pointer],
+						append([]Diff{Diff{DiffEqual, insertion[:overlapLength1]}}, diffs[pointer:]...)...)
+
+					diffs[pointer-1].Text =
+						deletion[0 : len(deletion)-overlapLength1]
+					diffs[pointer+1].Text = insertion[overlapLength1:]
+					pointer++
+				}
+			} else {
+				if float64(overlapLength2) >= float64(len(deletion))/2 ||
+					float64(overlapLength2) >= float64(len(insertion))/2 {
+					// Reverse overlap found. Insert an equality and swap and trim the surrounding edits.
+					overlap := Diff{DiffEqual, deletion[:overlapLength2]}
+					diffs = append(
+						diffs[:pointer],
+						append([]Diff{overlap}, diffs[pointer:]...)...)
+
+					diffs[pointer-1].Type = DiffInsert
+					diffs[pointer-1].Text = insertion[0 : len(insertion)-overlapLength2]
+					diffs[pointer+1].Type = DiffDelete
+					diffs[pointer+1].Text = deletion[overlapLength2:]
+					pointer++
+				}
+			}
+			pointer++
+		}
+		pointer++
+	}
+
+	return diffs
+}
+
+// Define some regex patterns for matching boundaries.
+var (
+	nonAlphaNumericRegex = regexp.MustCompile(`[^a-zA-Z0-9]`)
+	whitespaceRegex      = regexp.MustCompile(`\s`)
+	linebreakRegex       = regexp.MustCompile(`[\r\n]`)
+	blanklineEndRegex    = regexp.MustCompile(`\n\r?\n$`)
+	blanklineStartRegex  = regexp.MustCompile(`^\r?\n\r?\n`)
+)
+
+// diffCleanupSemanticScore computes a score representing whether the internal boundary falls on logical boundaries.
+// Scores range from 6 (best) to 0 (worst). Closure, but does not reference any external variables.
+func diffCleanupSemanticScore(one, two string) int {
+	if len(one) == 0 || len(two) == 0 {
+		// Edges are the best.
+		return 6
+	}
+
+	// Each port of this function behaves slightly differently due to subtle differences in each language's definition of things like 'whitespace'.  Since this function's purpose is largely cosmetic, the choice has been made to use each language's native features rather than force total conformity.
+	rune1, _ := utf8.DecodeLastRuneInString(one)
+	rune2, _ := utf8.DecodeRuneInString(two)
+	char1 := string(rune1)
+	char2 := string(rune2)
+
+	nonAlphaNumeric1 := nonAlphaNumericRegex.MatchString(char1)
+	nonAlphaNumeric2 := nonAlphaNumericRegex.MatchString(char2)
+	whitespace1 := nonAlphaNumeric1 && whitespaceRegex.MatchString(char1)
+	whitespace2 := nonAlphaNumeric2 && whitespaceRegex.MatchString(char2)
+	lineBreak1 := whitespace1 && linebreakRegex.MatchString(char1)
+	lineBreak2 := whitespace2 && linebreakRegex.MatchString(char2)
+	blankLine1 := lineBreak1 && blanklineEndRegex.MatchString(one)
+	blankLine2 := lineBreak2 && blanklineEndRegex.MatchString(two)
+
+	if blankLine1 || blankLine2 {
+		// Five points for blank lines.
+		return 5
+	} else if lineBreak1 || lineBreak2 {
+		// Four points for line breaks.
+		return 4
+	} else if nonAlphaNumeric1 && !whitespace1 && whitespace2 {
+		// Three points for end of sentences.
+		return 3
+	} else if whitespace1 || whitespace2 {
+		// Two points for whitespace.
+		return 2
+	} else if nonAlphaNumeric1 || nonAlphaNumeric2 {
+		// One point for non-alphanumeric.
+		return 1
+	}
+	return 0
+}
+
+// DiffCleanupSemanticLossless looks for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary.
+// E.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
+func (dmp *DiffMatchPatch) DiffCleanupSemanticLossless(diffs []Diff) []Diff {
+	pointer := 1
+
+	// Intentionally ignore the first and last element (don't need checking).
+	for pointer < len(diffs)-1 {
+		if diffs[pointer-1].Type == DiffEqual &&
+			diffs[pointer+1].Type == DiffEqual {
+
+			// This is a single edit surrounded by equalities.
+			equality1 := diffs[pointer-1].Text
+			edit := diffs[pointer].Text
+			equality2 := diffs[pointer+1].Text
+
+			// First, shift the edit as far left as possible.
+			commonOffset := dmp.DiffCommonSuffix(equality1, edit)
+			if commonOffset > 0 {
+				commonString := edit[len(edit)-commonOffset:]
+				equality1 = equality1[0 : len(equality1)-commonOffset]
+				edit = commonString + edit[:len(edit)-commonOffset]
+				equality2 = commonString + equality2
+			}
+
+			// Second, step character by character right, looking for the best fit.
+			bestEquality1 := equality1
+			bestEdit := edit
+			bestEquality2 := equality2
+			bestScore := diffCleanupSemanticScore(equality1, edit) +
+				diffCleanupSemanticScore(edit, equality2)
+
+			for len(edit) != 0 && len(equality2) != 0 {
+				_, sz := utf8.DecodeRuneInString(edit)
+				if len(equality2) < sz || edit[:sz] != equality2[:sz] {
+					break
+				}
+				equality1 += edit[:sz]
+				edit = edit[sz:] + equality2[:sz]
+				equality2 = equality2[sz:]
+				score := diffCleanupSemanticScore(equality1, edit) +
+					diffCleanupSemanticScore(edit, equality2)
+				// The >= encourages trailing rather than leading whitespace on edits.
+				if score >= bestScore {
+					bestScore = score
+					bestEquality1 = equality1
+					bestEdit = edit
+					bestEquality2 = equality2
+				}
+			}
+
+			if diffs[pointer-1].Text != bestEquality1 {
+				// We have an improvement, save it back to the diff.
+				if len(bestEquality1) != 0 {
+					diffs[pointer-1].Text = bestEquality1
+				} else {
+					diffs = splice(diffs, pointer-1, 1)
+					pointer--
+				}
+
+				diffs[pointer].Text = bestEdit
+				if len(bestEquality2) != 0 {
+					diffs[pointer+1].Text = bestEquality2
+				} else {
+					diffs = append(diffs[:pointer+1], diffs[pointer+2:]...)
+					pointer--
+				}
+			}
+		}
+		pointer++
+	}
+
+	return diffs
+}
+
+// DiffCleanupEfficiency reduces the number of edits by eliminating operationally trivial equalities.
+func (dmp *DiffMatchPatch) DiffCleanupEfficiency(diffs []Diff) []Diff {
+	changes := false
+	// Stack of indices where equalities are found.
+	type equality struct {
+		data int
+		next *equality
+	}
+	var equalities *equality
+	// Always equal to equalities[equalitiesLength-1][1]
+	lastequality := ""
+	pointer := 0 // Index of current position.
+	// Is there an insertion operation before the last equality.
+	preIns := false
+	// Is there a deletion operation before the last equality.
+	preDel := false
+	// Is there an insertion operation after the last equality.
+	postIns := false
+	// Is there a deletion operation after the last equality.
+	postDel := false
+	for pointer < len(diffs) {
+		if diffs[pointer].Type == DiffEqual { // Equality found.
+			if len(diffs[pointer].Text) < dmp.DiffEditCost &&
+				(postIns || postDel) {
+				// Candidate found.
+				equalities = &equality{
+					data: pointer,
+					next: equalities,
+				}
+				preIns = postIns
+				preDel = postDel
+				lastequality = diffs[pointer].Text
+			} else {
+				// Not a candidate, and can never become one.
+				equalities = nil
+				lastequality = ""
+			}
+			postIns = false
+			postDel = false
+		} else { // An insertion or deletion.
+			if diffs[pointer].Type == DiffDelete {
+				postDel = true
+			} else {
+				postIns = true
+			}
+
+			// Five types to be split:
+			// <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
+			// <ins>A</ins>X<ins>C</ins><del>D</del>
+			// <ins>A</ins><del>B</del>X<ins>C</ins>
+			// <ins>A</del>X<ins>C</ins><del>D</del>
+			// <ins>A</ins><del>B</del>X<del>C</del>
+			var sumPres int
+			if preIns {
+				sumPres++
+			}
+			if preDel {
+				sumPres++
+			}
+			if postIns {
+				sumPres++
+			}
+			if postDel {
+				sumPres++
+			}
+			if len(lastequality) > 0 &&
+				((preIns && preDel && postIns && postDel) ||
+					((len(lastequality) < dmp.DiffEditCost/2) && sumPres == 3)) {
+
+				insPoint := equalities.data
+
+				// Duplicate record.
+				diffs = append(diffs[:insPoint],
+					append([]Diff{Diff{DiffDelete, lastequality}}, diffs[insPoint:]...)...)
+
+				// Change second copy to insert.
+				diffs[insPoint+1].Type = DiffInsert
+				// Throw away the equality we just deleted.
+				equalities = equalities.next
+				lastequality = ""
+
+				if preIns && preDel {
+					// No changes made which could affect previous entry, keep going.
+					postIns = true
+					postDel = true
+					equalities = nil
+				} else {
+					if equalities != nil {
+						equalities = equalities.next
+					}
+					if equalities != nil {
+						pointer = equalities.data
+					} else {
+						pointer = -1
+					}
+					postIns = false
+					postDel = false
+				}
+				changes = true
+			}
+		}
+		pointer++
+	}
+
+	if changes {
+		diffs = dmp.DiffCleanupMerge(diffs)
+	}
+
+	return diffs
+}
+
+// DiffCleanupMerge reorders and merges like edit sections. Merge equalities.
+// Any edit section can move as long as it doesn't cross an equality.
+func (dmp *DiffMatchPatch) DiffCleanupMerge(diffs []Diff) []Diff {
+	// Add a dummy entry at the end.
+	diffs = append(diffs, Diff{DiffEqual, ""})
+	pointer := 0
+	countDelete := 0
+	countInsert := 0
+	commonlength := 0
+	textDelete := []rune(nil)
+	textInsert := []rune(nil)
+
+	for pointer < len(diffs) {
+		switch diffs[pointer].Type {
+		case DiffInsert:
+			countInsert++
+			textInsert = append(textInsert, []rune(diffs[pointer].Text)...)
+			pointer++
+			break
+		case DiffDelete:
+			countDelete++
+			textDelete = append(textDelete, []rune(diffs[pointer].Text)...)
+			pointer++
+			break
+		case DiffEqual:
+			// Upon reaching an equality, check for prior redundancies.
+			if countDelete+countInsert > 1 {
+				if countDelete != 0 && countInsert != 0 {
+					// Factor out any common prefixies.
+					commonlength = commonPrefixLength(textInsert, textDelete)
+					if commonlength != 0 {
+						x := pointer - countDelete - countInsert
+						if x > 0 && diffs[x-1].Type == DiffEqual {
+							diffs[x-1].Text += string(textInsert[:commonlength])
+						} else {
+							diffs = append([]Diff{Diff{DiffEqual, string(textInsert[:commonlength])}}, diffs...)
+							pointer++
+						}
+						textInsert = textInsert[commonlength:]
+						textDelete = textDelete[commonlength:]
+					}
+					// Factor out any common suffixies.
+					commonlength = commonSuffixLength(textInsert, textDelete)
+					if commonlength != 0 {
+						insertIndex := len(textInsert) - commonlength
+						deleteIndex := len(textDelete) - commonlength
+						diffs[pointer].Text = string(textInsert[insertIndex:]) + diffs[pointer].Text
+						textInsert = textInsert[:insertIndex]
+						textDelete = textDelete[:deleteIndex]
+					}
+				}
+				// Delete the offending records and add the merged ones.
+				if countDelete == 0 {
+					diffs = splice(diffs, pointer-countInsert,
+						countDelete+countInsert,
+						Diff{DiffInsert, string(textInsert)})
+				} else if countInsert == 0 {
+					diffs = splice(diffs, pointer-countDelete,
+						countDelete+countInsert,
+						Diff{DiffDelete, string(textDelete)})
+				} else {
+					diffs = splice(diffs, pointer-countDelete-countInsert,
+						countDelete+countInsert,
+						Diff{DiffDelete, string(textDelete)},
+						Diff{DiffInsert, string(textInsert)})
+				}
+
+				pointer = pointer - countDelete - countInsert + 1
+				if countDelete != 0 {
+					pointer++
+				}
+				if countInsert != 0 {
+					pointer++
+				}
+			} else if pointer != 0 && diffs[pointer-1].Type == DiffEqual {
+				// Merge this equality with the previous one.
+				diffs[pointer-1].Text += diffs[pointer].Text
+				diffs = append(diffs[:pointer], diffs[pointer+1:]...)
+			} else {
+				pointer++
+			}
+			countInsert = 0
+			countDelete = 0
+			textDelete = nil
+			textInsert = nil
+			break
+		}
+	}
+
+	if len(diffs[len(diffs)-1].Text) == 0 {
+		diffs = diffs[0 : len(diffs)-1] // Remove the dummy entry at the end.
+	}
+
+	// Second pass: look for single edits surrounded on both sides by equalities which can be shifted sideways to eliminate an equality. E.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
+	changes := false
+	pointer = 1
+	// Intentionally ignore the first and last element (don't need checking).
+	for pointer < (len(diffs) - 1) {
+		if diffs[pointer-1].Type == DiffEqual &&
+			diffs[pointer+1].Type == DiffEqual {
+			// This is a single edit surrounded by equalities.
+			if strings.HasSuffix(diffs[pointer].Text, diffs[pointer-1].Text) {
+				// Shift the edit over the previous equality.
+				diffs[pointer].Text = diffs[pointer-1].Text +
+					diffs[pointer].Text[:len(diffs[pointer].Text)-len(diffs[pointer-1].Text)]
+				diffs[pointer+1].Text = diffs[pointer-1].Text + diffs[pointer+1].Text
+				diffs = splice(diffs, pointer-1, 1)
+				changes = true
+			} else if strings.HasPrefix(diffs[pointer].Text, diffs[pointer+1].Text) {
+				// Shift the edit over the next equality.
+				diffs[pointer-1].Text += diffs[pointer+1].Text
+				diffs[pointer].Text =
+					diffs[pointer].Text[len(diffs[pointer+1].Text):] + diffs[pointer+1].Text
+				diffs = splice(diffs, pointer+1, 1)
+				changes = true
+			}
+		}
+		pointer++
+	}
+
+	// If shifts were made, the diff needs reordering and another shift sweep.
+	if changes {
+		diffs = dmp.DiffCleanupMerge(diffs)
+	}
+
+	return diffs
+}
+
+// DiffXIndex returns the equivalent location in s2.
+func (dmp *DiffMatchPatch) DiffXIndex(diffs []Diff, loc int) int {
+	chars1 := 0
+	chars2 := 0
+	lastChars1 := 0
+	lastChars2 := 0
+	lastDiff := Diff{}
+	for i := 0; i < len(diffs); i++ {
+		aDiff := diffs[i]
+		if aDiff.Type != DiffInsert {
+			// Equality or deletion.
+			chars1 += len(aDiff.Text)
+		}
+		if aDiff.Type != DiffDelete {
+			// Equality or insertion.
+			chars2 += len(aDiff.Text)
+		}
+		if chars1 > loc {
+			// Overshot the location.
+			lastDiff = aDiff
+			break
+		}
+		lastChars1 = chars1
+		lastChars2 = chars2
+	}
+	if lastDiff.Type == DiffDelete {
+		// The location was deleted.
+		return lastChars2
+	}
+	// Add the remaining character length.
+	return lastChars2 + (loc - lastChars1)
+}
+
+// DiffPrettyHtml converts a []Diff into a pretty HTML report.
+// It is intended as an example from which to write one's own display functions.
+func (dmp *DiffMatchPatch) DiffPrettyHtml(diffs []Diff) string {
+	var buff bytes.Buffer
+	for _, diff := range diffs {
+		text := strings.Replace(html.EscapeString(diff.Text), "\n", "&para;<br>", -1)
+		switch diff.Type {
+		case DiffInsert:
+			_, _ = buff.WriteString("<ins style=\"background:#e6ffe6;\">")
+			_, _ = buff.WriteString(text)
+			_, _ = buff.WriteString("</ins>")
+		case DiffDelete:
+			_, _ = buff.WriteString("<del style=\"background:#ffe6e6;\">")
+			_, _ = buff.WriteString(text)
+			_, _ = buff.WriteString("</del>")
+		case DiffEqual:
+			_, _ = buff.WriteString("<span>")
+			_, _ = buff.WriteString(text)
+			_, _ = buff.WriteString("</span>")
+		}
+	}
+	return buff.String()
+}
+
+// DiffPrettyText converts a []Diff into a colored text report.
+func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
+	var buff bytes.Buffer
+	for _, diff := range diffs {
+		text := diff.Text
+
+		switch diff.Type {
+		case DiffInsert:
+			_, _ = buff.WriteString("\x1b[32m")
+			_, _ = buff.WriteString(text)
+			_, _ = buff.WriteString("\x1b[0m")
+		case DiffDelete:
+			_, _ = buff.WriteString("\x1b[31m")
+			_, _ = buff.WriteString(text)
+			_, _ = buff.WriteString("\x1b[0m")
+		case DiffEqual:
+			_, _ = buff.WriteString(text)
+		}
+	}
+
+	return buff.String()
+}
+
+// DiffText1 computes and returns the source text (all equalities and deletions).
+func (dmp *DiffMatchPatch) DiffText1(diffs []Diff) string {
+	//StringBuilder text = new StringBuilder()
+	var text bytes.Buffer
+
+	for _, aDiff := range diffs {
+		if aDiff.Type != DiffInsert {
+			_, _ = text.WriteString(aDiff.Text)
+		}
+	}
+	return text.String()
+}
+
+// DiffText2 computes and returns the destination text (all equalities and insertions).
+func (dmp *DiffMatchPatch) DiffText2(diffs []Diff) string {
+	var text bytes.Buffer
+
+	for _, aDiff := range diffs {
+		if aDiff.Type != DiffDelete {
+			_, _ = text.WriteString(aDiff.Text)
+		}
+	}
+	return text.String()
+}
+
+// DiffLevenshtein computes the Levenshtein distance that is the number of inserted, deleted or substituted characters.
+func (dmp *DiffMatchPatch) DiffLevenshtein(diffs []Diff) int {
+	levenshtein := 0
+	insertions := 0
+	deletions := 0
+
+	for _, aDiff := range diffs {
+		switch aDiff.Type {
+		case DiffInsert:
+			insertions += len(aDiff.Text)
+		case DiffDelete:
+			deletions += len(aDiff.Text)
+		case DiffEqual:
+			// A deletion and an insertion is one substitution.
+			levenshtein += max(insertions, deletions)
+			insertions = 0
+			deletions = 0
+		}
+	}
+
+	levenshtein += max(insertions, deletions)
+	return levenshtein
+}
+
+// DiffToDelta crushes the diff into an encoded string which describes the operations required to transform text1 into text2.
+// E.g. =3\t-2\t+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'. Operations are tab-separated.  Inserted text is escaped using %xx notation.
+func (dmp *DiffMatchPatch) DiffToDelta(diffs []Diff) string {
+	var text bytes.Buffer
+	for _, aDiff := range diffs {
+		switch aDiff.Type {
+		case DiffInsert:
+			_, _ = text.WriteString("+")
+			_, _ = text.WriteString(strings.Replace(url.QueryEscape(aDiff.Text), "+", " ", -1))
+			_, _ = text.WriteString("\t")
+			break
+		case DiffDelete:
+			_, _ = text.WriteString("-")
+			_, _ = text.WriteString(strconv.Itoa(utf8.RuneCountInString(aDiff.Text)))
+			_, _ = text.WriteString("\t")
+			break
+		case DiffEqual:
+			_, _ = text.WriteString("=")
+			_, _ = text.WriteString(strconv.Itoa(utf8.RuneCountInString(aDiff.Text)))
+			_, _ = text.WriteString("\t")
+			break
+		}
+	}
+	delta := text.String()
+	if len(delta) != 0 {
+		// Strip off trailing tab character.
+		delta = delta[0 : utf8.RuneCountInString(delta)-1]
+		delta = unescaper.Replace(delta)
+	}
+	return delta
+}
+
+// DiffFromDelta given the original text1, and an encoded string which describes the operations required to transform text1 into text2, comAdde the full diff.
+func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Diff, err error) {
+	i := 0
+
+	for _, token := range strings.Split(delta, "\t") {
+		if len(token) == 0 {
+			// Blank tokens are ok (from a trailing \t).
+			continue
+		}
+
+		// Each token begins with a one character parameter which specifies the operation of this token (delete, insert, equality).
+		param := token[1:]
+
+		switch op := token[0]; op {
+		case '+':
+			// Decode would Diff all "+" to " "
+			param = strings.Replace(param, "+", "%2b", -1)
+			param, err = url.QueryUnescape(param)
+			if err != nil {
+				return nil, err
+			}
+			if !utf8.ValidString(param) {
+				return nil, fmt.Errorf("invalid UTF-8 token: %q", param)
+			}
+
+			diffs = append(diffs, Diff{DiffInsert, param})
+		case '=', '-':
+			n, err := strconv.ParseInt(param, 10, 0)
+			if err != nil {
+				return nil, err
+			} else if n < 0 {
+				return nil, errors.New("Negative number in DiffFromDelta: " + param)
+			}
+
+			// Remember that string slicing is by byte - we want by rune here.
+			text := string([]rune(text1)[i : i+int(n)])
+			i += int(n)
+
+			if op == '=' {
+				diffs = append(diffs, Diff{DiffEqual, text})
+			} else {
+				diffs = append(diffs, Diff{DiffDelete, text})
+			}
+		default:
+			// Anything else is an error.
+			return nil, errors.New("Invalid diff operation in DiffFromDelta: " + string(token[0]))
+		}
+	}
+
+	if i != len([]rune(text1)) {
+		return nil, fmt.Errorf("Delta length (%v) smaller than source text length (%v)", i, len(text1))
+	}
+
+	return diffs, nil
+}
diff --git a/diffmatchpatch/diff_test.go b/diffmatchpatch/diff_test.go
new file mode 100644
index 0000000..f701438
--- /dev/null
+++ b/diffmatchpatch/diff_test.go
@@ -0,0 +1,1410 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"bytes"
+	"fmt"
+	"strconv"
+	"strings"
+	"testing"
+	"time"
+	"unicode/utf8"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func pretty(diffs []Diff) string {
+	var w bytes.Buffer
+
+	for i, diff := range diffs {
+		_, _ = w.WriteString(fmt.Sprintf("%v. ", i))
+
+		switch diff.Type {
+		case DiffInsert:
+			_, _ = w.WriteString("DiffIns")
+		case DiffDelete:
+			_, _ = w.WriteString("DiffDel")
+		case DiffEqual:
+			_, _ = w.WriteString("DiffEql")
+		default:
+			_, _ = w.WriteString("Unknown")
+		}
+
+		_, _ = w.WriteString(fmt.Sprintf(": %v\n", diff.Text))
+	}
+
+	return w.String()
+}
+
+func diffRebuildTexts(diffs []Diff) []string {
+	texts := []string{"", ""}
+
+	for _, d := range diffs {
+		if d.Type != DiffInsert {
+			texts[0] += d.Text
+		}
+		if d.Type != DiffDelete {
+			texts[1] += d.Text
+		}
+	}
+
+	return texts
+}
+
+func TestDiffCommonPrefix(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text1 string
+		Text2 string
+
+		Expected int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Null", "abc", "xyz", 0},
+		{"Non-null", "1234abcdef", "1234xyz", 4},
+		{"Whole", "1234", "1234xyz", 4},
+	} {
+		actual := dmp.DiffCommonPrefix(tc.Text1, tc.Text2)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func BenchmarkDiffCommonPrefix(b *testing.B) {
+	s := "ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ"
+
+	dmp := New()
+
+	for i := 0; i < b.N; i++ {
+		dmp.DiffCommonPrefix(s, s)
+	}
+}
+
+func TestCommonPrefixLength(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+
+		Expected int
+	}
+
+	for i, tc := range []TestCase{
+		{"abc", "xyz", 0},
+		{"1234abcdef", "1234xyz", 4},
+		{"1234", "1234xyz", 4},
+	} {
+		actual := commonPrefixLength([]rune(tc.Text1), []rune(tc.Text2))
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestDiffCommonSuffix(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text1 string
+		Text2 string
+
+		Expected int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Null", "abc", "xyz", 0},
+		{"Non-null", "abcdef1234", "xyz1234", 4},
+		{"Whole", "1234", "xyz1234", 4},
+	} {
+		actual := dmp.DiffCommonSuffix(tc.Text1, tc.Text2)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func BenchmarkDiffCommonSuffix(b *testing.B) {
+	s := "ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ"
+
+	dmp := New()
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		dmp.DiffCommonSuffix(s, s)
+	}
+}
+
+func TestCommonSuffixLength(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+
+		Expected int
+	}
+
+	for i, tc := range []TestCase{
+		{"abc", "xyz", 0},
+		{"abcdef1234", "xyz1234", 4},
+		{"1234", "xyz1234", 4},
+		{"123", "a3", 1},
+	} {
+		actual := commonSuffixLength([]rune(tc.Text1), []rune(tc.Text2))
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestDiffCommonOverlap(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text1 string
+		Text2 string
+
+		Expected int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Null", "", "abcd", 0},
+		{"Whole", "abc", "abcd", 3},
+		{"Null", "123456", "abcd", 0},
+		{"Null", "123456xxx", "xxxabcd", 3},
+		// Some overly clever languages (C#) may treat ligatures as equal to their component letters, e.g. U+FB01 == 'fi'
+		{"Unicode", "fi", "\ufb01i", 0},
+	} {
+		actual := dmp.DiffCommonOverlap(tc.Text1, tc.Text2)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffHalfMatch(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+
+		Expected []string
+	}
+
+	dmp := New()
+	dmp.DiffTimeout = 1
+
+	for i, tc := range []TestCase{
+		// No match
+		{"1234567890", "abcdef", nil},
+		{"12345", "23", nil},
+
+		// Single Match
+		{"1234567890", "a345678z", []string{"12", "90", "a", "z", "345678"}},
+		{"a345678z", "1234567890", []string{"a", "z", "12", "90", "345678"}},
+		{"abc56789z", "1234567890", []string{"abc", "z", "1234", "0", "56789"}},
+		{"a23456xyz", "1234567890", []string{"a", "xyz", "1", "7890", "23456"}},
+
+		// Multiple Matches
+		{"121231234123451234123121", "a1234123451234z", []string{"12123", "123121", "a", "z", "1234123451234"}},
+		{"x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-=", []string{"", "-=-=-=-=-=", "x", "", "x-=-=-=-=-=-=-="}},
+		{"-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy", []string{"-=-=-=-=-=", "", "", "y", "-=-=-=-=-=-=-=y"}},
+
+		// Non-optimal halfmatch, ptimal diff would be -q+x=H-i+e=lloHe+Hu=llo-Hew+y not -qHillo+x=HelloHe-w+Hulloy
+		{"qHilloHelloHew", "xHelloHeHulloy", []string{"qHillo", "w", "x", "Hulloy", "HelloHe"}},
+	} {
+		actual := dmp.DiffHalfMatch(tc.Text1, tc.Text2)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+
+	dmp.DiffTimeout = 0
+
+	for i, tc := range []TestCase{
+		// Optimal no halfmatch
+		{"qHilloHelloHew", "xHelloHeHulloy", nil},
+	} {
+		actual := dmp.DiffHalfMatch(tc.Text1, tc.Text2)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func BenchmarkDiffHalfMatch(b *testing.B) {
+	s1, s2 := speedtestTexts()
+
+	dmp := New()
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		dmp.DiffHalfMatch(s1, s2)
+	}
+}
+
+func TestDiffBisectSplit(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+	}
+
+	dmp := New()
+
+	for _, tc := range []TestCase{
+		{"STUV\x05WX\x05YZ\x05[", "WĺĻļ\x05YZ\x05ĽľĿŀZ"},
+	} {
+		diffs := dmp.diffBisectSplit([]rune(tc.Text1),
+			[]rune(tc.Text2), 7, 6, time.Now().Add(time.Hour))
+
+		for _, d := range diffs {
+			assert.True(t, utf8.ValidString(d.Text))
+		}
+
+		// TODO define the expected outcome
+	}
+}
+
+func TestDiffLinesToChars(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+
+		ExpectedChars1 string
+		ExpectedChars2 string
+		ExpectedLines  []string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"", "alpha\r\nbeta\r\n\r\n\r\n", "", "\u0001\u0002\u0003\u0003", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}},
+		{"a", "b", "\u0001", "\u0002", []string{"", "a", "b"}},
+		// Omit final newline.
+		{"alpha\nbeta\nalpha", "", "\u0001\u0002\u0003", "", []string{"", "alpha\n", "beta\n", "alpha"}},
+	} {
+		actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(tc.Text1, tc.Text2)
+		assert.Equal(t, tc.ExpectedChars1, actualChars1, fmt.Sprintf("Test case #%d, %#v", i, tc))
+		assert.Equal(t, tc.ExpectedChars2, actualChars2, fmt.Sprintf("Test case #%d, %#v", i, tc))
+		assert.Equal(t, tc.ExpectedLines, actualLines, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+
+	// More than 256 to reveal any 8-bit limitations.
+	n := 300
+	lineList := []string{
+		"", // Account for the initial empty element of the lines array.
+	}
+	var charList []rune
+	for x := 1; x < n+1; x++ {
+		lineList = append(lineList, strconv.Itoa(x)+"\n")
+		charList = append(charList, rune(x))
+	}
+	lines := strings.Join(lineList, "")
+	chars := string(charList)
+	assert.Equal(t, n, utf8.RuneCountInString(chars))
+
+	actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(lines, "")
+	assert.Equal(t, chars, actualChars1)
+	assert.Equal(t, "", actualChars2)
+	assert.Equal(t, lineList, actualLines)
+}
+
+func TestDiffCharsToLines(t *testing.T) {
+	type TestCase struct {
+		Diffs []Diff
+		Lines []string
+
+		Expected []Diff
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			Diffs: []Diff{
+				{DiffEqual, "\u0001\u0002\u0001"},
+				{DiffInsert, "\u0002\u0001\u0002"},
+			},
+			Lines: []string{"", "alpha\n", "beta\n"},
+
+			Expected: []Diff{
+				{DiffEqual, "alpha\nbeta\nalpha\n"},
+				{DiffInsert, "beta\nalpha\nbeta\n"},
+			},
+		},
+	} {
+		actual := dmp.DiffCharsToLines(tc.Diffs, tc.Lines)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+
+	// More than 256 to reveal any 8-bit limitations.
+	n := 300
+	lineList := []string{
+		"", // Account for the initial empty element of the lines array.
+	}
+	charList := []rune{}
+	for x := 1; x <= n; x++ {
+		lineList = append(lineList, strconv.Itoa(x)+"\n")
+		charList = append(charList, rune(x))
+	}
+	assert.Equal(t, n, len(charList))
+
+	actual := dmp.DiffCharsToLines([]Diff{Diff{DiffDelete, string(charList)}}, lineList)
+	assert.Equal(t, []Diff{Diff{DiffDelete, strings.Join(lineList, "")}}, actual)
+}
+
+func TestDiffCleanupMerge(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Diffs []Diff
+
+		Expected []Diff
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			"Null case",
+			[]Diff{},
+			[]Diff{},
+		},
+		{
+			"No Diff case",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "b"}, Diff{DiffInsert, "c"}},
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "b"}, Diff{DiffInsert, "c"}},
+		},
+		{
+			"Merge equalities",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffEqual, "b"}, Diff{DiffEqual, "c"}},
+			[]Diff{Diff{DiffEqual, "abc"}},
+		},
+		{
+			"Merge deletions",
+			[]Diff{Diff{DiffDelete, "a"}, Diff{DiffDelete, "b"}, Diff{DiffDelete, "c"}},
+			[]Diff{Diff{DiffDelete, "abc"}},
+		},
+		{
+			"Merge insertions",
+			[]Diff{Diff{DiffInsert, "a"}, Diff{DiffInsert, "b"}, Diff{DiffInsert, "c"}},
+			[]Diff{Diff{DiffInsert, "abc"}},
+		},
+		{
+			"Merge interweave",
+			[]Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "b"}, Diff{DiffDelete, "c"}, Diff{DiffInsert, "d"}, Diff{DiffEqual, "e"}, Diff{DiffEqual, "f"}},
+			[]Diff{Diff{DiffDelete, "ac"}, Diff{DiffInsert, "bd"}, Diff{DiffEqual, "ef"}},
+		},
+		{
+			"Prefix and suffix detection",
+			[]Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "abc"}, Diff{DiffDelete, "dc"}},
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "d"}, Diff{DiffInsert, "b"}, Diff{DiffEqual, "c"}},
+		},
+		{
+			"Prefix and suffix detection with equalities",
+			[]Diff{Diff{DiffEqual, "x"}, Diff{DiffDelete, "a"}, Diff{DiffInsert, "abc"}, Diff{DiffDelete, "dc"}, Diff{DiffEqual, "y"}},
+			[]Diff{Diff{DiffEqual, "xa"}, Diff{DiffDelete, "d"}, Diff{DiffInsert, "b"}, Diff{DiffEqual, "cy"}},
+		},
+		{
+			"Same test as above but with unicode (\u0101 will appear in diffs with at least 257 unique lines)",
+			[]Diff{Diff{DiffEqual, "x"}, Diff{DiffDelete, "\u0101"}, Diff{DiffInsert, "\u0101bc"}, Diff{DiffDelete, "dc"}, Diff{DiffEqual, "y"}},
+			[]Diff{Diff{DiffEqual, "x\u0101"}, Diff{DiffDelete, "d"}, Diff{DiffInsert, "b"}, Diff{DiffEqual, "cy"}},
+		},
+		{
+			"Slide edit left",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffInsert, "ba"}, Diff{DiffEqual, "c"}},
+			[]Diff{Diff{DiffInsert, "ab"}, Diff{DiffEqual, "ac"}},
+		},
+		{
+			"Slide edit right",
+			[]Diff{Diff{DiffEqual, "c"}, Diff{DiffInsert, "ab"}, Diff{DiffEqual, "a"}},
+			[]Diff{Diff{DiffEqual, "ca"}, Diff{DiffInsert, "ba"}},
+		},
+		{
+			"Slide edit left recursive",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "b"}, Diff{DiffEqual, "c"}, Diff{DiffDelete, "ac"}, Diff{DiffEqual, "x"}},
+			[]Diff{Diff{DiffDelete, "abc"}, Diff{DiffEqual, "acx"}},
+		},
+		{
+			"Slide edit right recursive",
+			[]Diff{Diff{DiffEqual, "x"}, Diff{DiffDelete, "ca"}, Diff{DiffEqual, "c"}, Diff{DiffDelete, "b"}, Diff{DiffEqual, "a"}},
+			[]Diff{Diff{DiffEqual, "xca"}, Diff{DiffDelete, "cba"}},
+		},
+	} {
+		actual := dmp.DiffCleanupMerge(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffCleanupSemanticLossless(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Diffs []Diff
+
+		Expected []Diff
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			"Null case",
+			[]Diff{},
+			[]Diff{},
+		},
+		{
+			"Blank lines",
+			[]Diff{
+				Diff{DiffEqual, "AAA\r\n\r\nBBB"},
+				Diff{DiffInsert, "\r\nDDD\r\n\r\nBBB"},
+				Diff{DiffEqual, "\r\nEEE"},
+			},
+			[]Diff{
+				Diff{DiffEqual, "AAA\r\n\r\n"},
+				Diff{DiffInsert, "BBB\r\nDDD\r\n\r\n"},
+				Diff{DiffEqual, "BBB\r\nEEE"},
+			},
+		},
+		{
+			"Line boundaries",
+			[]Diff{
+				Diff{DiffEqual, "AAA\r\nBBB"},
+				Diff{DiffInsert, " DDD\r\nBBB"},
+				Diff{DiffEqual, " EEE"},
+			},
+			[]Diff{
+				Diff{DiffEqual, "AAA\r\n"},
+				Diff{DiffInsert, "BBB DDD\r\n"},
+				Diff{DiffEqual, "BBB EEE"},
+			},
+		},
+		{
+			"Word boundaries",
+			[]Diff{
+				Diff{DiffEqual, "The c"},
+				Diff{DiffInsert, "ow and the c"},
+				Diff{DiffEqual, "at."},
+			},
+			[]Diff{
+				Diff{DiffEqual, "The "},
+				Diff{DiffInsert, "cow and the "},
+				Diff{DiffEqual, "cat."},
+			},
+		},
+		{
+			"Alphanumeric boundaries",
+			[]Diff{
+				Diff{DiffEqual, "The-c"},
+				Diff{DiffInsert, "ow-and-the-c"},
+				Diff{DiffEqual, "at."},
+			},
+			[]Diff{
+				Diff{DiffEqual, "The-"},
+				Diff{DiffInsert, "cow-and-the-"},
+				Diff{DiffEqual, "cat."},
+			},
+		},
+		{
+			"Hitting the start",
+			[]Diff{
+				Diff{DiffEqual, "a"},
+				Diff{DiffDelete, "a"},
+				Diff{DiffEqual, "ax"},
+			},
+			[]Diff{
+				Diff{DiffDelete, "a"},
+				Diff{DiffEqual, "aax"},
+			},
+		},
+		{
+			"Hitting the end",
+			[]Diff{
+				Diff{DiffEqual, "xa"},
+				Diff{DiffDelete, "a"},
+				Diff{DiffEqual, "a"},
+			},
+			[]Diff{
+				Diff{DiffEqual, "xaa"},
+				Diff{DiffDelete, "a"},
+			},
+		},
+		{
+			"Sentence boundaries",
+			[]Diff{
+				Diff{DiffEqual, "The xxx. The "},
+				Diff{DiffInsert, "zzz. The "},
+				Diff{DiffEqual, "yyy."},
+			},
+			[]Diff{
+				Diff{DiffEqual, "The xxx."},
+				Diff{DiffInsert, " The zzz."},
+				Diff{DiffEqual, " The yyy."},
+			},
+		},
+		{
+			"UTF-8 strings",
+			[]Diff{
+				Diff{DiffEqual, "The ♕. The "},
+				Diff{DiffInsert, "â™”. The "},
+				Diff{DiffEqual, "â™–."},
+			},
+			[]Diff{
+				Diff{DiffEqual, "The ♕."},
+				Diff{DiffInsert, " The â™”."},
+				Diff{DiffEqual, " The â™–."},
+			},
+		},
+		{
+			"Rune boundaries",
+			[]Diff{
+				Diff{DiffEqual, "♕♕"},
+				Diff{DiffInsert, "♔♔"},
+				Diff{DiffEqual, "â™–â™–"},
+			},
+			[]Diff{
+				Diff{DiffEqual, "♕♕"},
+				Diff{DiffInsert, "♔♔"},
+				Diff{DiffEqual, "â™–â™–"},
+			},
+		},
+	} {
+		actual := dmp.DiffCleanupSemanticLossless(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffCleanupSemantic(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Diffs []Diff
+
+		Expected []Diff
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			"Null case",
+			[]Diff{},
+			[]Diff{},
+		},
+		{
+			"No elimination #1",
+			[]Diff{
+				{DiffDelete, "ab"},
+				{DiffInsert, "cd"},
+				{DiffEqual, "12"},
+				{DiffDelete, "e"},
+			},
+			[]Diff{
+				{DiffDelete, "ab"},
+				{DiffInsert, "cd"},
+				{DiffEqual, "12"},
+				{DiffDelete, "e"},
+			},
+		},
+		{
+			"No elimination #2",
+			[]Diff{
+				{DiffDelete, "abc"},
+				{DiffInsert, "ABC"},
+				{DiffEqual, "1234"},
+				{DiffDelete, "wxyz"},
+			},
+			[]Diff{
+				{DiffDelete, "abc"},
+				{DiffInsert, "ABC"},
+				{DiffEqual, "1234"},
+				{DiffDelete, "wxyz"},
+			},
+		},
+		{
+			"No elimination #3",
+			[]Diff{
+				{DiffEqual, "2016-09-01T03:07:1"},
+				{DiffInsert, "5.15"},
+				{DiffEqual, "4"},
+				{DiffDelete, "."},
+				{DiffEqual, "80"},
+				{DiffInsert, "0"},
+				{DiffEqual, "78"},
+				{DiffDelete, "3074"},
+				{DiffEqual, "1Z"},
+			},
+			[]Diff{
+				{DiffEqual, "2016-09-01T03:07:1"},
+				{DiffInsert, "5.15"},
+				{DiffEqual, "4"},
+				{DiffDelete, "."},
+				{DiffEqual, "80"},
+				{DiffInsert, "0"},
+				{DiffEqual, "78"},
+				{DiffDelete, "3074"},
+				{DiffEqual, "1Z"},
+			},
+		},
+		{
+			"Simple elimination",
+			[]Diff{
+				{DiffDelete, "a"},
+				{DiffEqual, "b"},
+				{DiffDelete, "c"},
+			},
+			[]Diff{
+				{DiffDelete, "abc"},
+				{DiffInsert, "b"},
+			},
+		},
+		{
+			"Backpass elimination",
+			[]Diff{
+				{DiffDelete, "ab"},
+				{DiffEqual, "cd"},
+				{DiffDelete, "e"},
+				{DiffEqual, "f"},
+				{DiffInsert, "g"},
+			},
+			[]Diff{
+				{DiffDelete, "abcdef"},
+				{DiffInsert, "cdfg"},
+			},
+		},
+		{
+			"Multiple eliminations",
+			[]Diff{
+				{DiffInsert, "1"},
+				{DiffEqual, "A"},
+				{DiffDelete, "B"},
+				{DiffInsert, "2"},
+				{DiffEqual, "_"},
+				{DiffInsert, "1"},
+				{DiffEqual, "A"},
+				{DiffDelete, "B"},
+				{DiffInsert, "2"},
+			},
+			[]Diff{
+				{DiffDelete, "AB_AB"},
+				{DiffInsert, "1A2_1A2"},
+			},
+		},
+		{
+			"Word boundaries",
+			[]Diff{
+				{DiffEqual, "The c"},
+				{DiffDelete, "ow and the c"},
+				{DiffEqual, "at."},
+			},
+			[]Diff{
+				{DiffEqual, "The "},
+				{DiffDelete, "cow and the "},
+				{DiffEqual, "cat."},
+			},
+		},
+		{
+			"No overlap elimination",
+			[]Diff{
+				{DiffDelete, "abcxx"},
+				{DiffInsert, "xxdef"},
+			},
+			[]Diff{
+				{DiffDelete, "abcxx"},
+				{DiffInsert, "xxdef"},
+			},
+		},
+		{
+			"Overlap elimination",
+			[]Diff{
+				{DiffDelete, "abcxxx"},
+				{DiffInsert, "xxxdef"},
+			},
+			[]Diff{
+				{DiffDelete, "abc"},
+				{DiffEqual, "xxx"},
+				{DiffInsert, "def"},
+			},
+		},
+		{
+			"Reverse overlap elimination",
+			[]Diff{
+				{DiffDelete, "xxxabc"},
+				{DiffInsert, "defxxx"},
+			},
+			[]Diff{
+				{DiffInsert, "def"},
+				{DiffEqual, "xxx"},
+				{DiffDelete, "abc"},
+			},
+		},
+		{
+			"Two overlap eliminations",
+			[]Diff{
+				{DiffDelete, "abcd1212"},
+				{DiffInsert, "1212efghi"},
+				{DiffEqual, "----"},
+				{DiffDelete, "A3"},
+				{DiffInsert, "3BC"},
+			},
+			[]Diff{
+				{DiffDelete, "abcd"},
+				{DiffEqual, "1212"},
+				{DiffInsert, "efghi"},
+				{DiffEqual, "----"},
+				{DiffDelete, "A"},
+				{DiffEqual, "3"},
+				{DiffInsert, "BC"},
+			},
+		},
+		{
+			"Test case for adapting DiffCleanupSemantic to be equal to the Python version #19",
+			[]Diff{
+				{DiffEqual, "James McCarthy "},
+				{DiffDelete, "close to "},
+				{DiffEqual, "sign"},
+				{DiffDelete, "ing"},
+				{DiffInsert, "s"},
+				{DiffEqual, " new "},
+				{DiffDelete, "E"},
+				{DiffInsert, "fi"},
+				{DiffEqual, "ve"},
+				{DiffInsert, "-yea"},
+				{DiffEqual, "r"},
+				{DiffDelete, "ton"},
+				{DiffEqual, " deal"},
+				{DiffInsert, " at Everton"},
+			},
+			[]Diff{
+				{DiffEqual, "James McCarthy "},
+				{DiffDelete, "close to "},
+				{DiffEqual, "sign"},
+				{DiffDelete, "ing"},
+				{DiffInsert, "s"},
+				{DiffEqual, " new "},
+				{DiffInsert, "five-year deal at "},
+				{DiffEqual, "Everton"},
+				{DiffDelete, " deal"},
+			},
+		},
+	} {
+		actual := dmp.DiffCleanupSemantic(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func BenchmarkDiffCleanupSemantic(b *testing.B) {
+	s1, s2 := speedtestTexts()
+
+	dmp := New()
+
+	diffs := dmp.DiffMain(s1, s2, false)
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		dmp.DiffCleanupSemantic(diffs)
+	}
+}
+
+func TestDiffCleanupEfficiency(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Diffs []Diff
+
+		Expected []Diff
+	}
+
+	dmp := New()
+	dmp.DiffEditCost = 4
+
+	for i, tc := range []TestCase{
+		{
+			"Null case",
+			[]Diff{},
+			[]Diff{},
+		},
+		{
+			"No elimination",
+			[]Diff{
+				Diff{DiffDelete, "ab"},
+				Diff{DiffInsert, "12"},
+				Diff{DiffEqual, "wxyz"},
+				Diff{DiffDelete, "cd"},
+				Diff{DiffInsert, "34"},
+			},
+			[]Diff{
+				Diff{DiffDelete, "ab"},
+				Diff{DiffInsert, "12"},
+				Diff{DiffEqual, "wxyz"},
+				Diff{DiffDelete, "cd"},
+				Diff{DiffInsert, "34"},
+			},
+		},
+		{
+			"Four-edit elimination",
+			[]Diff{
+				Diff{DiffDelete, "ab"},
+				Diff{DiffInsert, "12"},
+				Diff{DiffEqual, "xyz"},
+				Diff{DiffDelete, "cd"},
+				Diff{DiffInsert, "34"},
+			},
+			[]Diff{
+				Diff{DiffDelete, "abxyzcd"},
+				Diff{DiffInsert, "12xyz34"},
+			},
+		},
+		{
+			"Three-edit elimination",
+			[]Diff{
+				Diff{DiffInsert, "12"},
+				Diff{DiffEqual, "x"},
+				Diff{DiffDelete, "cd"},
+				Diff{DiffInsert, "34"},
+			},
+			[]Diff{
+				Diff{DiffDelete, "xcd"},
+				Diff{DiffInsert, "12x34"},
+			},
+		},
+		{
+			"Backpass elimination",
+			[]Diff{
+				Diff{DiffDelete, "ab"},
+				Diff{DiffInsert, "12"},
+				Diff{DiffEqual, "xy"},
+				Diff{DiffInsert, "34"},
+				Diff{DiffEqual, "z"},
+				Diff{DiffDelete, "cd"},
+				Diff{DiffInsert, "56"},
+			},
+			[]Diff{
+				Diff{DiffDelete, "abxyzcd"},
+				Diff{DiffInsert, "12xy34z56"},
+			},
+		},
+	} {
+		actual := dmp.DiffCleanupEfficiency(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.DiffEditCost = 5
+
+	for i, tc := range []TestCase{
+		{
+			"High cost elimination",
+			[]Diff{
+				Diff{DiffDelete, "ab"},
+				Diff{DiffInsert, "12"},
+				Diff{DiffEqual, "wxyz"},
+				Diff{DiffDelete, "cd"},
+				Diff{DiffInsert, "34"},
+			},
+			[]Diff{
+				Diff{DiffDelete, "abwxyzcd"},
+				Diff{DiffInsert, "12wxyz34"},
+			},
+		},
+	} {
+		actual := dmp.DiffCleanupEfficiency(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffPrettyHtml(t *testing.T) {
+	type TestCase struct {
+		Diffs []Diff
+
+		Expected string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			Diffs: []Diff{
+				{DiffEqual, "a\n"},
+				{DiffDelete, "<B>b</B>"},
+				{DiffInsert, "c&d"},
+			},
+
+			Expected: "<span>a&para;<br></span><del style=\"background:#ffe6e6;\">&lt;B&gt;b&lt;/B&gt;</del><ins style=\"background:#e6ffe6;\">c&amp;d</ins>",
+		},
+	} {
+		actual := dmp.DiffPrettyHtml(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestDiffPrettyText(t *testing.T) {
+	type TestCase struct {
+		Diffs []Diff
+
+		Expected string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			Diffs: []Diff{
+				{DiffEqual, "a\n"},
+				{DiffDelete, "<B>b</B>"},
+				{DiffInsert, "c&d"},
+			},
+
+			Expected: "a\n\x1b[31m<B>b</B>\x1b[0m\x1b[32mc&d\x1b[0m",
+		},
+	} {
+		actual := dmp.DiffPrettyText(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestDiffText(t *testing.T) {
+	type TestCase struct {
+		Diffs []Diff
+
+		ExpectedText1 string
+		ExpectedText2 string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			Diffs: []Diff{
+				{DiffEqual, "jump"},
+				{DiffDelete, "s"},
+				{DiffInsert, "ed"},
+				{DiffEqual, " over "},
+				{DiffDelete, "the"},
+				{DiffInsert, "a"},
+				{DiffEqual, " lazy"},
+			},
+
+			ExpectedText1: "jumps over the lazy",
+			ExpectedText2: "jumped over a lazy",
+		},
+	} {
+		actualText1 := dmp.DiffText1(tc.Diffs)
+		assert.Equal(t, tc.ExpectedText1, actualText1, fmt.Sprintf("Test case #%d, %#v", i, tc))
+
+		actualText2 := dmp.DiffText2(tc.Diffs)
+		assert.Equal(t, tc.ExpectedText2, actualText2, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestDiffDelta(t *testing.T) {
+	dmp := New()
+
+	// Convert a diff into delta string.
+	diffs := []Diff{
+		Diff{DiffEqual, "jump"},
+		Diff{DiffDelete, "s"},
+		Diff{DiffInsert, "ed"},
+		Diff{DiffEqual, " over "},
+		Diff{DiffDelete, "the"},
+		Diff{DiffInsert, "a"},
+		Diff{DiffEqual, " lazy"},
+		Diff{DiffInsert, "old dog"},
+	}
+	text1 := dmp.DiffText1(diffs)
+	assert.Equal(t, "jumps over the lazy", text1)
+
+	delta := dmp.DiffToDelta(diffs)
+	assert.Equal(t, "=4\t-1\t+ed\t=6\t-3\t+a\t=5\t+old dog", delta)
+
+	// Convert delta string into a diff.
+	deltaDiffs, err := dmp.DiffFromDelta(text1, delta)
+	assert.Equal(t, diffs, deltaDiffs)
+
+	// Generates error (19 < 20).
+	_, err = dmp.DiffFromDelta(text1+"x", delta)
+	if err == nil {
+		t.Fatal("Too long.")
+	}
+
+	// Generates error (19 > 18).
+	_, err = dmp.DiffFromDelta(text1[1:], delta)
+	if err == nil {
+		t.Fatal("Too short.")
+	}
+
+	// Generates error (%xy invalid URL escape).
+	_, err = dmp.DiffFromDelta("", "+%c3%xy")
+	if err == nil {
+		assert.Fail(t, "expected Invalid URL escape.")
+	}
+
+	// Generates error (invalid utf8).
+	_, err = dmp.DiffFromDelta("", "+%c3xy")
+	if err == nil {
+		assert.Fail(t, "expected Invalid utf8.")
+	}
+
+	// Test deltas with special characters.
+	diffs = []Diff{
+		Diff{DiffEqual, "\u0680 \x00 \t %"},
+		Diff{DiffDelete, "\u0681 \x01 \n ^"},
+		Diff{DiffInsert, "\u0682 \x02 \\ |"},
+	}
+	text1 = dmp.DiffText1(diffs)
+	assert.Equal(t, "\u0680 \x00 \t %\u0681 \x01 \n ^", text1)
+
+	// Lowercase, due to UrlEncode uses lower.
+	delta = dmp.DiffToDelta(diffs)
+	assert.Equal(t, "=7\t-7\t+%DA%82 %02 %5C %7C", delta)
+
+	deltaDiffs, err = dmp.DiffFromDelta(text1, delta)
+	assert.Equal(t, diffs, deltaDiffs)
+	assert.Nil(t, err)
+
+	// Verify pool of unchanged characters.
+	diffs = []Diff{
+		Diff{DiffInsert, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # "},
+	}
+
+	delta = dmp.DiffToDelta(diffs)
+	assert.Equal(t, "+A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ", delta, "Unchanged characters.")
+
+	// Convert delta string into a diff.
+	deltaDiffs, err = dmp.DiffFromDelta("", delta)
+	assert.Equal(t, diffs, deltaDiffs)
+	assert.Nil(t, err)
+}
+
+func TestDiffXIndex(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Diffs    []Diff
+		Location int
+
+		Expected int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Translation on equality", []Diff{{DiffDelete, "a"}, {DiffInsert, "1234"}, {DiffEqual, "xyz"}}, 2, 5},
+		{"Translation on deletion", []Diff{{DiffEqual, "a"}, {DiffDelete, "1234"}, {DiffEqual, "xyz"}}, 3, 1},
+	} {
+		actual := dmp.DiffXIndex(tc.Diffs, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffLevenshtein(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Diffs []Diff
+
+		Expected int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Levenshtein with trailing equality", []Diff{{DiffDelete, "abc"}, {DiffInsert, "1234"}, {DiffEqual, "xyz"}}, 4},
+		{"Levenshtein with leading equality", []Diff{{DiffEqual, "xyz"}, {DiffDelete, "abc"}, {DiffInsert, "1234"}}, 4},
+		{"Levenshtein with middle equality", []Diff{{DiffDelete, "abc"}, {DiffEqual, "xyz"}, {DiffInsert, "1234"}}, 7},
+	} {
+		actual := dmp.DiffLevenshtein(tc.Diffs)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffBisect(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Time time.Time
+
+		Expected []Diff
+	}
+
+	dmp := New()
+
+	text1 := "cat"
+	text2 := "map"
+
+	for i, tc := range []TestCase{
+		{
+			Name: "normal",
+			Time: time.Date(9999, time.December, 31, 23, 59, 59, 59, time.UTC),
+
+			Expected: []Diff{
+				{DiffDelete, "c"},
+				{DiffInsert, "m"},
+				{DiffEqual, "a"},
+				{DiffDelete, "t"},
+				{DiffInsert, "p"},
+			},
+		},
+		{
+			Name: "Negative deadlines count as having infinite time",
+			Time: time.Date(0001, time.January, 01, 00, 00, 00, 00, time.UTC),
+
+			Expected: []Diff{
+				{DiffDelete, "c"},
+				{DiffInsert, "m"},
+				{DiffEqual, "a"},
+				{DiffDelete, "t"},
+				{DiffInsert, "p"},
+			},
+		},
+		{
+			Name: "Timeout",
+			Time: time.Now().Add(time.Nanosecond),
+
+			Expected: []Diff{
+				{DiffDelete, "cat"},
+				{DiffInsert, "map"},
+			},
+		},
+	} {
+		actual := dmp.DiffBisect(text1, text2, tc.Time)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestDiffMain(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+
+		Expected []Diff
+	}
+
+	dmp := New()
+
+	// Perform a trivial diff.
+	for i, tc := range []TestCase{
+		{
+			"",
+			"",
+			nil,
+		},
+		{
+			"abc",
+			"abc",
+			[]Diff{Diff{DiffEqual, "abc"}},
+		},
+		{
+			"abc",
+			"ab123c",
+			[]Diff{Diff{DiffEqual, "ab"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "c"}},
+		},
+		{
+			"a123bc",
+			"abc",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "bc"}},
+		},
+		{
+			"abc",
+			"a123b456c",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "b"}, Diff{DiffInsert, "456"}, Diff{DiffEqual, "c"}},
+		},
+		{
+			"a123b456c",
+			"abc",
+			[]Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "b"}, Diff{DiffDelete, "456"}, Diff{DiffEqual, "c"}},
+		},
+	} {
+		actual := dmp.DiffMain(tc.Text1, tc.Text2, false)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+
+	// Perform a real diff and switch off the timeout.
+	dmp.DiffTimeout = 0
+
+	for i, tc := range []TestCase{
+		{
+			"a",
+			"b",
+			[]Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "b"}},
+		},
+		{
+			"Apples are a fruit.",
+			"Bananas are also fruit.",
+			[]Diff{
+				Diff{DiffDelete, "Apple"},
+				Diff{DiffInsert, "Banana"},
+				Diff{DiffEqual, "s are a"},
+				Diff{DiffInsert, "lso"},
+				Diff{DiffEqual, " fruit."},
+			},
+		},
+		{
+			"ax\t",
+			"\u0680x\u0000",
+			[]Diff{
+				Diff{DiffDelete, "a"},
+				Diff{DiffInsert, "\u0680"},
+				Diff{DiffEqual, "x"},
+				Diff{DiffDelete, "\t"},
+				Diff{DiffInsert, "\u0000"},
+			},
+		},
+		{
+			"1ayb2",
+			"abxab",
+			[]Diff{
+				Diff{DiffDelete, "1"},
+				Diff{DiffEqual, "a"},
+				Diff{DiffDelete, "y"},
+				Diff{DiffEqual, "b"},
+				Diff{DiffDelete, "2"},
+				Diff{DiffInsert, "xab"},
+			},
+		},
+		{
+			"abcy",
+			"xaxcxabc",
+			[]Diff{
+				Diff{DiffInsert, "xaxcx"},
+				Diff{DiffEqual, "abc"}, Diff{DiffDelete, "y"},
+			},
+		},
+		{
+			"ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg",
+			"a-bcd-efghijklmnopqrs",
+			[]Diff{
+				Diff{DiffDelete, "ABCD"},
+				Diff{DiffEqual, "a"},
+				Diff{DiffDelete, "="},
+				Diff{DiffInsert, "-"},
+				Diff{DiffEqual, "bcd"},
+				Diff{DiffDelete, "="},
+				Diff{DiffInsert, "-"},
+				Diff{DiffEqual, "efghijklmnopqrs"},
+				Diff{DiffDelete, "EFGHIJKLMNOefg"},
+			},
+		},
+		{
+			"a [[Pennsylvania]] and [[New",
+			" and [[Pennsylvania]]",
+			[]Diff{
+				Diff{DiffInsert, " "},
+				Diff{DiffEqual, "a"},
+				Diff{DiffInsert, "nd"},
+				Diff{DiffEqual, " [[Pennsylvania]]"},
+				Diff{DiffDelete, " and [[New"},
+			},
+		},
+	} {
+		actual := dmp.DiffMain(tc.Text1, tc.Text2, false)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestDiffMainWithTimeout(t *testing.T) {
+	dmp := New()
+	dmp.DiffTimeout = 200 * time.Millisecond
+
+	a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
+	b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
+	// Increase the text lengths by 1024 times to ensure a timeout.
+	for x := 0; x < 13; x++ {
+		a = a + a
+		b = b + b
+	}
+
+	startTime := time.Now()
+	dmp.DiffMain(a, b, true)
+	endTime := time.Now()
+
+	delta := endTime.Sub(startTime)
+
+	// Test that we took at least the timeout period.
+	assert.True(t, delta >= dmp.DiffTimeout, fmt.Sprintf("%v !>= %v", delta, dmp.DiffTimeout))
+
+	// Test that we didn't take forever (be very forgiving). Theoretically this test could fail very occasionally if the OS task swaps or locks up for a second at the wrong moment.
+	assert.True(t, delta < (dmp.DiffTimeout*100), fmt.Sprintf("%v !< %v", delta, dmp.DiffTimeout*100))
+}
+
+func TestDiffMainWithCheckLines(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+	}
+
+	dmp := New()
+	dmp.DiffTimeout = 0
+
+	// Test cases must be at least 100 chars long to pass the cutoff.
+	for i, tc := range []TestCase{
+		{
+			"1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n",
+			"abcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\n",
+		},
+		{
+			"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
+			"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
+		},
+		{
+			"1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n",
+			"abcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n",
+		},
+	} {
+		resultWithoutCheckLines := dmp.DiffMain(tc.Text1, tc.Text2, false)
+		resultWithCheckLines := dmp.DiffMain(tc.Text1, tc.Text2, true)
+
+		// TODO this fails for the third test case, why?
+		if i != 2 {
+			assert.Equal(t, resultWithoutCheckLines, resultWithCheckLines, fmt.Sprintf("Test case #%d, %#v", i, tc))
+		}
+		assert.Equal(t, diffRebuildTexts(resultWithoutCheckLines), diffRebuildTexts(resultWithCheckLines), fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func BenchmarkDiffMain(bench *testing.B) {
+	s1 := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
+	s2 := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
+
+	// Increase the text lengths by 1024 times to ensure a timeout.
+	for x := 0; x < 10; x++ {
+		s1 = s1 + s1
+		s2 = s2 + s2
+	}
+
+	dmp := New()
+	dmp.DiffTimeout = time.Second
+
+	bench.ResetTimer()
+
+	for i := 0; i < bench.N; i++ {
+		dmp.DiffMain(s1, s2, true)
+	}
+}
+
+func BenchmarkDiffMainLarge(b *testing.B) {
+	s1, s2 := speedtestTexts()
+
+	dmp := New()
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		dmp.DiffMain(s1, s2, true)
+	}
+}
+
+func BenchmarkDiffMainRunesLargeLines(b *testing.B) {
+	s1, s2 := speedtestTexts()
+
+	dmp := New()
+
+	b.ResetTimer()
+
+	for i := 0; i < b.N; i++ {
+		text1, text2, linearray := dmp.DiffLinesToRunes(s1, s2)
+
+		diffs := dmp.DiffMainRunes(text1, text2, false)
+		diffs = dmp.DiffCharsToLines(diffs, linearray)
+	}
+}
diff --git a/diffmatchpatch/diffmatchpatch.go b/diffmatchpatch/diffmatchpatch.go
new file mode 100644
index 0000000..d3acc32
--- /dev/null
+++ b/diffmatchpatch/diffmatchpatch.go
@@ -0,0 +1,46 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+// Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
+package diffmatchpatch
+
+import (
+	"time"
+)
+
+// DiffMatchPatch holds the configuration for diff-match-patch operations.
+type DiffMatchPatch struct {
+	// Number of seconds to map a diff before giving up (0 for infinity).
+	DiffTimeout time.Duration
+	// Cost of an empty edit operation in terms of edit characters.
+	DiffEditCost int
+	// How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
+	MatchDistance int
+	// When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose).  Note that MatchThreshold controls how closely the end points of a delete need to match.
+	PatchDeleteThreshold float64
+	// Chunk size for context length.
+	PatchMargin int
+	// The number of bits in an int.
+	MatchMaxBits int
+	// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
+	MatchThreshold float64
+}
+
+// New creates a new DiffMatchPatch object with default parameters.
+func New() *DiffMatchPatch {
+	// Defaults.
+	return &DiffMatchPatch{
+		DiffTimeout:          time.Second,
+		DiffEditCost:         4,
+		MatchThreshold:       0.5,
+		MatchDistance:        1000,
+		PatchDeleteThreshold: 0.5,
+		PatchMargin:          4,
+		MatchMaxBits:         32,
+	}
+}
diff --git a/diffmatchpatch/dmp.go b/diffmatchpatch/dmp.go
deleted file mode 100644
index 4e61821..0000000
--- a/diffmatchpatch/dmp.go
+++ /dev/null
@@ -1,2244 +0,0 @@
-/**
- * dmp.go
- *
- * Go language implementation of Google Diff, Match, and Patch library
- *
- * Original library is Copyright (c) 2006 Google Inc.
- * http://code.google.com/p/google-diff-match-patch/
- *
- * Copyright (c) 2012 Sergi Mansilla <sergi.mansilla@gmail.com>
- * https://github.com/sergi/go-diff
- *
- * See included LICENSE file for license details.
- */
-
-// Package diffmatchpatch offers robust algorithms to perform the
-// operations required for synchronizing plain text.
-package diffmatchpatch
-
-import (
-	"bytes"
-	"errors"
-	"fmt"
-	"html"
-	"math"
-	"net/url"
-	"regexp"
-	"strconv"
-	"strings"
-	"time"
-	"unicode/utf8"
-)
-
-// The data structure representing a diff is an array of tuples:
-// [[DiffDelete, 'Hello'], [DiffInsert, 'Goodbye'], [DiffEqual, ' world.']]
-// which means: delete 'Hello', add 'Goodbye' and keep ' world.'
-
-// Operation defines the operation of a diff item.
-type Operation int8
-
-const (
-	// DiffDelete item represents a delete diff.
-	DiffDelete Operation = -1
-	// DiffInsert item represents an insert diff.
-	DiffInsert Operation = 1
-	// DiffEqual item represents an equal diff.
-	DiffEqual Operation = 0
-)
-
-// unescaper unescapes selected chars for compatibility with JavaScript's encodeURI.
-// In speed critical applications this could be dropped since the
-// receiving application will certainly decode these fine.
-// Note that this function is case-sensitive.  Thus "%3F" would not be
-// unescaped.  But this is ok because it is only called with the output of
-// HttpUtility.UrlEncode which returns lowercase hex.
-//
-// Example: "%3f" -> "?", "%24" -> "$", etc.
-var unescaper = strings.NewReplacer(
-	"%21", "!", "%7E", "~", "%27", "'",
-	"%28", "(", "%29", ")", "%3B", ";",
-	"%2F", "/", "%3F", "?", "%3A", ":",
-	"%40", "@", "%26", "&", "%3D", "=",
-	"%2B", "+", "%24", "$", "%2C", ",", "%23", "#", "%2A", "*")
-
-// Define some regex patterns for matching boundaries.
-var (
-	nonAlphaNumericRegex = regexp.MustCompile(`[^a-zA-Z0-9]`)
-	whitespaceRegex      = regexp.MustCompile(`\s`)
-	linebreakRegex       = regexp.MustCompile(`[\r\n]`)
-	blanklineEndRegex    = regexp.MustCompile(`\n\r?\n$`)
-	blanklineStartRegex  = regexp.MustCompile(`^\r?\n\r?\n`)
-)
-
-func splice(slice []Diff, index int, amount int, elements ...Diff) []Diff {
-	return append(slice[:index], append(elements, slice[index+amount:]...)...)
-}
-
-// indexOf returns the first index of pattern in str, starting at str[i].
-func indexOf(str string, pattern string, i int) int {
-	if i > len(str)-1 {
-		return -1
-	}
-	if i <= 0 {
-		return strings.Index(str, pattern)
-	}
-	ind := strings.Index(str[i:], pattern)
-	if ind == -1 {
-		return -1
-	}
-	return ind + i
-}
-
-// lastIndexOf returns the last index of pattern in str, starting at str[i].
-func lastIndexOf(str string, pattern string, i int) int {
-	if i < 0 {
-		return -1
-	}
-	if i >= len(str) {
-		return strings.LastIndex(str, pattern)
-	}
-	_, size := utf8.DecodeRuneInString(str[i:])
-	return strings.LastIndex(str[:i+size], pattern)
-}
-
-// Return the index of pattern in target, starting at target[i].
-func runesIndexOf(target, pattern []rune, i int) int {
-	if i > len(target)-1 {
-		return -1
-	}
-	if i <= 0 {
-		return runesIndex(target, pattern)
-	}
-	ind := runesIndex(target[i:], pattern)
-	if ind == -1 {
-		return -1
-	}
-	return ind + i
-}
-
-func min(x, y int) int {
-	if x < y {
-		return x
-	}
-	return y
-}
-
-func max(x, y int) int {
-	if x > y {
-		return x
-	}
-	return y
-}
-
-func runesEqual(r1, r2 []rune) bool {
-	if len(r1) != len(r2) {
-		return false
-	}
-	for i, c := range r1 {
-		if c != r2[i] {
-			return false
-		}
-	}
-	return true
-}
-
-// The equivalent of strings.Index for rune slices.
-func runesIndex(r1, r2 []rune) int {
-	last := len(r1) - len(r2)
-	for i := 0; i <= last; i++ {
-		if runesEqual(r1[i:i+len(r2)], r2) {
-			return i
-		}
-	}
-	return -1
-}
-
-// Diff represents one diff operation
-type Diff struct {
-	Type Operation
-	Text string
-}
-
-// Patch represents one patch operation.
-type Patch struct {
-	diffs   []Diff
-	start1  int
-	start2  int
-	length1 int
-	length2 int
-}
-
-// String emulates GNU diff's format.
-// Header: @@ -382,8 +481,9 @@
-// Indicies are printed as 1-based, not 0-based.
-func (p *Patch) String() string {
-	var coords1, coords2 string
-
-	if p.length1 == 0 {
-		coords1 = strconv.Itoa(p.start1) + ",0"
-	} else if p.length1 == 1 {
-		coords1 = strconv.Itoa(p.start1 + 1)
-	} else {
-		coords1 = strconv.Itoa(p.start1+1) + "," + strconv.Itoa(p.length1)
-	}
-
-	if p.length2 == 0 {
-		coords2 = strconv.Itoa(p.start2) + ",0"
-	} else if p.length2 == 1 {
-		coords2 = strconv.Itoa(p.start2 + 1)
-	} else {
-		coords2 = strconv.Itoa(p.start2+1) + "," + strconv.Itoa(p.length2)
-	}
-
-	var text bytes.Buffer
-	_, _ = text.WriteString("@@ -" + coords1 + " +" + coords2 + " @@\n")
-
-	// Escape the body of the patch with %xx notation.
-	for _, aDiff := range p.diffs {
-		switch aDiff.Type {
-		case DiffInsert:
-			_, _ = text.WriteString("+")
-		case DiffDelete:
-			_, _ = text.WriteString("-")
-		case DiffEqual:
-			_, _ = text.WriteString(" ")
-		}
-
-		_, _ = text.WriteString(strings.Replace(url.QueryEscape(aDiff.Text), "+", " ", -1))
-		_, _ = text.WriteString("\n")
-	}
-
-	return unescaper.Replace(text.String())
-}
-
-// DiffMatchPatch holds the configuration for diff-match-patch operations.
-type DiffMatchPatch struct {
-	// Number of seconds to map a diff before giving up (0 for infinity).
-	DiffTimeout time.Duration
-	// Cost of an empty edit operation in terms of edit characters.
-	DiffEditCost int
-	// How far to search for a match (0 = exact location, 1000+ = broad match).
-	// A match this many characters away from the expected location will add
-	// 1.0 to the score (0.0 is a perfect match).
-	MatchDistance int
-	// When deleting a large block of text (over ~64 characters), how close do
-	// the contents have to be to match the expected contents. (0.0 = perfection,
-	// 1.0 = very loose).  Note that MatchThreshold controls how closely the
-	// end points of a delete need to match.
-	PatchDeleteThreshold float64
-	// Chunk size for context length.
-	PatchMargin int
-	// The number of bits in an int.
-	MatchMaxBits int
-	// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
-	MatchThreshold float64
-}
-
-// New creates a new DiffMatchPatch object with default parameters.
-func New() *DiffMatchPatch {
-	// Defaults.
-	return &DiffMatchPatch{
-		DiffTimeout:          time.Second,
-		DiffEditCost:         4,
-		MatchThreshold:       0.5,
-		MatchDistance:        1000,
-		PatchDeleteThreshold: 0.5,
-		PatchMargin:          4,
-		MatchMaxBits:         32,
-	}
-}
-
-// DiffMain finds the differences between two texts.
-func (dmp *DiffMatchPatch) DiffMain(text1, text2 string, checklines bool) []Diff {
-	return dmp.DiffMainRunes([]rune(text1), []rune(text2), checklines)
-}
-
-// DiffMainRunes finds the differences between two rune sequences.
-func (dmp *DiffMatchPatch) DiffMainRunes(text1, text2 []rune, checklines bool) []Diff {
-	var deadline time.Time
-	if dmp.DiffTimeout > 0 {
-		deadline = time.Now().Add(dmp.DiffTimeout)
-	}
-	return dmp.diffMainRunes(text1, text2, checklines, deadline)
-}
-
-func (dmp *DiffMatchPatch) diffMainRunes(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {
-	if runesEqual(text1, text2) {
-		var diffs []Diff
-		if len(text1) > 0 {
-			diffs = append(diffs, Diff{DiffEqual, string(text1)})
-		}
-		return diffs
-	}
-	// Trim off common prefix (speedup).
-	commonlength := commonPrefixLength(text1, text2)
-	commonprefix := text1[:commonlength]
-	text1 = text1[commonlength:]
-	text2 = text2[commonlength:]
-
-	// Trim off common suffix (speedup).
-	commonlength = commonSuffixLength(text1, text2)
-	commonsuffix := text1[len(text1)-commonlength:]
-	text1 = text1[:len(text1)-commonlength]
-	text2 = text2[:len(text2)-commonlength]
-
-	// Compute the diff on the middle block.
-	diffs := dmp.diffCompute(text1, text2, checklines, deadline)
-
-	// Restore the prefix and suffix.
-	if len(commonprefix) != 0 {
-		diffs = append([]Diff{Diff{DiffEqual, string(commonprefix)}}, diffs...)
-	}
-	if len(commonsuffix) != 0 {
-		diffs = append(diffs, Diff{DiffEqual, string(commonsuffix)})
-	}
-
-	return dmp.DiffCleanupMerge(diffs)
-}
-
-// diffCompute finds the differences between two rune slices.  Assumes that the texts do not
-// have any common prefix or suffix.
-func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {
-	diffs := []Diff{}
-	if len(text1) == 0 {
-		// Just add some text (speedup).
-		return append(diffs, Diff{DiffInsert, string(text2)})
-	} else if len(text2) == 0 {
-		// Just delete some text (speedup).
-		return append(diffs, Diff{DiffDelete, string(text1)})
-	}
-
-	var longtext, shorttext []rune
-	if len(text1) > len(text2) {
-		longtext = text1
-		shorttext = text2
-	} else {
-		longtext = text2
-		shorttext = text1
-	}
-
-	if i := runesIndex(longtext, shorttext); i != -1 {
-		op := DiffInsert
-		// Swap insertions for deletions if diff is reversed.
-		if len(text1) > len(text2) {
-			op = DiffDelete
-		}
-		// Shorter text is inside the longer text (speedup).
-		return []Diff{
-			Diff{op, string(longtext[:i])},
-			Diff{DiffEqual, string(shorttext)},
-			Diff{op, string(longtext[i+len(shorttext):])},
-		}
-	} else if len(shorttext) == 1 {
-		// Single character string.
-		// After the previous speedup, the character can't be an equality.
-		return []Diff{
-			Diff{DiffDelete, string(text1)},
-			Diff{DiffInsert, string(text2)},
-		}
-		// Check to see if the problem can be split in two.
-	} else if hm := dmp.diffHalfMatch(text1, text2); hm != nil {
-		// A half-match was found, sort out the return data.
-		text1A := hm[0]
-		text1B := hm[1]
-		text2A := hm[2]
-		text2B := hm[3]
-		midCommon := hm[4]
-		// Send both pairs off for separate processing.
-		diffsA := dmp.diffMainRunes(text1A, text2A, checklines, deadline)
-		diffsB := dmp.diffMainRunes(text1B, text2B, checklines, deadline)
-		// Merge the results.
-		return append(diffsA, append([]Diff{Diff{DiffEqual, string(midCommon)}}, diffsB...)...)
-	} else if checklines && len(text1) > 100 && len(text2) > 100 {
-		return dmp.diffLineMode(text1, text2, deadline)
-	}
-	return dmp.diffBisect(text1, text2, deadline)
-}
-
-// diffLineMode does a quick line-level diff on both []runes, then rediff the parts for
-// greater accuracy. This speedup can produce non-minimal diffs.
-func (dmp *DiffMatchPatch) diffLineMode(text1, text2 []rune, deadline time.Time) []Diff {
-	// Scan the text on a line-by-line basis first.
-	text1, text2, linearray := dmp.diffLinesToRunes(text1, text2)
-
-	diffs := dmp.diffMainRunes(text1, text2, false, deadline)
-
-	// Convert the diff back to original text.
-	diffs = dmp.DiffCharsToLines(diffs, linearray)
-	// Eliminate freak matches (e.g. blank lines)
-	diffs = dmp.DiffCleanupSemantic(diffs)
-
-	// Rediff any replacement blocks, this time character-by-character.
-	// Add a dummy entry at the end.
-	diffs = append(diffs, Diff{DiffEqual, ""})
-
-	pointer := 0
-	countDelete := 0
-	countInsert := 0
-
-	// NOTE: Rune slices are slower than using strings in this case.
-	textDelete := ""
-	textInsert := ""
-
-	for pointer < len(diffs) {
-		switch diffs[pointer].Type {
-		case DiffInsert:
-			countInsert++
-			textInsert += diffs[pointer].Text
-		case DiffDelete:
-			countDelete++
-			textDelete += diffs[pointer].Text
-		case DiffEqual:
-			// Upon reaching an equality, check for prior redundancies.
-			if countDelete >= 1 && countInsert >= 1 {
-				// Delete the offending records and add the merged ones.
-				diffs = splice(diffs, pointer-countDelete-countInsert,
-					countDelete+countInsert)
-
-				pointer = pointer - countDelete - countInsert
-				a := dmp.diffMainRunes([]rune(textDelete), []rune(textInsert), false, deadline)
-				for j := len(a) - 1; j >= 0; j-- {
-					diffs = splice(diffs, pointer, 0, a[j])
-				}
-				pointer = pointer + len(a)
-			}
-
-			countInsert = 0
-			countDelete = 0
-			textDelete = ""
-			textInsert = ""
-		}
-		pointer++
-	}
-
-	return diffs[:len(diffs)-1] // Remove the dummy entry at the end.
-}
-
-// DiffBisect finds the 'middle snake' of a diff, split the problem in two
-// and return the recursively constructed diff.
-// See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
-func (dmp *DiffMatchPatch) DiffBisect(text1, text2 string, deadline time.Time) []Diff {
-	// Unused in this code, but retained for interface compatibility.
-	return dmp.diffBisect([]rune(text1), []rune(text2), deadline)
-}
-
-// diffBisect finds the 'middle snake' of a diff, splits the problem in two
-// and returns the recursively constructed diff.
-// See Myers's 1986 paper: An O(ND) Difference Algorithm and Its Variations.
-func (dmp *DiffMatchPatch) diffBisect(runes1, runes2 []rune, deadline time.Time) []Diff {
-	// Cache the text lengths to prevent multiple calls.
-	runes1Len, runes2Len := len(runes1), len(runes2)
-
-	maxD := (runes1Len + runes2Len + 1) / 2
-	vOffset := maxD
-	vLength := 2 * maxD
-
-	v1 := make([]int, vLength)
-	v2 := make([]int, vLength)
-	for i := range v1 {
-		v1[i] = -1
-		v2[i] = -1
-	}
-	v1[vOffset+1] = 0
-	v2[vOffset+1] = 0
-
-	delta := runes1Len - runes2Len
-	// If the total number of characters is odd, then the front path will collide
-	// with the reverse path.
-	front := (delta%2 != 0)
-	// Offsets for start and end of k loop.
-	// Prevents mapping of space beyond the grid.
-	k1start := 0
-	k1end := 0
-	k2start := 0
-	k2end := 0
-	for d := 0; d < maxD; d++ {
-		// Bail out if deadline is reached.
-		if !deadline.IsZero() && time.Now().After(deadline) {
-			break
-		}
-
-		// Walk the front path one step.
-		for k1 := -d + k1start; k1 <= d-k1end; k1 += 2 {
-			k1Offset := vOffset + k1
-			var x1 int
-
-			if k1 == -d || (k1 != d && v1[k1Offset-1] < v1[k1Offset+1]) {
-				x1 = v1[k1Offset+1]
-			} else {
-				x1 = v1[k1Offset-1] + 1
-			}
-
-			y1 := x1 - k1
-			for x1 < runes1Len && y1 < runes2Len {
-				if runes1[x1] != runes2[y1] {
-					break
-				}
-				x1++
-				y1++
-			}
-			v1[k1Offset] = x1
-			if x1 > runes1Len {
-				// Ran off the right of the graph.
-				k1end += 2
-			} else if y1 > runes2Len {
-				// Ran off the bottom of the graph.
-				k1start += 2
-			} else if front {
-				k2Offset := vOffset + delta - k1
-				if k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] != -1 {
-					// Mirror x2 onto top-left coordinate system.
-					x2 := runes1Len - v2[k2Offset]
-					if x1 >= x2 {
-						// Overlap detected.
-						return dmp.diffBisectSplit(runes1, runes2, x1, y1, deadline)
-					}
-				}
-			}
-		}
-		// Walk the reverse path one step.
-		for k2 := -d + k2start; k2 <= d-k2end; k2 += 2 {
-			k2Offset := vOffset + k2
-			var x2 int
-			if k2 == -d || (k2 != d && v2[k2Offset-1] < v2[k2Offset+1]) {
-				x2 = v2[k2Offset+1]
-			} else {
-				x2 = v2[k2Offset-1] + 1
-			}
-			var y2 = x2 - k2
-			for x2 < runes1Len && y2 < runes2Len {
-				if runes1[runes1Len-x2-1] != runes2[runes2Len-y2-1] {
-					break
-				}
-				x2++
-				y2++
-			}
-			v2[k2Offset] = x2
-			if x2 > runes1Len {
-				// Ran off the left of the graph.
-				k2end += 2
-			} else if y2 > runes2Len {
-				// Ran off the top of the graph.
-				k2start += 2
-			} else if !front {
-				k1Offset := vOffset + delta - k2
-				if k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] != -1 {
-					x1 := v1[k1Offset]
-					y1 := vOffset + x1 - k1Offset
-					// Mirror x2 onto top-left coordinate system.
-					x2 = runes1Len - x2
-					if x1 >= x2 {
-						// Overlap detected.
-						return dmp.diffBisectSplit(runes1, runes2, x1, y1, deadline)
-					}
-				}
-			}
-		}
-	}
-	// Diff took too long and hit the deadline or
-	// number of diffs equals number of characters, no commonality at all.
-	return []Diff{
-		Diff{DiffDelete, string(runes1)},
-		Diff{DiffInsert, string(runes2)},
-	}
-}
-
-func (dmp *DiffMatchPatch) diffBisectSplit(runes1, runes2 []rune, x, y int,
-	deadline time.Time) []Diff {
-	runes1a := runes1[:x]
-	runes2a := runes2[:y]
-	runes1b := runes1[x:]
-	runes2b := runes2[y:]
-
-	// Compute both diffs serially.
-	diffs := dmp.diffMainRunes(runes1a, runes2a, false, deadline)
-	diffsb := dmp.diffMainRunes(runes1b, runes2b, false, deadline)
-
-	return append(diffs, diffsb...)
-}
-
-// DiffLinesToChars splits two texts into a list of strings.  Reduces the texts to a string of
-// hashes where each Unicode character represents one line.
-// It's slightly faster to call DiffLinesToRunes first, followed by DiffMainRunes.
-func (dmp *DiffMatchPatch) DiffLinesToChars(text1, text2 string) (string, string, []string) {
-	chars1, chars2, lineArray := dmp.DiffLinesToRunes(text1, text2)
-	return string(chars1), string(chars2), lineArray
-}
-
-// DiffLinesToRunes splits two texts into a list of runes.  Each rune represents one line.
-func (dmp *DiffMatchPatch) DiffLinesToRunes(text1, text2 string) ([]rune, []rune, []string) {
-	// '\x00' is a valid character, but various debuggers don't like it.
-	// So we'll insert a junk entry to avoid generating a null character.
-	lineArray := []string{""}    // e.g. lineArray[4] == 'Hello\n'
-	lineHash := map[string]int{} // e.g. lineHash['Hello\n'] == 4
-
-	chars1 := dmp.diffLinesToRunesMunge(text1, &lineArray, lineHash)
-	chars2 := dmp.diffLinesToRunesMunge(text2, &lineArray, lineHash)
-
-	return chars1, chars2, lineArray
-}
-
-func (dmp *DiffMatchPatch) diffLinesToRunes(text1, text2 []rune) ([]rune, []rune, []string) {
-	return dmp.DiffLinesToRunes(string(text1), string(text2))
-}
-
-// diffLinesToRunesMunge splits a text into an array of strings.  Reduces the
-// texts to a []rune where each Unicode character represents one line.
-// We use strings instead of []runes as input mainly because you can't use []rune as a map key.
-func (dmp *DiffMatchPatch) diffLinesToRunesMunge(text string, lineArray *[]string, lineHash map[string]int) []rune {
-	// Walk the text, pulling out a substring for each line.
-	// text.split('\n') would would temporarily double our memory footprint.
-	// Modifying text would create many large strings to garbage collect.
-	lineStart := 0
-	lineEnd := -1
-	runes := []rune{}
-
-	for lineEnd < len(text)-1 {
-		lineEnd = indexOf(text, "\n", lineStart)
-
-		if lineEnd == -1 {
-			lineEnd = len(text) - 1
-		}
-
-		line := text[lineStart : lineEnd+1]
-		lineStart = lineEnd + 1
-		lineValue, ok := lineHash[line]
-
-		if ok {
-			runes = append(runes, rune(lineValue))
-		} else {
-			*lineArray = append(*lineArray, line)
-			lineHash[line] = len(*lineArray) - 1
-			runes = append(runes, rune(len(*lineArray)-1))
-		}
-	}
-
-	return runes
-}
-
-// DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of
-// text.
-func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []Diff {
-	hydrated := make([]Diff, 0, len(diffs))
-	for _, aDiff := range diffs {
-		chars := aDiff.Text
-		text := make([]string, len(chars))
-
-		for i, r := range chars {
-			text[i] = lineArray[r]
-		}
-
-		aDiff.Text = strings.Join(text, "")
-		hydrated = append(hydrated, aDiff)
-	}
-	return hydrated
-}
-
-// DiffCommonPrefix determines the common prefix length of two strings.
-func (dmp *DiffMatchPatch) DiffCommonPrefix(text1, text2 string) int {
-	// Unused in this code, but retained for interface compatibility.
-	return commonPrefixLength([]rune(text1), []rune(text2))
-}
-
-// DiffCommonSuffix determines the common suffix length of two strings.
-func (dmp *DiffMatchPatch) DiffCommonSuffix(text1, text2 string) int {
-	// Unused in this code, but retained for interface compatibility.
-	return commonSuffixLength([]rune(text1), []rune(text2))
-}
-
-// commonPrefixLength returns the length of the common prefix of two rune slices.
-func commonPrefixLength(text1, text2 []rune) int {
-	short, long := text1, text2
-	if len(short) > len(long) {
-		short, long = long, short
-	}
-	for i, r := range short {
-		if r != long[i] {
-			return i
-		}
-	}
-	return len(short)
-}
-
-// commonSuffixLength returns the length of the common suffix of two rune slices.
-func commonSuffixLength(text1, text2 []rune) int {
-	n := min(len(text1), len(text2))
-	for i := 0; i < n; i++ {
-		if text1[len(text1)-i-1] != text2[len(text2)-i-1] {
-			return i
-		}
-	}
-	return n
-
-	// Binary search.
-	// Performance analysis: http://neil.fraser.name/news/2007/10/09/
-	/*
-	   pointermin := 0
-	   pointermax := math.Min(len(text1), len(text2))
-	   pointermid := pointermax
-	   pointerend := 0
-	   for pointermin < pointermid {
-	       if text1[len(text1)-pointermid:len(text1)-pointerend] ==
-	           text2[len(text2)-pointermid:len(text2)-pointerend] {
-	           pointermin = pointermid
-	           pointerend = pointermin
-	       } else {
-	           pointermax = pointermid
-	       }
-	       pointermid = math.Floor((pointermax-pointermin)/2 + pointermin)
-	   }
-	   return pointermid
-	*/
-}
-
-// DiffCommonOverlap determines if the suffix of one string is the prefix of another.
-func (dmp *DiffMatchPatch) DiffCommonOverlap(text1 string, text2 string) int {
-	// Cache the text lengths to prevent multiple calls.
-	text1Length := len(text1)
-	text2Length := len(text2)
-	// Eliminate the null case.
-	if text1Length == 0 || text2Length == 0 {
-		return 0
-	}
-	// Truncate the longer string.
-	if text1Length > text2Length {
-		text1 = text1[text1Length-text2Length:]
-	} else if text1Length < text2Length {
-		text2 = text2[0:text1Length]
-	}
-	textLength := int(math.Min(float64(text1Length), float64(text2Length)))
-	// Quick check for the worst case.
-	if text1 == text2 {
-		return textLength
-	}
-
-	// Start by looking for a single character match
-	// and increase length until no match is found.
-	// Performance analysis: http://neil.fraser.name/news/2010/11/04/
-	best := 0
-	length := 1
-	for {
-		pattern := text1[textLength-length:]
-		found := strings.Index(text2, pattern)
-		if found == -1 {
-			break
-		}
-		length += found
-		if found == 0 || text1[textLength-length:] == text2[0:length] {
-			best = length
-			length++
-		}
-	}
-
-	return best
-}
-
-// DiffHalfMatch checks whether the two texts share a substring which is at
-// least half the length of the longer text. This speedup can produce non-minimal diffs.
-func (dmp *DiffMatchPatch) DiffHalfMatch(text1, text2 string) []string {
-	// Unused in this code, but retained for interface compatibility.
-	runeSlices := dmp.diffHalfMatch([]rune(text1), []rune(text2))
-	if runeSlices == nil {
-		return nil
-	}
-
-	result := make([]string, len(runeSlices))
-	for i, r := range runeSlices {
-		result[i] = string(r)
-	}
-	return result
-}
-
-func (dmp *DiffMatchPatch) diffHalfMatch(text1, text2 []rune) [][]rune {
-	if dmp.DiffTimeout <= 0 {
-		// Don't risk returning a non-optimal diff if we have unlimited time.
-		return nil
-	}
-
-	var longtext, shorttext []rune
-	if len(text1) > len(text2) {
-		longtext = text1
-		shorttext = text2
-	} else {
-		longtext = text2
-		shorttext = text1
-	}
-
-	if len(longtext) < 4 || len(shorttext)*2 < len(longtext) {
-		return nil // Pointless.
-	}
-
-	// First check if the second quarter is the seed for a half-match.
-	hm1 := dmp.diffHalfMatchI(longtext, shorttext, int(float64(len(longtext)+3)/4))
-
-	// Check again based on the third quarter.
-	hm2 := dmp.diffHalfMatchI(longtext, shorttext, int(float64(len(longtext)+1)/2))
-
-	hm := [][]rune{}
-	if hm1 == nil && hm2 == nil {
-		return nil
-	} else if hm2 == nil {
-		hm = hm1
-	} else if hm1 == nil {
-		hm = hm2
-	} else {
-		// Both matched.  Select the longest.
-		if len(hm1[4]) > len(hm2[4]) {
-			hm = hm1
-		} else {
-			hm = hm2
-		}
-	}
-
-	// A half-match was found, sort out the return data.
-	if len(text1) > len(text2) {
-		return hm
-	}
-
-	return [][]rune{hm[2], hm[3], hm[0], hm[1], hm[4]}
-}
-
-// diffHalfMatchI checks if a substring of shorttext exist within longtext such that the substring is at least half the length of longtext?
-// @param {string} longtext Longer string.
-// @param {string} shorttext Shorter string.
-// @param {number} i Start index of quarter length substring within longtext.
-// @return {Array.<string>} Five element Array, containing the prefix of
-//     longtext, the suffix of longtext, the prefix of shorttext, the suffix
-//     of shorttext and the common middle.  Or null if there was no match.
-func (dmp *DiffMatchPatch) diffHalfMatchI(l, s []rune, i int) [][]rune {
-	var bestCommonA []rune
-	var bestCommonB []rune
-	var bestCommonLen int
-	var bestLongtextA []rune
-	var bestLongtextB []rune
-	var bestShorttextA []rune
-	var bestShorttextB []rune
-
-	// Start with a 1/4 length substring at position i as a seed.
-	seed := l[i : i+len(l)/4]
-
-	for j := runesIndexOf(s, seed, 0); j != -1; j = runesIndexOf(s, seed, j+1) {
-		prefixLength := commonPrefixLength(l[i:], s[j:])
-		suffixLength := commonSuffixLength(l[:i], s[:j])
-
-		if bestCommonLen < suffixLength+prefixLength {
-			bestCommonA = s[j-suffixLength : j]
-			bestCommonB = s[j : j+prefixLength]
-			bestCommonLen = len(bestCommonA) + len(bestCommonB)
-			bestLongtextA = l[:i-suffixLength]
-			bestLongtextB = l[i+prefixLength:]
-			bestShorttextA = s[:j-suffixLength]
-			bestShorttextB = s[j+prefixLength:]
-		}
-	}
-
-	if bestCommonLen*2 < len(l) {
-		return nil
-	}
-
-	return [][]rune{
-		bestLongtextA,
-		bestLongtextB,
-		bestShorttextA,
-		bestShorttextB,
-		append(bestCommonA, bestCommonB...),
-	}
-}
-
-// DiffCleanupSemantic reduces the number of edits by eliminating
-// semantically trivial equalities.
-func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
-	changes := false
-	// Stack of indices where equalities are found.
-	type equality struct {
-		data int
-		next *equality
-	}
-	var equalities *equality
-
-	var lastequality string
-	// Always equal to diffs[equalities[equalitiesLength - 1]][1]
-	var pointer int // Index of current position.
-	// Number of characters that changed prior to the equality.
-	var lengthInsertions1, lengthDeletions1 int
-	// Number of characters that changed after the equality.
-	var lengthInsertions2, lengthDeletions2 int
-
-	for pointer < len(diffs) {
-		if diffs[pointer].Type == DiffEqual { // Equality found.
-			equalities = &equality{
-				data: pointer,
-				next: equalities,
-			}
-			lengthInsertions1 = lengthInsertions2
-			lengthDeletions1 = lengthDeletions2
-			lengthInsertions2 = 0
-			lengthDeletions2 = 0
-			lastequality = diffs[pointer].Text
-		} else { // An insertion or deletion.
-			if diffs[pointer].Type == DiffInsert {
-				lengthInsertions2 += len(diffs[pointer].Text)
-			} else {
-				lengthDeletions2 += len(diffs[pointer].Text)
-			}
-			// Eliminate an equality that is smaller or equal to the edits on both
-			// sides of it.
-			difference1 := int(math.Max(float64(lengthInsertions1), float64(lengthDeletions1)))
-			difference2 := int(math.Max(float64(lengthInsertions2), float64(lengthDeletions2)))
-			if len(lastequality) > 0 &&
-				(len(lastequality) <= difference1) &&
-				(len(lastequality) <= difference2) {
-				// Duplicate record.
-				insPoint := equalities.data
-				diffs = append(
-					diffs[:insPoint],
-					append([]Diff{Diff{DiffDelete, lastequality}}, diffs[insPoint:]...)...)
-
-				// Change second copy to insert.
-				diffs[insPoint+1].Type = DiffInsert
-				// Throw away the equality we just deleted.
-				equalities = equalities.next
-
-				if equalities != nil {
-					equalities = equalities.next
-				}
-				if equalities != nil {
-					pointer = equalities.data
-				} else {
-					pointer = -1
-				}
-
-				lengthInsertions1 = 0 // Reset the counters.
-				lengthDeletions1 = 0
-				lengthInsertions2 = 0
-				lengthDeletions2 = 0
-				lastequality = ""
-				changes = true
-			}
-		}
-		pointer++
-	}
-
-	// Normalize the diff.
-	if changes {
-		diffs = dmp.DiffCleanupMerge(diffs)
-	}
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-	// Find any overlaps between deletions and insertions.
-	// e.g: <del>abcxxx</del><ins>xxxdef</ins>
-	//   -> <del>abc</del>xxx<ins>def</ins>
-	// e.g: <del>xxxabc</del><ins>defxxx</ins>
-	//   -> <ins>def</ins>xxx<del>abc</del>
-	// Only extract an overlap if it is as big as the edit ahead or behind it.
-	pointer = 1
-	for pointer < len(diffs) {
-		if diffs[pointer-1].Type == DiffDelete &&
-			diffs[pointer].Type == DiffInsert {
-			deletion := diffs[pointer-1].Text
-			insertion := diffs[pointer].Text
-			overlapLength1 := dmp.DiffCommonOverlap(deletion, insertion)
-			overlapLength2 := dmp.DiffCommonOverlap(insertion, deletion)
-			if overlapLength1 >= overlapLength2 {
-				if float64(overlapLength1) >= float64(len(deletion))/2 ||
-					float64(overlapLength1) >= float64(len(insertion))/2 {
-
-					// Overlap found.  Insert an equality and trim the surrounding edits.
-					diffs = append(
-						diffs[:pointer],
-						append([]Diff{Diff{DiffEqual, insertion[:overlapLength1]}}, diffs[pointer:]...)...)
-					//diffs.splice(pointer, 0,
-					//    [DiffEqual, insertion[0 : overlapLength1)]]
-					diffs[pointer-1].Text =
-						deletion[0 : len(deletion)-overlapLength1]
-					diffs[pointer+1].Text = insertion[overlapLength1:]
-					pointer++
-				}
-			} else {
-				if float64(overlapLength2) >= float64(len(deletion))/2 ||
-					float64(overlapLength2) >= float64(len(insertion))/2 {
-					// Reverse overlap found.
-					// Insert an equality and swap and trim the surrounding edits.
-					overlap := Diff{DiffEqual, deletion[:overlapLength2]}
-					diffs = append(
-						diffs[:pointer],
-						append([]Diff{overlap}, diffs[pointer:]...)...)
-					// diffs.splice(pointer, 0,
-					//     [DiffEqual, deletion[0 : overlapLength2)]]
-					diffs[pointer-1].Type = DiffInsert
-					diffs[pointer-1].Text = insertion[0 : len(insertion)-overlapLength2]
-					diffs[pointer+1].Type = DiffDelete
-					diffs[pointer+1].Text = deletion[overlapLength2:]
-					pointer++
-				}
-			}
-			pointer++
-		}
-		pointer++
-	}
-
-	return diffs
-}
-
-// DiffCleanupSemanticLossless looks for single edits surrounded on both sides by equalities
-// which can be shifted sideways to align the edit to a word boundary.
-// e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
-func (dmp *DiffMatchPatch) DiffCleanupSemanticLossless(diffs []Diff) []Diff {
-
-	/**
-	 * Given two strings, compute a score representing whether the internal
-	 * boundary falls on logical boundaries.
-	 * Scores range from 6 (best) to 0 (worst).
-	 * Closure, but does not reference any external variables.
-	 * @param {string} one First string.
-	 * @param {string} two Second string.
-	 * @return {number} The score.
-	 * @private
-	 */
-	diffCleanupSemanticScore := func(one, two string) int {
-		if len(one) == 0 || len(two) == 0 {
-			// Edges are the best.
-			return 6
-		}
-
-		// Each port of this function behaves slightly differently due to
-		// subtle differences in each language's definition of things like
-		// 'whitespace'.  Since this function's purpose is largely cosmetic,
-		// the choice has been made to use each language's native features
-		// rather than force total conformity.
-		rune1, _ := utf8.DecodeLastRuneInString(one)
-		rune2, _ := utf8.DecodeRuneInString(two)
-		char1 := string(rune1)
-		char2 := string(rune2)
-
-		nonAlphaNumeric1 := nonAlphaNumericRegex.MatchString(char1)
-		nonAlphaNumeric2 := nonAlphaNumericRegex.MatchString(char2)
-		whitespace1 := nonAlphaNumeric1 && whitespaceRegex.MatchString(char1)
-		whitespace2 := nonAlphaNumeric2 && whitespaceRegex.MatchString(char2)
-		lineBreak1 := whitespace1 && linebreakRegex.MatchString(char1)
-		lineBreak2 := whitespace2 && linebreakRegex.MatchString(char2)
-		blankLine1 := lineBreak1 && blanklineEndRegex.MatchString(one)
-		blankLine2 := lineBreak2 && blanklineEndRegex.MatchString(two)
-
-		if blankLine1 || blankLine2 {
-			// Five points for blank lines.
-			return 5
-		} else if lineBreak1 || lineBreak2 {
-			// Four points for line breaks.
-			return 4
-		} else if nonAlphaNumeric1 && !whitespace1 && whitespace2 {
-			// Three points for end of sentences.
-			return 3
-		} else if whitespace1 || whitespace2 {
-			// Two points for whitespace.
-			return 2
-		} else if nonAlphaNumeric1 || nonAlphaNumeric2 {
-			// One point for non-alphanumeric.
-			return 1
-		}
-		return 0
-	}
-
-	pointer := 1
-
-	// Intentionally ignore the first and last element (don't need checking).
-	for pointer < len(diffs)-1 {
-		if diffs[pointer-1].Type == DiffEqual &&
-			diffs[pointer+1].Type == DiffEqual {
-
-			// This is a single edit surrounded by equalities.
-			equality1 := diffs[pointer-1].Text
-			edit := diffs[pointer].Text
-			equality2 := diffs[pointer+1].Text
-
-			// First, shift the edit as far left as possible.
-			commonOffset := dmp.DiffCommonSuffix(equality1, edit)
-			if commonOffset > 0 {
-				commonString := edit[len(edit)-commonOffset:]
-				equality1 = equality1[0 : len(equality1)-commonOffset]
-				edit = commonString + edit[:len(edit)-commonOffset]
-				equality2 = commonString + equality2
-			}
-
-			// Second, step character by character right, looking for the best fit.
-			bestEquality1 := equality1
-			bestEdit := edit
-			bestEquality2 := equality2
-			bestScore := diffCleanupSemanticScore(equality1, edit) +
-				diffCleanupSemanticScore(edit, equality2)
-
-			for len(edit) != 0 && len(equality2) != 0 {
-				_, sz := utf8.DecodeRuneInString(edit)
-				if len(equality2) < sz || edit[:sz] != equality2[:sz] {
-					break
-				}
-				equality1 += edit[:sz]
-				edit = edit[sz:] + equality2[:sz]
-				equality2 = equality2[sz:]
-				score := diffCleanupSemanticScore(equality1, edit) +
-					diffCleanupSemanticScore(edit, equality2)
-				// The >= encourages trailing rather than leading whitespace on
-				// edits.
-				if score >= bestScore {
-					bestScore = score
-					bestEquality1 = equality1
-					bestEdit = edit
-					bestEquality2 = equality2
-				}
-			}
-
-			if diffs[pointer-1].Text != bestEquality1 {
-				// We have an improvement, save it back to the diff.
-				if len(bestEquality1) != 0 {
-					diffs[pointer-1].Text = bestEquality1
-				} else {
-					diffs = splice(diffs, pointer-1, 1)
-					pointer--
-				}
-
-				diffs[pointer].Text = bestEdit
-				if len(bestEquality2) != 0 {
-					diffs[pointer+1].Text = bestEquality2
-				} else {
-					//splice(diffs, pointer+1, 1)
-					diffs = append(diffs[:pointer+1], diffs[pointer+2:]...)
-					pointer--
-				}
-			}
-		}
-		pointer++
-	}
-
-	return diffs
-}
-
-// DiffCleanupEfficiency reduces the number of edits by eliminating
-// operationally trivial equalities.
-func (dmp *DiffMatchPatch) DiffCleanupEfficiency(diffs []Diff) []Diff {
-	changes := false
-	// Stack of indices where equalities are found.
-	type equality struct {
-		data int
-		next *equality
-	}
-	var equalities *equality
-	// Always equal to equalities[equalitiesLength-1][1]
-	lastequality := ""
-	pointer := 0 // Index of current position.
-	// Is there an insertion operation before the last equality.
-	preIns := false
-	// Is there a deletion operation before the last equality.
-	preDel := false
-	// Is there an insertion operation after the last equality.
-	postIns := false
-	// Is there a deletion operation after the last equality.
-	postDel := false
-	for pointer < len(diffs) {
-		if diffs[pointer].Type == DiffEqual { // Equality found.
-			if len(diffs[pointer].Text) < dmp.DiffEditCost &&
-				(postIns || postDel) {
-				// Candidate found.
-				equalities = &equality{
-					data: pointer,
-					next: equalities,
-				}
-				preIns = postIns
-				preDel = postDel
-				lastequality = diffs[pointer].Text
-			} else {
-				// Not a candidate, and can never become one.
-				equalities = nil
-				lastequality = ""
-			}
-			postIns = false
-			postDel = false
-		} else { // An insertion or deletion.
-			if diffs[pointer].Type == DiffDelete {
-				postDel = true
-			} else {
-				postIns = true
-			}
-			/*
-			 * Five types to be split:
-			 * <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
-			 * <ins>A</ins>X<ins>C</ins><del>D</del>
-			 * <ins>A</ins><del>B</del>X<ins>C</ins>
-			 * <ins>A</del>X<ins>C</ins><del>D</del>
-			 * <ins>A</ins><del>B</del>X<del>C</del>
-			 */
-			var sumPres int
-			if preIns {
-				sumPres++
-			}
-			if preDel {
-				sumPres++
-			}
-			if postIns {
-				sumPres++
-			}
-			if postDel {
-				sumPres++
-			}
-			if len(lastequality) > 0 &&
-				((preIns && preDel && postIns && postDel) ||
-					((len(lastequality) < dmp.DiffEditCost/2) && sumPres == 3)) {
-
-				insPoint := equalities.data
-
-				// Duplicate record.
-				diffs = append(diffs[:insPoint],
-					append([]Diff{Diff{DiffDelete, lastequality}}, diffs[insPoint:]...)...)
-
-				// Change second copy to insert.
-				diffs[insPoint+1].Type = DiffInsert
-				// Throw away the equality we just deleted.
-				equalities = equalities.next
-				lastequality = ""
-
-				if preIns && preDel {
-					// No changes made which could affect previous entry, keep going.
-					postIns = true
-					postDel = true
-					equalities = nil
-				} else {
-					if equalities != nil {
-						equalities = equalities.next
-					}
-					if equalities != nil {
-						pointer = equalities.data
-					} else {
-						pointer = -1
-					}
-					postIns = false
-					postDel = false
-				}
-				changes = true
-			}
-		}
-		pointer++
-	}
-
-	if changes {
-		diffs = dmp.DiffCleanupMerge(diffs)
-	}
-
-	return diffs
-}
-
-// DiffCleanupMerge reorders and merges like edit sections.  Merge equalities.
-// Any edit section can move as long as it doesn't cross an equality.
-func (dmp *DiffMatchPatch) DiffCleanupMerge(diffs []Diff) []Diff {
-	// Add a dummy entry at the end.
-	diffs = append(diffs, Diff{DiffEqual, ""})
-	pointer := 0
-	countDelete := 0
-	countInsert := 0
-	commonlength := 0
-	textDelete := []rune(nil)
-	textInsert := []rune(nil)
-
-	for pointer < len(diffs) {
-		switch diffs[pointer].Type {
-		case DiffInsert:
-			countInsert++
-			textInsert = append(textInsert, []rune(diffs[pointer].Text)...)
-			pointer++
-			break
-		case DiffDelete:
-			countDelete++
-			textDelete = append(textDelete, []rune(diffs[pointer].Text)...)
-			pointer++
-			break
-		case DiffEqual:
-			// Upon reaching an equality, check for prior redundancies.
-			if countDelete+countInsert > 1 {
-				if countDelete != 0 && countInsert != 0 {
-					// Factor out any common prefixies.
-					commonlength = commonPrefixLength(textInsert, textDelete)
-					if commonlength != 0 {
-						x := pointer - countDelete - countInsert
-						if x > 0 && diffs[x-1].Type == DiffEqual {
-							diffs[x-1].Text += string(textInsert[:commonlength])
-						} else {
-							diffs = append([]Diff{Diff{DiffEqual, string(textInsert[:commonlength])}}, diffs...)
-							pointer++
-						}
-						textInsert = textInsert[commonlength:]
-						textDelete = textDelete[commonlength:]
-					}
-					// Factor out any common suffixies.
-					commonlength = commonSuffixLength(textInsert, textDelete)
-					if commonlength != 0 {
-						insertIndex := len(textInsert) - commonlength
-						deleteIndex := len(textDelete) - commonlength
-						diffs[pointer].Text = string(textInsert[insertIndex:]) + diffs[pointer].Text
-						textInsert = textInsert[:insertIndex]
-						textDelete = textDelete[:deleteIndex]
-					}
-				}
-				// Delete the offending records and add the merged ones.
-				if countDelete == 0 {
-					diffs = splice(diffs, pointer-countInsert,
-						countDelete+countInsert,
-						Diff{DiffInsert, string(textInsert)})
-				} else if countInsert == 0 {
-					diffs = splice(diffs, pointer-countDelete,
-						countDelete+countInsert,
-						Diff{DiffDelete, string(textDelete)})
-				} else {
-					diffs = splice(diffs, pointer-countDelete-countInsert,
-						countDelete+countInsert,
-						Diff{DiffDelete, string(textDelete)},
-						Diff{DiffInsert, string(textInsert)})
-				}
-
-				pointer = pointer - countDelete - countInsert + 1
-				if countDelete != 0 {
-					pointer++
-				}
-				if countInsert != 0 {
-					pointer++
-				}
-			} else if pointer != 0 && diffs[pointer-1].Type == DiffEqual {
-				// Merge this equality with the previous one.
-				diffs[pointer-1].Text += diffs[pointer].Text
-				diffs = append(diffs[:pointer], diffs[pointer+1:]...)
-			} else {
-				pointer++
-			}
-			countInsert = 0
-			countDelete = 0
-			textDelete = nil
-			textInsert = nil
-			break
-		}
-	}
-
-	if len(diffs[len(diffs)-1].Text) == 0 {
-		diffs = diffs[0 : len(diffs)-1] // Remove the dummy entry at the end.
-	}
-
-	// Second pass: look for single edits surrounded on both sides by
-	// equalities which can be shifted sideways to eliminate an equality.
-	// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
-	changes := false
-	pointer = 1
-	// Intentionally ignore the first and last element (don't need checking).
-	for pointer < (len(diffs) - 1) {
-		if diffs[pointer-1].Type == DiffEqual &&
-			diffs[pointer+1].Type == DiffEqual {
-			// This is a single edit surrounded by equalities.
-			if strings.HasSuffix(diffs[pointer].Text, diffs[pointer-1].Text) {
-				// Shift the edit over the previous equality.
-				diffs[pointer].Text = diffs[pointer-1].Text +
-					diffs[pointer].Text[:len(diffs[pointer].Text)-len(diffs[pointer-1].Text)]
-				diffs[pointer+1].Text = diffs[pointer-1].Text + diffs[pointer+1].Text
-				diffs = splice(diffs, pointer-1, 1)
-				changes = true
-			} else if strings.HasPrefix(diffs[pointer].Text, diffs[pointer+1].Text) {
-				// Shift the edit over the next equality.
-				diffs[pointer-1].Text += diffs[pointer+1].Text
-				diffs[pointer].Text =
-					diffs[pointer].Text[len(diffs[pointer+1].Text):] + diffs[pointer+1].Text
-				diffs = splice(diffs, pointer+1, 1)
-				changes = true
-			}
-		}
-		pointer++
-	}
-
-	// If shifts were made, the diff needs reordering and another shift sweep.
-	if changes {
-		diffs = dmp.DiffCleanupMerge(diffs)
-	}
-
-	return diffs
-}
-
-// DiffXIndex returns the equivalent location in s2.
-// loc is a location in text1, comAdde and return the equivalent location in
-// text2.
-// e.g. "The cat" vs "The big cat", 1->1, 5->8
-func (dmp *DiffMatchPatch) DiffXIndex(diffs []Diff, loc int) int {
-	chars1 := 0
-	chars2 := 0
-	lastChars1 := 0
-	lastChars2 := 0
-	lastDiff := Diff{}
-	for i := 0; i < len(diffs); i++ {
-		aDiff := diffs[i]
-		if aDiff.Type != DiffInsert {
-			// Equality or deletion.
-			chars1 += len(aDiff.Text)
-		}
-		if aDiff.Type != DiffDelete {
-			// Equality or insertion.
-			chars2 += len(aDiff.Text)
-		}
-		if chars1 > loc {
-			// Overshot the location.
-			lastDiff = aDiff
-			break
-		}
-		lastChars1 = chars1
-		lastChars2 = chars2
-	}
-	if lastDiff.Type == DiffDelete {
-		// The location was deleted.
-		return lastChars2
-	}
-	// Add the remaining character length.
-	return lastChars2 + (loc - lastChars1)
-}
-
-// DiffPrettyHtml converts a []Diff into a pretty HTML report.
-// It is intended as an example from which to write one's own
-// display functions.
-func (dmp *DiffMatchPatch) DiffPrettyHtml(diffs []Diff) string {
-	var buff bytes.Buffer
-	for _, diff := range diffs {
-		text := strings.Replace(html.EscapeString(diff.Text), "\n", "&para;<br>", -1)
-		switch diff.Type {
-		case DiffInsert:
-			_, _ = buff.WriteString("<ins style=\"background:#e6ffe6;\">")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("</ins>")
-		case DiffDelete:
-			_, _ = buff.WriteString("<del style=\"background:#ffe6e6;\">")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("</del>")
-		case DiffEqual:
-			_, _ = buff.WriteString("<span>")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("</span>")
-		}
-	}
-	return buff.String()
-}
-
-// DiffPrettyText converts a []Diff into a colored text report.
-func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
-	var buff bytes.Buffer
-	for _, diff := range diffs {
-		text := diff.Text
-
-		switch diff.Type {
-		case DiffInsert:
-			_, _ = buff.WriteString("\x1b[32m")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("\x1b[0m")
-		case DiffDelete:
-			_, _ = buff.WriteString("\x1b[31m")
-			_, _ = buff.WriteString(text)
-			_, _ = buff.WriteString("\x1b[0m")
-		case DiffEqual:
-			_, _ = buff.WriteString(text)
-		}
-	}
-
-	return buff.String()
-}
-
-// DiffText1 computes and returns the source text (all equalities and deletions).
-func (dmp *DiffMatchPatch) DiffText1(diffs []Diff) string {
-	//StringBuilder text = new StringBuilder()
-	var text bytes.Buffer
-
-	for _, aDiff := range diffs {
-		if aDiff.Type != DiffInsert {
-			_, _ = text.WriteString(aDiff.Text)
-		}
-	}
-	return text.String()
-}
-
-// DiffText2 computes and returns the destination text (all equalities and insertions).
-func (dmp *DiffMatchPatch) DiffText2(diffs []Diff) string {
-	var text bytes.Buffer
-
-	for _, aDiff := range diffs {
-		if aDiff.Type != DiffDelete {
-			_, _ = text.WriteString(aDiff.Text)
-		}
-	}
-	return text.String()
-}
-
-// DiffLevenshtein computes the Levenshtein distance; the number of inserted, deleted or
-// substituted characters.
-func (dmp *DiffMatchPatch) DiffLevenshtein(diffs []Diff) int {
-	levenshtein := 0
-	insertions := 0
-	deletions := 0
-
-	for _, aDiff := range diffs {
-		switch aDiff.Type {
-		case DiffInsert:
-			insertions += len(aDiff.Text)
-		case DiffDelete:
-			deletions += len(aDiff.Text)
-		case DiffEqual:
-			// A deletion and an insertion is one substitution.
-			levenshtein += max(insertions, deletions)
-			insertions = 0
-			deletions = 0
-		}
-	}
-
-	levenshtein += max(insertions, deletions)
-	return levenshtein
-}
-
-// DiffToDelta crushes the diff into an encoded string which describes the operations
-// required to transform text1 into text2.
-// E.g. =3\t-2\t+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'.
-// Operations are tab-separated.  Inserted text is escaped using %xx
-// notation.
-func (dmp *DiffMatchPatch) DiffToDelta(diffs []Diff) string {
-	var text bytes.Buffer
-	for _, aDiff := range diffs {
-		switch aDiff.Type {
-		case DiffInsert:
-			_, _ = text.WriteString("+")
-			_, _ = text.WriteString(strings.Replace(url.QueryEscape(aDiff.Text), "+", " ", -1))
-			_, _ = text.WriteString("\t")
-			break
-		case DiffDelete:
-			_, _ = text.WriteString("-")
-			_, _ = text.WriteString(strconv.Itoa(utf8.RuneCountInString(aDiff.Text)))
-			_, _ = text.WriteString("\t")
-			break
-		case DiffEqual:
-			_, _ = text.WriteString("=")
-			_, _ = text.WriteString(strconv.Itoa(utf8.RuneCountInString(aDiff.Text)))
-			_, _ = text.WriteString("\t")
-			break
-		}
-	}
-	delta := text.String()
-	if len(delta) != 0 {
-		// Strip off trailing tab character.
-		delta = delta[0 : utf8.RuneCountInString(delta)-1]
-		delta = unescaper.Replace(delta)
-	}
-	return delta
-}
-
-// DiffFromDelta given the original text1, and an encoded string which describes the
-// operations required to transform text1 into text2, comAdde the full diff.
-func (dmp *DiffMatchPatch) DiffFromDelta(text1, delta string) (diffs []Diff, err error) {
-	diffs = []Diff{}
-
-	defer func() {
-		if r := recover(); r != nil {
-			err = r.(error)
-		}
-	}()
-
-	pointer := 0 // Cursor in text1
-	tokens := strings.Split(delta, "\t")
-
-	for _, token := range tokens {
-		if len(token) == 0 {
-			// Blank tokens are ok (from a trailing \t).
-			continue
-		}
-
-		// Each token begins with a one character parameter which specifies the
-		// operation of this token (delete, insert, equality).
-		param := token[1:]
-
-		switch op := token[0]; op {
-		case '+':
-			// decode would Diff all "+" to " "
-			param = strings.Replace(param, "+", "%2b", -1)
-			param, err = url.QueryUnescape(param)
-			if err != nil {
-				return nil, err
-			}
-			if !utf8.ValidString(param) {
-				return nil, fmt.Errorf("invalid UTF-8 token: %q", param)
-			}
-			diffs = append(diffs, Diff{DiffInsert, param})
-		case '=', '-':
-			n, err := strconv.ParseInt(param, 10, 0)
-			if err != nil {
-				return diffs, err
-			} else if n < 0 {
-				return diffs, errors.New("Negative number in DiffFromDelta: " + param)
-			}
-
-			// remember that string slicing is by byte - we want by rune here.
-			text := string([]rune(text1)[pointer : pointer+int(n)])
-			pointer += int(n)
-
-			if op == '=' {
-				diffs = append(diffs, Diff{DiffEqual, text})
-			} else {
-				diffs = append(diffs, Diff{DiffDelete, text})
-			}
-		default:
-			// Anything else is an error.
-			return diffs, errors.New("Invalid diff operation in DiffFromDelta: " + string(token[0]))
-		}
-	}
-
-	if pointer != len([]rune(text1)) {
-		return diffs, fmt.Errorf("Delta length (%v) smaller than source text length (%v)", pointer, len(text1))
-	}
-	return diffs, err
-}
-
-//  MATCH FUNCTIONS
-
-// MatchMain locates the best instance of 'pattern' in 'text' near 'loc'.
-// Returns -1 if no match found.
-func (dmp *DiffMatchPatch) MatchMain(text, pattern string, loc int) int {
-	// Check for null inputs not needed since null can't be passed in C#.
-
-	loc = int(math.Max(0, math.Min(float64(loc), float64(len(text)))))
-	if text == pattern {
-		// Shortcut (potentially not guaranteed by the algorithm)
-		return 0
-	} else if len(text) == 0 {
-		// Nothing to match.
-		return -1
-	} else if loc+len(pattern) <= len(text) && text[loc:loc+len(pattern)] == pattern {
-		// Perfect match at the perfect spot!  (Includes case of null pattern)
-		return loc
-	}
-	// Do a fuzzy compare.
-	return dmp.MatchBitap(text, pattern, loc)
-}
-
-// MatchBitap locates the best instance of 'pattern' in 'text' near 'loc' using the
-// Bitap algorithm.  Returns -1 if no match found.
-func (dmp *DiffMatchPatch) MatchBitap(text, pattern string, loc int) int {
-	// Initialise the alphabet.
-	s := dmp.MatchAlphabet(pattern)
-
-	// Highest score beyond which we give up.
-	scoreThreshold := dmp.MatchThreshold
-	// Is there a nearby exact match? (speedup)
-	bestLoc := indexOf(text, pattern, loc)
-	if bestLoc != -1 {
-		scoreThreshold = math.Min(dmp.matchBitapScore(0, bestLoc, loc,
-			pattern), scoreThreshold)
-		// What about in the other direction? (speedup)
-		bestLoc = lastIndexOf(text, pattern, loc+len(pattern))
-		if bestLoc != -1 {
-			scoreThreshold = math.Min(dmp.matchBitapScore(0, bestLoc, loc,
-				pattern), scoreThreshold)
-		}
-	}
-
-	// Initialise the bit arrays.
-	matchmask := 1 << uint((len(pattern) - 1))
-	bestLoc = -1
-
-	var binMin, binMid int
-	binMax := len(pattern) + len(text)
-	lastRd := []int{}
-	for d := 0; d < len(pattern); d++ {
-		// Scan for the best match; each iteration allows for one more error.
-		// Run a binary search to determine how far from 'loc' we can stray at
-		// this error level.
-		binMin = 0
-		binMid = binMax
-		for binMin < binMid {
-			if dmp.matchBitapScore(d, loc+binMid, loc, pattern) <= scoreThreshold {
-				binMin = binMid
-			} else {
-				binMax = binMid
-			}
-			binMid = (binMax-binMin)/2 + binMin
-		}
-		// Use the result from this iteration as the maximum for the next.
-		binMax = binMid
-		start := int(math.Max(1, float64(loc-binMid+1)))
-		finish := int(math.Min(float64(loc+binMid), float64(len(text))) + float64(len(pattern)))
-
-		rd := make([]int, finish+2)
-		rd[finish+1] = (1 << uint(d)) - 1
-
-		for j := finish; j >= start; j-- {
-			var charMatch int
-			if len(text) <= j-1 {
-				// Out of range.
-				charMatch = 0
-			} else if _, ok := s[text[j-1]]; !ok {
-				charMatch = 0
-			} else {
-				charMatch = s[text[j-1]]
-			}
-
-			if d == 0 {
-				// First pass: exact match.
-				rd[j] = ((rd[j+1] << 1) | 1) & charMatch
-			} else {
-				// Subsequent passes: fuzzy match.
-				rd[j] = ((rd[j+1]<<1)|1)&charMatch | (((lastRd[j+1] | lastRd[j]) << 1) | 1) | lastRd[j+1]
-			}
-			if (rd[j] & matchmask) != 0 {
-				score := dmp.matchBitapScore(d, j-1, loc, pattern)
-				// This match will almost certainly be better than any existing
-				// match.  But check anyway.
-				if score <= scoreThreshold {
-					// Told you so.
-					scoreThreshold = score
-					bestLoc = j - 1
-					if bestLoc > loc {
-						// When passing loc, don't exceed our current distance from loc.
-						start = int(math.Max(1, float64(2*loc-bestLoc)))
-					} else {
-						// Already passed loc, downhill from here on in.
-						break
-					}
-				}
-			}
-		}
-		if dmp.matchBitapScore(d+1, loc, loc, pattern) > scoreThreshold {
-			// No hope for a (better) match at greater error levels.
-			break
-		}
-		lastRd = rd
-	}
-	return bestLoc
-}
-
-// matchBitapScore computes and returns the score for a match with e errors and x location.
-func (dmp *DiffMatchPatch) matchBitapScore(e, x, loc int, pattern string) float64 {
-	accuracy := float64(e) / float64(len(pattern))
-	proximity := math.Abs(float64(loc - x))
-	if dmp.MatchDistance == 0 {
-		// Dodge divide by zero error.
-		if proximity == 0 {
-			return accuracy
-		}
-
-		return 1.0
-	}
-	return accuracy + (proximity / float64(dmp.MatchDistance))
-}
-
-// MatchAlphabet initialises the alphabet for the Bitap algorithm.
-func (dmp *DiffMatchPatch) MatchAlphabet(pattern string) map[byte]int {
-	s := map[byte]int{}
-	charPattern := []byte(pattern)
-	for _, c := range charPattern {
-		_, ok := s[c]
-		if !ok {
-			s[c] = 0
-		}
-	}
-	i := 0
-
-	for _, c := range charPattern {
-		value := s[c] | int(uint(1)<<uint((len(pattern)-i-1)))
-		s[c] = value
-		i++
-	}
-	return s
-}
-
-//  PATCH FUNCTIONS
-
-// PatchAddContext increases the context until it is unique,
-// but doesn't let the pattern expand beyond MatchMaxBits.
-func (dmp *DiffMatchPatch) PatchAddContext(patch Patch, text string) Patch {
-	if len(text) == 0 {
-		return patch
-	}
-
-	pattern := text[patch.start2 : patch.start2+patch.length1]
-	padding := 0
-
-	// Look for the first and last matches of pattern in text.  If two
-	// different matches are found, increase the pattern length.
-	for strings.Index(text, pattern) != strings.LastIndex(text, pattern) &&
-		len(pattern) < dmp.MatchMaxBits-2*dmp.PatchMargin {
-		padding += dmp.PatchMargin
-		maxStart := max(0, patch.start2-padding)
-		minEnd := min(len(text), patch.start2+patch.length1+padding)
-		pattern = text[maxStart:minEnd]
-	}
-	// Add one chunk for good luck.
-	padding += dmp.PatchMargin
-
-	// Add the prefix.
-	prefix := text[max(0, patch.start2-padding):patch.start2]
-	if len(prefix) != 0 {
-		patch.diffs = append([]Diff{Diff{DiffEqual, prefix}}, patch.diffs...)
-	}
-	// Add the suffix.
-	suffix := text[patch.start2+patch.length1 : min(len(text), patch.start2+patch.length1+padding)]
-	if len(suffix) != 0 {
-		patch.diffs = append(patch.diffs, Diff{DiffEqual, suffix})
-	}
-
-	// Roll back the start points.
-	patch.start1 -= len(prefix)
-	patch.start2 -= len(prefix)
-	// Extend the lengths.
-	patch.length1 += len(prefix) + len(suffix)
-	patch.length2 += len(prefix) + len(suffix)
-
-	return patch
-}
-
-// PatchMake computes a list of patches.
-func (dmp *DiffMatchPatch) PatchMake(opt ...interface{}) []Patch {
-	if len(opt) == 1 {
-		diffs, _ := opt[0].([]Diff)
-		text1 := dmp.DiffText1(diffs)
-		return dmp.PatchMake(text1, diffs)
-	} else if len(opt) == 2 {
-		text1 := opt[0].(string)
-		switch t := opt[1].(type) {
-		case string:
-			diffs := dmp.DiffMain(text1, t, true)
-			if len(diffs) > 2 {
-				diffs = dmp.DiffCleanupSemantic(diffs)
-				diffs = dmp.DiffCleanupEfficiency(diffs)
-			}
-			return dmp.PatchMake(text1, diffs)
-		case []Diff:
-			return dmp.patchMake2(text1, t)
-		}
-	} else if len(opt) == 3 {
-		return dmp.PatchMake(opt[0], opt[2])
-	}
-	return []Patch{}
-}
-
-// patchMake2 computes a list of patches to turn text1 into text2.
-// text2 is not provided, diffs are the delta between text1 and text2.
-func (dmp *DiffMatchPatch) patchMake2(text1 string, diffs []Diff) []Patch {
-	// Check for null inputs not needed since null can't be passed in C#.
-	patches := []Patch{}
-	if len(diffs) == 0 {
-		return patches // Get rid of the null case.
-	}
-
-	patch := Patch{}
-	charCount1 := 0 // Number of characters into the text1 string.
-	charCount2 := 0 // Number of characters into the text2 string.
-	// Start with text1 (prepatchText) and apply the diffs until we arrive at
-	// text2 (postpatchText). We recreate the patches one by one to determine
-	// context info.
-	prepatchText := text1
-	postpatchText := text1
-
-	for i, aDiff := range diffs {
-		if len(patch.diffs) == 0 && aDiff.Type != DiffEqual {
-			// A new patch starts here.
-			patch.start1 = charCount1
-			patch.start2 = charCount2
-		}
-
-		switch aDiff.Type {
-		case DiffInsert:
-			patch.diffs = append(patch.diffs, aDiff)
-			patch.length2 += len(aDiff.Text)
-			postpatchText = postpatchText[:charCount2] +
-				aDiff.Text + postpatchText[charCount2:]
-		case DiffDelete:
-			patch.length1 += len(aDiff.Text)
-			patch.diffs = append(patch.diffs, aDiff)
-			postpatchText = postpatchText[:charCount2] + postpatchText[charCount2+len(aDiff.Text):]
-		case DiffEqual:
-			if len(aDiff.Text) <= 2*dmp.PatchMargin &&
-				len(patch.diffs) != 0 && i != len(diffs)-1 {
-				// Small equality inside a patch.
-				patch.diffs = append(patch.diffs, aDiff)
-				patch.length1 += len(aDiff.Text)
-				patch.length2 += len(aDiff.Text)
-			}
-			if len(aDiff.Text) >= 2*dmp.PatchMargin {
-				// Time for a new patch.
-				if len(patch.diffs) != 0 {
-					patch = dmp.PatchAddContext(patch, prepatchText)
-					patches = append(patches, patch)
-					patch = Patch{}
-					// Unlike Unidiff, our patch lists have a rolling context.
-					// http://code.google.com/p/google-diff-match-patch/wiki/Unidiff
-					// Update prepatch text & pos to reflect the application of the
-					// just completed patch.
-					prepatchText = postpatchText
-					charCount1 = charCount2
-				}
-			}
-		}
-
-		// Update the current character count.
-		if aDiff.Type != DiffInsert {
-			charCount1 += len(aDiff.Text)
-		}
-		if aDiff.Type != DiffDelete {
-			charCount2 += len(aDiff.Text)
-		}
-	}
-
-	// Pick up the leftover patch if not empty.
-	if len(patch.diffs) != 0 {
-		patch = dmp.PatchAddContext(patch, prepatchText)
-		patches = append(patches, patch)
-	}
-
-	return patches
-}
-
-// PatchDeepCopy returns an array that is identical to a
-// given an array of patches.
-func (dmp *DiffMatchPatch) PatchDeepCopy(patches []Patch) []Patch {
-	patchesCopy := []Patch{}
-	for _, aPatch := range patches {
-		patchCopy := Patch{}
-		for _, aDiff := range aPatch.diffs {
-			patchCopy.diffs = append(patchCopy.diffs, Diff{
-				aDiff.Type,
-				aDiff.Text,
-			})
-		}
-		patchCopy.start1 = aPatch.start1
-		patchCopy.start2 = aPatch.start2
-		patchCopy.length1 = aPatch.length1
-		patchCopy.length2 = aPatch.length2
-		patchesCopy = append(patchesCopy, patchCopy)
-	}
-	return patchesCopy
-}
-
-// PatchApply merges a set of patches onto the text.  Returns a patched text, as well
-// as an array of true/false values indicating which patches were applied.
-func (dmp *DiffMatchPatch) PatchApply(patches []Patch, text string) (string, []bool) {
-	if len(patches) == 0 {
-		return text, []bool{}
-	}
-
-	// Deep copy the patches so that no changes are made to originals.
-	patches = dmp.PatchDeepCopy(patches)
-
-	nullPadding := dmp.PatchAddPadding(patches)
-	text = nullPadding + text + nullPadding
-	patches = dmp.PatchSplitMax(patches)
-
-	x := 0
-	// delta keeps track of the offset between the expected and actual
-	// location of the previous patch.  If there are patches expected at
-	// positions 10 and 20, but the first patch was found at 12, delta is 2
-	// and the second patch has an effective expected position of 22.
-	delta := 0
-	results := make([]bool, len(patches))
-	for _, aPatch := range patches {
-		expectedLoc := aPatch.start2 + delta
-		text1 := dmp.DiffText1(aPatch.diffs)
-		var startLoc int
-		endLoc := -1
-		if len(text1) > dmp.MatchMaxBits {
-			// PatchSplitMax will only provide an oversized pattern
-			// in the case of a monster delete.
-			startLoc = dmp.MatchMain(text, text1[:dmp.MatchMaxBits], expectedLoc)
-			if startLoc != -1 {
-				endLoc = dmp.MatchMain(text,
-					text1[len(text1)-dmp.MatchMaxBits:], expectedLoc+len(text1)-dmp.MatchMaxBits)
-				if endLoc == -1 || startLoc >= endLoc {
-					// Can't find valid trailing context.  Drop this patch.
-					startLoc = -1
-				}
-			}
-		} else {
-			startLoc = dmp.MatchMain(text, text1, expectedLoc)
-		}
-		if startLoc == -1 {
-			// No match found.  :(
-			results[x] = false
-			// Subtract the delta for this failed patch from subsequent patches.
-			delta -= aPatch.length2 - aPatch.length1
-		} else {
-			// Found a match.  :)
-			results[x] = true
-			delta = startLoc - expectedLoc
-			var text2 string
-			if endLoc == -1 {
-				text2 = text[startLoc:int(math.Min(float64(startLoc+len(text1)), float64(len(text))))]
-			} else {
-				text2 = text[startLoc:int(math.Min(float64(endLoc+dmp.MatchMaxBits), float64(len(text))))]
-			}
-			if text1 == text2 {
-				// Perfect match, just shove the Replacement text in.
-				text = text[:startLoc] + dmp.DiffText2(aPatch.diffs) + text[startLoc+len(text1):]
-			} else {
-				// Imperfect match.  Run a diff to get a framework of equivalent
-				// indices.
-				diffs := dmp.DiffMain(text1, text2, false)
-				if len(text1) > dmp.MatchMaxBits && float64(dmp.DiffLevenshtein(diffs))/float64(len(text1)) > dmp.PatchDeleteThreshold {
-					// The end points match, but the content is unacceptably bad.
-					results[x] = false
-				} else {
-					diffs = dmp.DiffCleanupSemanticLossless(diffs)
-					index1 := 0
-					for _, aDiff := range aPatch.diffs {
-						if aDiff.Type != DiffEqual {
-							index2 := dmp.DiffXIndex(diffs, index1)
-							if aDiff.Type == DiffInsert {
-								// Insertion
-								text = text[:startLoc+index2] + aDiff.Text + text[startLoc+index2:]
-							} else if aDiff.Type == DiffDelete {
-								// Deletion
-								startIndex := startLoc + index2
-								text = text[:startIndex] +
-									text[startIndex+dmp.DiffXIndex(diffs, index1+len(aDiff.Text))-index2:]
-							}
-						}
-						if aDiff.Type != DiffDelete {
-							index1 += len(aDiff.Text)
-						}
-					}
-				}
-			}
-		}
-		x++
-	}
-	// Strip the padding off.
-	text = text[len(nullPadding) : len(nullPadding)+(len(text)-2*len(nullPadding))]
-	return text, results
-}
-
-// PatchAddPadding adds some padding on text start and end so that edges can match something.
-// Intended to be called only from within patchApply.
-func (dmp *DiffMatchPatch) PatchAddPadding(patches []Patch) string {
-	paddingLength := dmp.PatchMargin
-	nullPadding := ""
-	for x := 1; x <= paddingLength; x++ {
-		nullPadding += string(x)
-	}
-
-	// Bump all the patches forward.
-	for i := range patches {
-		patches[i].start1 += paddingLength
-		patches[i].start2 += paddingLength
-	}
-
-	// Add some padding on start of first diff.
-	if len(patches[0].diffs) == 0 || patches[0].diffs[0].Type != DiffEqual {
-		// Add nullPadding equality.
-		patches[0].diffs = append([]Diff{Diff{DiffEqual, nullPadding}}, patches[0].diffs...)
-		patches[0].start1 -= paddingLength // Should be 0.
-		patches[0].start2 -= paddingLength // Should be 0.
-		patches[0].length1 += paddingLength
-		patches[0].length2 += paddingLength
-	} else if paddingLength > len(patches[0].diffs[0].Text) {
-		// Grow first equality.
-		extraLength := paddingLength - len(patches[0].diffs[0].Text)
-		patches[0].diffs[0].Text = nullPadding[len(patches[0].diffs[0].Text):] + patches[0].diffs[0].Text
-		patches[0].start1 -= extraLength
-		patches[0].start2 -= extraLength
-		patches[0].length1 += extraLength
-		patches[0].length2 += extraLength
-	}
-
-	// Add some padding on end of last diff.
-	last := len(patches) - 1
-	if len(patches[last].diffs) == 0 || patches[last].diffs[len(patches[last].diffs)-1].Type != DiffEqual {
-		// Add nullPadding equality.
-		patches[last].diffs = append(patches[last].diffs, Diff{DiffEqual, nullPadding})
-		patches[last].length1 += paddingLength
-		patches[last].length2 += paddingLength
-	} else if paddingLength > len(patches[last].diffs[len(patches[last].diffs)-1].Text) {
-		// Grow last equality.
-		lastDiff := patches[last].diffs[len(patches[last].diffs)-1]
-		extraLength := paddingLength - len(lastDiff.Text)
-		patches[last].diffs[len(patches[last].diffs)-1].Text += nullPadding[:extraLength]
-		patches[last].length1 += extraLength
-		patches[last].length2 += extraLength
-	}
-
-	return nullPadding
-}
-
-// PatchSplitMax looks through the patches and breaks up any which are longer than the
-// maximum limit of the match algorithm.
-// Intended to be called only from within patchApply.
-func (dmp *DiffMatchPatch) PatchSplitMax(patches []Patch) []Patch {
-	patchSize := dmp.MatchMaxBits
-	for x := 0; x < len(patches); x++ {
-		if patches[x].length1 <= patchSize {
-			continue
-		}
-		bigpatch := patches[x]
-		// Remove the big old patch.
-		patches = append(patches[:x], patches[x+1:]...)
-		x--
-
-		start1 := bigpatch.start1
-		start2 := bigpatch.start2
-		precontext := ""
-		for len(bigpatch.diffs) != 0 {
-			// Create one of several smaller patches.
-			patch := Patch{}
-			empty := true
-			patch.start1 = start1 - len(precontext)
-			patch.start2 = start2 - len(precontext)
-			if len(precontext) != 0 {
-				patch.length1 = len(precontext)
-				patch.length2 = len(precontext)
-				patch.diffs = append(patch.diffs, Diff{DiffEqual, precontext})
-			}
-			for len(bigpatch.diffs) != 0 && patch.length1 < patchSize-dmp.PatchMargin {
-				diffType := bigpatch.diffs[0].Type
-				diffText := bigpatch.diffs[0].Text
-				if diffType == DiffInsert {
-					// Insertions are harmless.
-					patch.length2 += len(diffText)
-					start2 += len(diffText)
-					patch.diffs = append(patch.diffs, bigpatch.diffs[0])
-					bigpatch.diffs = bigpatch.diffs[1:]
-					empty = false
-				} else if diffType == DiffDelete && len(patch.diffs) == 1 && patch.diffs[0].Type == DiffEqual && len(diffText) > 2*patchSize {
-					// This is a large deletion.  Let it pass in one chunk.
-					patch.length1 += len(diffText)
-					start1 += len(diffText)
-					empty = false
-					patch.diffs = append(patch.diffs, Diff{diffType, diffText})
-					bigpatch.diffs = bigpatch.diffs[1:]
-				} else {
-					// Deletion or equality.  Only take as much as we can stomach.
-					diffText = diffText[:min(len(diffText), patchSize-patch.length1-dmp.PatchMargin)]
-
-					patch.length1 += len(diffText)
-					start1 += len(diffText)
-					if diffType == DiffEqual {
-						patch.length2 += len(diffText)
-						start2 += len(diffText)
-					} else {
-						empty = false
-					}
-					patch.diffs = append(patch.diffs, Diff{diffType, diffText})
-					if diffText == bigpatch.diffs[0].Text {
-						bigpatch.diffs = bigpatch.diffs[1:]
-					} else {
-						bigpatch.diffs[0].Text =
-							bigpatch.diffs[0].Text[len(diffText):]
-					}
-				}
-			}
-			// Compute the head context for the next patch.
-			precontext = dmp.DiffText2(patch.diffs)
-			precontext = precontext[max(0, len(precontext)-dmp.PatchMargin):]
-
-			postcontext := ""
-			// Append the end context for this patch.
-			if len(dmp.DiffText1(bigpatch.diffs)) > dmp.PatchMargin {
-				postcontext = dmp.DiffText1(bigpatch.diffs)[:dmp.PatchMargin]
-			} else {
-				postcontext = dmp.DiffText1(bigpatch.diffs)
-			}
-
-			if len(postcontext) != 0 {
-				patch.length1 += len(postcontext)
-				patch.length2 += len(postcontext)
-				if len(patch.diffs) != 0 && patch.diffs[len(patch.diffs)-1].Type == DiffEqual {
-					patch.diffs[len(patch.diffs)-1].Text += postcontext
-				} else {
-					patch.diffs = append(patch.diffs, Diff{DiffEqual, postcontext})
-				}
-			}
-			if !empty {
-				x++
-				patches = append(patches[:x], append([]Patch{patch}, patches[x:]...)...)
-			}
-		}
-	}
-	return patches
-}
-
-// PatchToText takes a list of patches and returns a textual representation.
-func (dmp *DiffMatchPatch) PatchToText(patches []Patch) string {
-	var text bytes.Buffer
-	for _, aPatch := range patches {
-		_, _ = text.WriteString(aPatch.String())
-	}
-	return text.String()
-}
-
-// PatchFromText parses a textual representation of patches and returns a List of Patch
-// objects.
-func (dmp *DiffMatchPatch) PatchFromText(textline string) ([]Patch, error) {
-	patches := []Patch{}
-	if len(textline) == 0 {
-		return patches, nil
-	}
-	text := strings.Split(textline, "\n")
-	textPointer := 0
-	patchHeader := regexp.MustCompile("^@@ -(\\d+),?(\\d*) \\+(\\d+),?(\\d*) @@$")
-
-	var patch Patch
-	var sign uint8
-	var line string
-	for textPointer < len(text) {
-
-		if !patchHeader.MatchString(text[textPointer]) {
-			return patches, errors.New("Invalid patch string: " + text[textPointer])
-		}
-
-		patch = Patch{}
-		m := patchHeader.FindStringSubmatch(text[textPointer])
-
-		patch.start1, _ = strconv.Atoi(m[1])
-		if len(m[2]) == 0 {
-			patch.start1--
-			patch.length1 = 1
-		} else if m[2] == "0" {
-			patch.length1 = 0
-		} else {
-			patch.start1--
-			patch.length1, _ = strconv.Atoi(m[2])
-		}
-
-		patch.start2, _ = strconv.Atoi(m[3])
-
-		if len(m[4]) == 0 {
-			patch.start2--
-			patch.length2 = 1
-		} else if m[4] == "0" {
-			patch.length2 = 0
-		} else {
-			patch.start2--
-			patch.length2, _ = strconv.Atoi(m[4])
-		}
-		textPointer++
-
-		for textPointer < len(text) {
-			if len(text[textPointer]) > 0 {
-				sign = text[textPointer][0]
-			} else {
-				textPointer++
-				continue
-			}
-
-			line = text[textPointer][1:]
-			line = strings.Replace(line, "+", "%2b", -1)
-			line, _ = url.QueryUnescape(line)
-			if sign == '-' {
-				// Deletion.
-				patch.diffs = append(patch.diffs, Diff{DiffDelete, line})
-			} else if sign == '+' {
-				// Insertion.
-				patch.diffs = append(patch.diffs, Diff{DiffInsert, line})
-			} else if sign == ' ' {
-				// Minor equality.
-				patch.diffs = append(patch.diffs, Diff{DiffEqual, line})
-			} else if sign == '@' {
-				// Start of next patch.
-				break
-			} else {
-				// WTF?
-				return patches, errors.New("Invalid patch mode '" + string(sign) + "' in: " + string(line))
-			}
-			textPointer++
-		}
-
-		patches = append(patches, patch)
-	}
-	return patches, nil
-}
diff --git a/diffmatchpatch/dmp_test.go b/diffmatchpatch/dmp_test.go
deleted file mode 100644
index 99883bc..0000000
--- a/diffmatchpatch/dmp_test.go
+++ /dev/null
@@ -1,1586 +0,0 @@
-package diffmatchpatch
-
-import (
-	"bytes"
-	"fmt"
-	"io/ioutil"
-	"runtime"
-	"strconv"
-	"strings"
-	"testing"
-	"time"
-	"unicode/utf8"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func caller() string {
-	if _, _, line, ok := runtime.Caller(2); ok {
-		return fmt.Sprintf("(actual-line %v) ", line)
-	}
-	return ""
-}
-
-func pretty(diffs []Diff) string {
-	var w bytes.Buffer
-	for i, diff := range diffs {
-		_, _ = w.WriteString(fmt.Sprintf("%v. ", i))
-		switch diff.Type {
-		case DiffInsert:
-			_, _ = w.WriteString("DiffIns")
-		case DiffDelete:
-			_, _ = w.WriteString("DiffDel")
-		case DiffEqual:
-			_, _ = w.WriteString("DiffEql")
-		default:
-			_, _ = w.WriteString("Unknown")
-		}
-		_, _ = w.WriteString(fmt.Sprintf(": %v\n", diff.Text))
-	}
-	return w.String()
-}
-
-func assertDiffEqual(t *testing.T, seq1, seq2 []Diff) {
-	if a, b := len(seq1), len(seq2); a != b {
-		t.Errorf("%v\nseq1:\n%v\nseq2:\n%v", caller(), pretty(seq1), pretty(seq2))
-		t.Errorf("%v Sequences of different length: %v != %v", caller(), a, b)
-		return
-	}
-
-	for i := range seq1 {
-		if a, b := seq1[i], seq2[i]; a != b {
-			t.Errorf("%v\nseq1:\n%v\nseq2:\n%v", caller(), pretty(seq1), pretty(seq2))
-			t.Errorf("%v %v != %v", caller(), a, b)
-			return
-		}
-	}
-}
-
-func assertStrEqual(t *testing.T, seq1, seq2 []string) {
-	if a, b := len(seq1), len(seq2); a != b {
-		t.Fatalf("%v Sequences of different length: %v != %v", caller(), a, b)
-	}
-
-	for i := range seq1 {
-		if a, b := seq1[i], seq2[i]; a != b {
-			t.Fatalf("%v %v != %v", caller(), a, b)
-		}
-	}
-}
-
-func diffRebuildtexts(diffs []Diff) []string {
-	text := []string{"", ""}
-	for _, myDiff := range diffs {
-		if myDiff.Type != DiffInsert {
-			text[0] += myDiff.Text
-		}
-		if myDiff.Type != DiffDelete {
-			text[1] += myDiff.Text
-		}
-	}
-	return text
-}
-
-func Test_diffCommonPrefix(t *testing.T) {
-	dmp := New()
-	// Detect any common suffix.
-	// Null case.
-	assert.Equal(t, 0, dmp.DiffCommonPrefix("abc", "xyz"), "'abc' and 'xyz' should not be equal")
-
-	// Non-null case.
-	assert.Equal(t, 4, dmp.DiffCommonPrefix("1234abcdef", "1234xyz"), "")
-
-	// Whole case.
-	assert.Equal(t, 4, dmp.DiffCommonPrefix("1234", "1234xyz"), "")
-}
-
-func Test_commonPrefixLength(t *testing.T) {
-	for _, test := range []struct {
-		s1, s2 string
-		want   int
-	}{
-		{"abc", "xyz", 0},
-		{"1234abcdef", "1234xyz", 4},
-		{"1234", "1234xyz", 4},
-	} {
-		assert.Equal(t, test.want, commonPrefixLength([]rune(test.s1), []rune(test.s2)),
-			fmt.Sprintf("%q, %q", test.s1, test.s2))
-	}
-}
-
-func Test_diffCommonSuffixTest(t *testing.T) {
-	dmp := New()
-	// Detect any common suffix.
-	// Null case.
-	assert.Equal(t, 0, dmp.DiffCommonSuffix("abc", "xyz"), "")
-
-	// Non-null case.
-	assert.Equal(t, 4, dmp.DiffCommonSuffix("abcdef1234", "xyz1234"), "")
-
-	// Whole case.
-	assert.Equal(t, 4, dmp.DiffCommonSuffix("1234", "xyz1234"), "")
-}
-
-func Test_commonSuffixLength(t *testing.T) {
-	for _, test := range []struct {
-		s1, s2 string
-		want   int
-	}{
-		{"abc", "xyz", 0},
-		{"abcdef1234", "xyz1234", 4},
-		{"1234", "xyz1234", 4},
-		{"123", "a3", 1},
-	} {
-		assert.Equal(t, test.want, commonSuffixLength([]rune(test.s1), []rune(test.s2)),
-			fmt.Sprintf("%q, %q", test.s1, test.s2))
-	}
-}
-
-func Test_runesIndexOf(t *testing.T) {
-	target := []rune("abcde")
-	for _, test := range []struct {
-		pattern string
-		start   int
-		want    int
-	}{
-		{"abc", 0, 0},
-		{"cde", 0, 2},
-		{"e", 0, 4},
-		{"cdef", 0, -1},
-		{"abcdef", 0, -1},
-		{"abc", 2, -1},
-		{"cde", 2, 2},
-		{"e", 2, 4},
-		{"cdef", 2, -1},
-		{"abcdef", 2, -1},
-		{"e", 6, -1},
-	} {
-		assert.Equal(t, test.want,
-			runesIndexOf(target, []rune(test.pattern), test.start),
-			fmt.Sprintf("%q, %d", test.pattern, test.start))
-	}
-}
-
-func Test_diffCommonOverlapTest(t *testing.T) {
-	dmp := New()
-	// Detect any suffix/prefix overlap.
-	// Null case.
-	assert.Equal(t, 0, dmp.DiffCommonOverlap("", "abcd"), "")
-
-	// Whole case.
-	assert.Equal(t, 3, dmp.DiffCommonOverlap("abc", "abcd"), "")
-
-	// No overlap.
-	assert.Equal(t, 0, dmp.DiffCommonOverlap("123456", "abcd"), "")
-
-	// Overlap.
-	assert.Equal(t, 3, dmp.DiffCommonOverlap("123456xxx", "xxxabcd"), "")
-
-	// Unicode.
-	// Some overly clever languages (C#) may treat ligatures as equal to their
-	// component letters.  E.g. U+FB01 == 'fi'
-	assert.Equal(t, 0, dmp.DiffCommonOverlap("fi", "\ufb01i"), "")
-}
-
-func Test_diffHalfmatchTest(t *testing.T) {
-	dmp := New()
-	dmp.DiffTimeout = 1
-	// No match.
-	assert.True(t, dmp.DiffHalfMatch("1234567890", "abcdef") == nil, "")
-	assert.True(t, dmp.DiffHalfMatch("12345", "23") == nil, "")
-
-	// Single Match.
-	assertStrEqual(t,
-		[]string{"12", "90", "a", "z", "345678"},
-		dmp.DiffHalfMatch("1234567890", "a345678z"))
-
-	assertStrEqual(t, []string{"a", "z", "12", "90", "345678"}, dmp.DiffHalfMatch("a345678z", "1234567890"))
-
-	assertStrEqual(t, []string{"abc", "z", "1234", "0", "56789"}, dmp.DiffHalfMatch("abc56789z", "1234567890"))
-
-	assertStrEqual(t, []string{"a", "xyz", "1", "7890", "23456"}, dmp.DiffHalfMatch("a23456xyz", "1234567890"))
-
-	// Multiple Matches.
-	assertStrEqual(t, []string{"12123", "123121", "a", "z", "1234123451234"}, dmp.DiffHalfMatch("121231234123451234123121", "a1234123451234z"))
-
-	assertStrEqual(t, []string{"", "-=-=-=-=-=", "x", "", "x-=-=-=-=-=-=-="}, dmp.DiffHalfMatch("x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-="))
-
-	assertStrEqual(t, []string{"-=-=-=-=-=", "", "", "y", "-=-=-=-=-=-=-=y"}, dmp.DiffHalfMatch("-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy"))
-
-	// Non-optimal halfmatch.
-	// Optimal diff would be -q+x=H-i+e=lloHe+Hu=llo-Hew+y not -qHillo+x=HelloHe-w+Hulloy
-	assertStrEqual(t, []string{"qHillo", "w", "x", "Hulloy", "HelloHe"}, dmp.DiffHalfMatch("qHilloHelloHew", "xHelloHeHulloy"))
-
-	// Optimal no halfmatch.
-	dmp.DiffTimeout = 0
-	assert.True(t, dmp.DiffHalfMatch("qHilloHelloHew", "xHelloHeHulloy") == nil, "")
-}
-
-func Test_diffBisectSplit(t *testing.T) {
-	// As originally written, this can produce invalid utf8 strings.
-	dmp := New()
-	diffs := dmp.diffBisectSplit([]rune("STUV\x05WX\x05YZ\x05["),
-		[]rune("WĺĻļ\x05YZ\x05ĽľĿŀZ"), 7, 6, time.Now().Add(time.Hour))
-	for _, d := range diffs {
-		assert.True(t, utf8.ValidString(d.Text))
-	}
-}
-
-func Test_diffLinesToChars(t *testing.T) {
-	dmp := New()
-	// Convert lines down to characters.
-	tmpVector := []string{"", "alpha\n", "beta\n"}
-
-	result0, result1, result2 := dmp.DiffLinesToChars("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n")
-	assert.Equal(t, "\u0001\u0002\u0001", result0, "")
-	assert.Equal(t, "\u0002\u0001\u0002", result1, "")
-	assertStrEqual(t, tmpVector, result2)
-
-	tmpVector = []string{"", "alpha\r\n", "beta\r\n", "\r\n"}
-	result0, result1, result2 = dmp.DiffLinesToChars("", "alpha\r\nbeta\r\n\r\n\r\n")
-	assert.Equal(t, "", result0, "")
-	assert.Equal(t, "\u0001\u0002\u0003\u0003", result1, "")
-	assertStrEqual(t, tmpVector, result2)
-
-	tmpVector = []string{"", "a", "b"}
-	result0, result1, result2 = dmp.DiffLinesToChars("a", "b")
-	assert.Equal(t, "\u0001", result0, "")
-	assert.Equal(t, "\u0002", result1, "")
-	assertStrEqual(t, tmpVector, result2)
-
-	// Omit final newline.
-	result0, result1, result2 = dmp.DiffLinesToChars("alpha\nbeta\nalpha", "")
-	assert.Equal(t, "\u0001\u0002\u0003", result0)
-	assert.Equal(t, "", result1)
-	assertStrEqual(t, []string{"", "alpha\n", "beta\n", "alpha"}, result2)
-
-	// More than 256 to reveal any 8-bit limitations.
-	n := 300
-	lineList := []string{}
-	charList := []rune{}
-
-	for x := 1; x < n+1; x++ {
-		lineList = append(lineList, strconv.Itoa(x)+"\n")
-		charList = append(charList, rune(x))
-	}
-
-	lines := strings.Join(lineList, "")
-	chars := string(charList)
-	assert.Equal(t, n, utf8.RuneCountInString(chars), "")
-
-	result0, result1, result2 = dmp.DiffLinesToChars(lines, "")
-
-	assert.Equal(t, chars, result0)
-	assert.Equal(t, "", result1, "")
-	// Account for the initial empty element of the lines array.
-	assertStrEqual(t, append([]string{""}, lineList...), result2)
-}
-
-func Test_diffCharsToLines(t *testing.T) {
-	dmp := New()
-	// Convert chars up to lines.
-	diffs := []Diff{
-		Diff{DiffEqual, "\u0001\u0002\u0001"},
-		Diff{DiffInsert, "\u0002\u0001\u0002"}}
-
-	tmpVector := []string{"", "alpha\n", "beta\n"}
-	actual := dmp.DiffCharsToLines(diffs, tmpVector)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "alpha\nbeta\nalpha\n"},
-		Diff{DiffInsert, "beta\nalpha\nbeta\n"}}, actual)
-
-	// More than 256 to reveal any 8-bit limitations.
-	n := 300
-	lineList := []string{}
-	charList := []rune{}
-
-	for x := 1; x <= n; x++ {
-		lineList = append(lineList, strconv.Itoa(x)+"\n")
-		charList = append(charList, rune(x))
-	}
-
-	assert.Equal(t, n, len(charList))
-
-	lineList = append([]string{""}, lineList...)
-	diffs = []Diff{Diff{DiffDelete, string(charList)}}
-	actual = dmp.DiffCharsToLines(diffs, lineList)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, strings.Join(lineList, "")}}, actual)
-}
-
-func Test_diffCleanupMerge(t *testing.T) {
-	dmp := New()
-	// Cleanup a messy diff.
-	// Null case.
-	diffs := []Diff{}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{}, diffs)
-
-	// No Diff case.
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "b"}, Diff{DiffInsert, "c"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "b"}, Diff{DiffInsert, "c"}}, diffs)
-
-	// Merge equalities.
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffEqual, "b"}, Diff{DiffEqual, "c"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "abc"}}, diffs)
-
-	// Merge deletions.
-	diffs = []Diff{Diff{DiffDelete, "a"}, Diff{DiffDelete, "b"}, Diff{DiffDelete, "c"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffDelete, "abc"}}, diffs)
-
-	// Merge insertions.
-	diffs = []Diff{Diff{DiffInsert, "a"}, Diff{DiffInsert, "b"}, Diff{DiffInsert, "c"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffInsert, "abc"}}, diffs)
-
-	// Merge interweave.
-	diffs = []Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "b"}, Diff{DiffDelete, "c"}, Diff{DiffInsert, "d"}, Diff{DiffEqual, "e"}, Diff{DiffEqual, "f"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffDelete, "ac"}, Diff{DiffInsert, "bd"}, Diff{DiffEqual, "ef"}}, diffs)
-
-	// Prefix and suffix detection.
-	diffs = []Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "abc"}, Diff{DiffDelete, "dc"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "d"}, Diff{DiffInsert, "b"}, Diff{DiffEqual, "c"}}, diffs)
-
-	// Prefix and suffix detection with equalities.
-	diffs = []Diff{Diff{DiffEqual, "x"}, Diff{DiffDelete, "a"}, Diff{DiffInsert, "abc"}, Diff{DiffDelete, "dc"}, Diff{DiffEqual, "y"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "xa"}, Diff{DiffDelete, "d"}, Diff{DiffInsert, "b"}, Diff{DiffEqual, "cy"}}, diffs)
-
-	// Same test as above but with unicode (\u0101 will appear in diffs with at least 257 unique lines)
-	diffs = []Diff{Diff{DiffEqual, "x"}, Diff{DiffDelete, "\u0101"}, Diff{DiffInsert, "\u0101bc"}, Diff{DiffDelete, "dc"}, Diff{DiffEqual, "y"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "x\u0101"}, Diff{DiffDelete, "d"}, Diff{DiffInsert, "b"}, Diff{DiffEqual, "cy"}}, diffs)
-
-	// Slide edit left.
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffInsert, "ba"}, Diff{DiffEqual, "c"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffInsert, "ab"}, Diff{DiffEqual, "ac"}}, diffs)
-
-	// Slide edit right.
-	diffs = []Diff{Diff{DiffEqual, "c"}, Diff{DiffInsert, "ab"}, Diff{DiffEqual, "a"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "ca"}, Diff{DiffInsert, "ba"}}, diffs)
-
-	// Slide edit left recursive.
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "b"}, Diff{DiffEqual, "c"}, Diff{DiffDelete, "ac"}, Diff{DiffEqual, "x"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffDelete, "abc"}, Diff{DiffEqual, "acx"}}, diffs)
-
-	// Slide edit right recursive.
-	diffs = []Diff{Diff{DiffEqual, "x"}, Diff{DiffDelete, "ca"}, Diff{DiffEqual, "c"}, Diff{DiffDelete, "b"}, Diff{DiffEqual, "a"}}
-	diffs = dmp.DiffCleanupMerge(diffs)
-	assertDiffEqual(t, []Diff{Diff{DiffEqual, "xca"}, Diff{DiffDelete, "cba"}}, diffs)
-}
-
-func Test_diffCleanupSemanticLossless(t *testing.T) {
-	dmp := New()
-	// Slide diffs to match logical boundaries.
-	// Null case.
-	diffs := []Diff{}
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-	assertDiffEqual(t, []Diff{}, diffs)
-
-	// Blank lines.
-	diffs = []Diff{
-		Diff{DiffEqual, "AAA\r\n\r\nBBB"},
-		Diff{DiffInsert, "\r\nDDD\r\n\r\nBBB"},
-		Diff{DiffEqual, "\r\nEEE"},
-	}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "AAA\r\n\r\n"},
-		Diff{DiffInsert, "BBB\r\nDDD\r\n\r\n"},
-		Diff{DiffEqual, "BBB\r\nEEE"}}, diffs)
-
-	// Line boundaries.
-	diffs = []Diff{
-		Diff{DiffEqual, "AAA\r\nBBB"},
-		Diff{DiffInsert, " DDD\r\nBBB"},
-		Diff{DiffEqual, " EEE"}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "AAA\r\n"},
-		Diff{DiffInsert, "BBB DDD\r\n"},
-		Diff{DiffEqual, "BBB EEE"}}, diffs)
-
-	// Word boundaries.
-	diffs = []Diff{
-		Diff{DiffEqual, "The c"},
-		Diff{DiffInsert, "ow and the c"},
-		Diff{DiffEqual, "at."}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "The "},
-		Diff{DiffInsert, "cow and the "},
-		Diff{DiffEqual, "cat."}}, diffs)
-
-	// Alphanumeric boundaries.
-	diffs = []Diff{
-		Diff{DiffEqual, "The-c"},
-		Diff{DiffInsert, "ow-and-the-c"},
-		Diff{DiffEqual, "at."}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "The-"},
-		Diff{DiffInsert, "cow-and-the-"},
-		Diff{DiffEqual, "cat."}}, diffs)
-
-	// Hitting the start.
-	diffs = []Diff{
-		Diff{DiffEqual, "a"},
-		Diff{DiffDelete, "a"},
-		Diff{DiffEqual, "ax"}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "a"},
-		Diff{DiffEqual, "aax"}}, diffs)
-
-	// Hitting the end.
-	diffs = []Diff{
-		Diff{DiffEqual, "xa"},
-		Diff{DiffDelete, "a"},
-		Diff{DiffEqual, "a"}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "xaa"},
-		Diff{DiffDelete, "a"}}, diffs)
-
-	// Sentence boundaries.
-	diffs = []Diff{
-		Diff{DiffEqual, "The xxx. The "},
-		Diff{DiffInsert, "zzz. The "},
-		Diff{DiffEqual, "yyy."}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "The xxx."},
-		Diff{DiffInsert, " The zzz."},
-		Diff{DiffEqual, " The yyy."}}, diffs)
-
-	// UTF-8 strings.
-	diffs = []Diff{
-		Diff{DiffEqual, "The ♕. The "},
-		Diff{DiffInsert, "â™”. The "},
-		Diff{DiffEqual, "â™–."}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "The ♕."},
-		Diff{DiffInsert, " The â™”."},
-		Diff{DiffEqual, " The â™–."}}, diffs)
-
-	// Rune boundaries.
-	diffs = []Diff{
-		Diff{DiffEqual, "♕♕"},
-		Diff{DiffInsert, "♔♔"},
-		Diff{DiffEqual, "â™–â™–"}}
-
-	diffs = dmp.DiffCleanupSemanticLossless(diffs)
-
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "♕♕"},
-		Diff{DiffInsert, "♔♔"},
-		Diff{DiffEqual, "â™–â™–"}}, diffs)
-}
-
-func Test_diffCleanupSemantic(t *testing.T) {
-	dmp := New()
-	// Cleanup semantically trivial equalities.
-	// Null case.
-	diffs := []Diff{}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{}, diffs)
-
-	// No elimination #1.
-	diffs = []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "cd"},
-		Diff{DiffEqual, "12"},
-		Diff{DiffDelete, "e"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "cd"},
-		Diff{DiffEqual, "12"},
-		Diff{DiffDelete, "e"}}, diffs)
-
-	// No elimination #2.
-	diffs = []Diff{
-		Diff{DiffDelete, "abc"},
-		Diff{DiffInsert, "ABC"},
-		Diff{DiffEqual, "1234"},
-		Diff{DiffDelete, "wxyz"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abc"},
-		Diff{DiffInsert, "ABC"},
-		Diff{DiffEqual, "1234"},
-		Diff{DiffDelete, "wxyz"}}, diffs)
-
-	// No elimination #3.
-	diffs = []Diff{
-		Diff{DiffEqual, "2016-09-01T03:07:1"},
-		Diff{DiffInsert, "5.15"},
-		Diff{DiffEqual, "4"},
-		Diff{DiffDelete, "."},
-		Diff{DiffEqual, "80"},
-		Diff{DiffInsert, "0"},
-		Diff{DiffEqual, "78"},
-		Diff{DiffDelete, "3074"},
-		Diff{DiffEqual, "1Z"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "2016-09-01T03:07:1"},
-		Diff{DiffInsert, "5.15"},
-		Diff{DiffEqual, "4"},
-		Diff{DiffDelete, "."},
-		Diff{DiffEqual, "80"},
-		Diff{DiffInsert, "0"},
-		Diff{DiffEqual, "78"},
-		Diff{DiffDelete, "3074"},
-		Diff{DiffEqual, "1Z"}}, diffs)
-
-	// Simple elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "a"},
-		Diff{DiffEqual, "b"},
-		Diff{DiffDelete, "c"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abc"},
-		Diff{DiffInsert, "b"}}, diffs)
-
-	// Backpass elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffEqual, "cd"},
-		Diff{DiffDelete, "e"},
-		Diff{DiffEqual, "f"},
-		Diff{DiffInsert, "g"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abcdef"},
-		Diff{DiffInsert, "cdfg"}}, diffs)
-
-	// Multiple eliminations.
-	diffs = []Diff{
-		Diff{DiffInsert, "1"},
-		Diff{DiffEqual, "A"},
-		Diff{DiffDelete, "B"},
-		Diff{DiffInsert, "2"},
-		Diff{DiffEqual, "_"},
-		Diff{DiffInsert, "1"},
-		Diff{DiffEqual, "A"},
-		Diff{DiffDelete, "B"},
-		Diff{DiffInsert, "2"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "AB_AB"},
-		Diff{DiffInsert, "1A2_1A2"}}, diffs)
-
-	// Word boundaries.
-	diffs = []Diff{
-		Diff{DiffEqual, "The c"},
-		Diff{DiffDelete, "ow and the c"},
-		Diff{DiffEqual, "at."}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "The "},
-		Diff{DiffDelete, "cow and the "},
-		Diff{DiffEqual, "cat."}}, diffs)
-
-	// No overlap elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "abcxx"},
-		Diff{DiffInsert, "xxdef"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abcxx"},
-		Diff{DiffInsert, "xxdef"}}, diffs)
-
-	// Overlap elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "abcxxx"},
-		Diff{DiffInsert, "xxxdef"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abc"},
-		Diff{DiffEqual, "xxx"},
-		Diff{DiffInsert, "def"}}, diffs)
-
-	// Reverse overlap elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "xxxabc"},
-		Diff{DiffInsert, "defxxx"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffInsert, "def"},
-		Diff{DiffEqual, "xxx"},
-		Diff{DiffDelete, "abc"}}, diffs)
-
-	// Two overlap eliminations.
-	diffs = []Diff{
-		Diff{DiffDelete, "abcd1212"},
-		Diff{DiffInsert, "1212efghi"},
-		Diff{DiffEqual, "----"},
-		Diff{DiffDelete, "A3"},
-		Diff{DiffInsert, "3BC"}}
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abcd"},
-		Diff{DiffEqual, "1212"},
-		Diff{DiffInsert, "efghi"},
-		Diff{DiffEqual, "----"},
-		Diff{DiffDelete, "A"},
-		Diff{DiffEqual, "3"},
-		Diff{DiffInsert, "BC"}}, diffs)
-
-	// Test case for adapting DiffCleanupSemantic to be equal to the Python version #19
-	diffs = dmp.DiffMain("James McCarthy close to signing new Everton deal", "James McCarthy signs new five-year deal at Everton", false)
-	diffs = dmp.DiffCleanupSemantic(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffEqual, "James McCarthy "},
-		Diff{DiffDelete, "close to "},
-		Diff{DiffEqual, "sign"},
-		Diff{DiffDelete, "ing"},
-		Diff{DiffInsert, "s"},
-		Diff{DiffEqual, " new "},
-		Diff{DiffInsert, "five-year deal at "},
-		Diff{DiffEqual, "Everton"},
-		Diff{DiffDelete, " deal"},
-	}, diffs)
-}
-
-func Test_diffCleanupEfficiency(t *testing.T) {
-	dmp := New()
-	// Cleanup operationally trivial equalities.
-	dmp.DiffEditCost = 4
-	// Null case.
-	diffs := []Diff{}
-	diffs = dmp.DiffCleanupEfficiency(diffs)
-	assertDiffEqual(t, []Diff{}, diffs)
-
-	// No elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "12"},
-		Diff{DiffEqual, "wxyz"},
-		Diff{DiffDelete, "cd"},
-		Diff{DiffInsert, "34"}}
-	diffs = dmp.DiffCleanupEfficiency(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "12"},
-		Diff{DiffEqual, "wxyz"},
-		Diff{DiffDelete, "cd"},
-		Diff{DiffInsert, "34"}}, diffs)
-
-	// Four-edit elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "12"},
-		Diff{DiffEqual, "xyz"},
-		Diff{DiffDelete, "cd"},
-		Diff{DiffInsert, "34"}}
-	diffs = dmp.DiffCleanupEfficiency(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abxyzcd"},
-		Diff{DiffInsert, "12xyz34"}}, diffs)
-
-	// Three-edit elimination.
-	diffs = []Diff{
-		Diff{DiffInsert, "12"},
-		Diff{DiffEqual, "x"},
-		Diff{DiffDelete, "cd"},
-		Diff{DiffInsert, "34"}}
-	diffs = dmp.DiffCleanupEfficiency(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "xcd"},
-		Diff{DiffInsert, "12x34"}}, diffs)
-
-	// Backpass elimination.
-	diffs = []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "12"},
-		Diff{DiffEqual, "xy"},
-		Diff{DiffInsert, "34"},
-		Diff{DiffEqual, "z"},
-		Diff{DiffDelete, "cd"},
-		Diff{DiffInsert, "56"}}
-	diffs = dmp.DiffCleanupEfficiency(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abxyzcd"},
-		Diff{DiffInsert, "12xy34z56"}}, diffs)
-
-	// High cost elimination.
-	dmp.DiffEditCost = 5
-	diffs = []Diff{
-		Diff{DiffDelete, "ab"},
-		Diff{DiffInsert, "12"},
-		Diff{DiffEqual, "wxyz"},
-		Diff{DiffDelete, "cd"},
-		Diff{DiffInsert, "34"}}
-	diffs = dmp.DiffCleanupEfficiency(diffs)
-	assertDiffEqual(t, []Diff{
-		Diff{DiffDelete, "abwxyzcd"},
-		Diff{DiffInsert, "12wxyz34"}}, diffs)
-	dmp.DiffEditCost = 4
-}
-
-func Test_diffPrettyHtml(t *testing.T) {
-	dmp := New()
-	// Pretty print.
-	diffs := []Diff{
-		Diff{DiffEqual, "a\n"},
-		Diff{DiffDelete, "<B>b</B>"},
-		Diff{DiffInsert, "c&d"}}
-	assert.Equal(t, "<span>a&para;<br></span><del style=\"background:#ffe6e6;\">&lt;B&gt;b&lt;/B&gt;</del><ins style=\"background:#e6ffe6;\">c&amp;d</ins>",
-		dmp.DiffPrettyHtml(diffs))
-}
-
-func Test_diffPrettyText(t *testing.T) {
-	dmp := New()
-	// Pretty print.
-	diffs := []Diff{
-		Diff{DiffEqual, "a\n"},
-		Diff{DiffDelete, "<B>b</B>"},
-		Diff{DiffInsert, "c&d"}}
-	assert.Equal(t, "a\n\x1b[31m<B>b</B>\x1b[0m\x1b[32mc&d\x1b[0m",
-		dmp.DiffPrettyText(diffs))
-}
-
-func Test_diffText(t *testing.T) {
-	dmp := New()
-	// Compute the source and destination texts.
-	diffs := []Diff{
-		Diff{DiffEqual, "jump"},
-		Diff{DiffDelete, "s"},
-		Diff{DiffInsert, "ed"},
-		Diff{DiffEqual, " over "},
-		Diff{DiffDelete, "the"},
-		Diff{DiffInsert, "a"},
-		Diff{DiffEqual, " lazy"}}
-	assert.Equal(t, "jumps over the lazy", dmp.DiffText1(diffs))
-	assert.Equal(t, "jumped over a lazy", dmp.DiffText2(diffs))
-}
-
-func Test_diffDelta(t *testing.T) {
-	dmp := New()
-	// Convert a diff into delta string.
-	diffs := []Diff{
-		Diff{DiffEqual, "jump"},
-		Diff{DiffDelete, "s"},
-		Diff{DiffInsert, "ed"},
-		Diff{DiffEqual, " over "},
-		Diff{DiffDelete, "the"},
-		Diff{DiffInsert, "a"},
-		Diff{DiffEqual, " lazy"},
-		Diff{DiffInsert, "old dog"}}
-
-	text1 := dmp.DiffText1(diffs)
-	assert.Equal(t, "jumps over the lazy", text1)
-
-	delta := dmp.DiffToDelta(diffs)
-	assert.Equal(t, "=4\t-1\t+ed\t=6\t-3\t+a\t=5\t+old dog", delta)
-
-	// Convert delta string into a diff.
-	_seq1, err := dmp.DiffFromDelta(text1, delta)
-	assertDiffEqual(t, diffs, _seq1)
-
-	// Generates error (19 < 20).
-	_, err = dmp.DiffFromDelta(text1+"x", delta)
-	if err == nil {
-		t.Fatal("diff_fromDelta: Too long.")
-	}
-
-	// Generates error (19 > 18).
-	_, err = dmp.DiffFromDelta(text1[1:], delta)
-	if err == nil {
-		t.Fatal("diff_fromDelta: Too short.")
-	}
-
-	// Generates error (%xy invalid URL escape).
-	_, err = dmp.DiffFromDelta("", "+%c3%xy")
-	if err == nil {
-		assert.Fail(t, "diff_fromDelta: expected Invalid URL escape.")
-	}
-
-	// Generates error (invalid utf8).
-	_, err = dmp.DiffFromDelta("", "+%c3xy")
-	if err == nil {
-		assert.Fail(t, "diff_fromDelta: expected Invalid utf8.")
-	}
-
-	// Test deltas with special characters.
-	diffs = []Diff{
-		Diff{DiffEqual, "\u0680 \x00 \t %"},
-		Diff{DiffDelete, "\u0681 \x01 \n ^"},
-		Diff{DiffInsert, "\u0682 \x02 \\ |"}}
-	text1 = dmp.DiffText1(diffs)
-	assert.Equal(t, "\u0680 \x00 \t %\u0681 \x01 \n ^", text1)
-
-	delta = dmp.DiffToDelta(diffs)
-	// Lowercase, due to UrlEncode uses lower.
-	assert.Equal(t, "=7\t-7\t+%DA%82 %02 %5C %7C", delta)
-
-	_res1, err := dmp.DiffFromDelta(text1, delta)
-	if err != nil {
-		t.Fatal(err)
-	}
-	assertDiffEqual(t, diffs, _res1)
-
-	// Verify pool of unchanged characters.
-	diffs = []Diff{
-		Diff{DiffInsert, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # "}}
-	text2 := dmp.DiffText2(diffs)
-	assert.Equal(t, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ", text2, "diff_text2: Unchanged characters.")
-
-	delta = dmp.DiffToDelta(diffs)
-	assert.Equal(t, "+A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ", delta, "diff_toDelta: Unchanged characters.")
-
-	// Convert delta string into a diff.
-	_res2, _ := dmp.DiffFromDelta("", delta)
-	assertDiffEqual(t, diffs, _res2)
-}
-
-func Test_diffXIndex(t *testing.T) {
-	dmp := New()
-	// Translate a location in text1 to text2.
-	diffs := []Diff{
-		Diff{DiffDelete, "a"},
-		Diff{DiffInsert, "1234"},
-		Diff{DiffEqual, "xyz"}}
-	assert.Equal(t, 5, dmp.DiffXIndex(diffs, 2), "diff_xIndex: Translation on equality.")
-
-	diffs = []Diff{
-		Diff{DiffEqual, "a"},
-		Diff{DiffDelete, "1234"},
-		Diff{DiffEqual, "xyz"}}
-	assert.Equal(t, 1, dmp.DiffXIndex(diffs, 3), "diff_xIndex: Translation on deletion.")
-}
-
-func Test_diffLevenshtein(t *testing.T) {
-	dmp := New()
-	diffs := []Diff{
-		Diff{DiffDelete, "abc"},
-		Diff{DiffInsert, "1234"},
-		Diff{DiffEqual, "xyz"}}
-	assert.Equal(t, 4, dmp.DiffLevenshtein(diffs), "diff_levenshtein: Levenshtein with trailing equality.")
-
-	diffs = []Diff{
-		Diff{DiffEqual, "xyz"},
-		Diff{DiffDelete, "abc"},
-		Diff{DiffInsert, "1234"}}
-	assert.Equal(t, 4, dmp.DiffLevenshtein(diffs), "diff_levenshtein: Levenshtein with leading equality.")
-
-	diffs = []Diff{
-		Diff{DiffDelete, "abc"},
-		Diff{DiffEqual, "xyz"},
-		Diff{DiffInsert, "1234"}}
-	assert.Equal(t, 7, dmp.DiffLevenshtein(diffs), "diff_levenshtein: Levenshtein with middle equality.")
-}
-
-func Test_diffBisect(t *testing.T) {
-	dmp := New()
-	// Normal.
-	a := "cat"
-	b := "map"
-	// Since the resulting diff hasn't been normalized, it would be ok if
-	// the insertion and deletion pairs are swapped.
-	// If the order changes, tweak this test as required.
-	correctDiffs := []Diff{
-		Diff{DiffDelete, "c"},
-		Diff{DiffInsert, "m"},
-		Diff{DiffEqual, "a"},
-		Diff{DiffDelete, "t"},
-		Diff{DiffInsert, "p"}}
-
-	assertDiffEqual(t, correctDiffs, dmp.DiffBisect(a, b, time.Date(9999, time.December, 31, 23, 59, 59, 59, time.UTC)))
-
-	// Timeout.
-	diffs := []Diff{Diff{DiffDelete, "cat"}, Diff{DiffInsert, "map"}}
-	assertDiffEqual(t, diffs, dmp.DiffBisect(a, b, time.Now().Add(time.Nanosecond)))
-
-	// Negative deadlines count as having infinite time.
-	assertDiffEqual(t, correctDiffs, dmp.DiffBisect(a, b, time.Date(0001, time.January, 01, 00, 00, 00, 00, time.UTC)))
-}
-
-func Test_diffMain(t *testing.T) {
-	dmp := New()
-	// Perform a trivial diff.
-	diffs := []Diff{}
-	assertDiffEqual(t, diffs, dmp.DiffMain("", "", false))
-
-	diffs = []Diff{Diff{DiffEqual, "abc"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("abc", "abc", false))
-
-	diffs = []Diff{Diff{DiffEqual, "ab"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "c"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("abc", "ab123c", false))
-
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "bc"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("a123bc", "abc", false))
-
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "b"}, Diff{DiffInsert, "456"}, Diff{DiffEqual, "c"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("abc", "a123b456c", false))
-
-	diffs = []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "b"}, Diff{DiffDelete, "456"}, Diff{DiffEqual, "c"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("a123b456c", "abc", false))
-
-	// Perform a real diff.
-	// Switch off the timeout.
-	dmp.DiffTimeout = 0
-	diffs = []Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "b"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("a", "b", false))
-
-	diffs = []Diff{
-		Diff{DiffDelete, "Apple"},
-		Diff{DiffInsert, "Banana"},
-		Diff{DiffEqual, "s are a"},
-		Diff{DiffInsert, "lso"},
-		Diff{DiffEqual, " fruit."}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("Apples are a fruit.", "Bananas are also fruit.", false))
-
-	diffs = []Diff{
-		Diff{DiffDelete, "a"},
-		Diff{DiffInsert, "\u0680"},
-		Diff{DiffEqual, "x"},
-		Diff{DiffDelete, "\t"},
-		Diff{DiffInsert, "\u0000"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("ax\t", "\u0680x\u0000", false))
-
-	diffs = []Diff{
-		Diff{DiffDelete, "1"},
-		Diff{DiffEqual, "a"},
-		Diff{DiffDelete, "y"},
-		Diff{DiffEqual, "b"},
-		Diff{DiffDelete, "2"},
-		Diff{DiffInsert, "xab"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("1ayb2", "abxab", false))
-
-	diffs = []Diff{
-		Diff{DiffInsert, "xaxcx"},
-		Diff{DiffEqual, "abc"}, Diff{DiffDelete, "y"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("abcy", "xaxcxabc", false))
-
-	diffs = []Diff{
-		Diff{DiffDelete, "ABCD"},
-		Diff{DiffEqual, "a"},
-		Diff{DiffDelete, "="},
-		Diff{DiffInsert, "-"},
-		Diff{DiffEqual, "bcd"},
-		Diff{DiffDelete, "="},
-		Diff{DiffInsert, "-"},
-		Diff{DiffEqual, "efghijklmnopqrs"},
-		Diff{DiffDelete, "EFGHIJKLMNOefg"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg", "a-bcd-efghijklmnopqrs", false))
-
-	diffs = []Diff{
-		Diff{DiffInsert, " "},
-		Diff{DiffEqual, "a"},
-		Diff{DiffInsert, "nd"},
-		Diff{DiffEqual, " [[Pennsylvania]]"},
-		Diff{DiffDelete, " and [[New"}}
-	assertDiffEqual(t, diffs, dmp.DiffMain("a [[Pennsylvania]] and [[New", " and [[Pennsylvania]]", false))
-
-	dmp.DiffTimeout = 200 * time.Millisecond
-	a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
-	b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
-	// Increase the text lengths by 1024 times to ensure a timeout.
-	for x := 0; x < 13; x++ {
-		a = a + a
-		b = b + b
-	}
-
-	startTime := time.Now()
-	dmp.DiffMain(a, b, true)
-	endTime := time.Now()
-	delta := endTime.Sub(startTime)
-	// Test that we took at least the timeout period.
-	assert.True(t, delta >= dmp.DiffTimeout, fmt.Sprintf("%v !>= %v", delta, dmp.DiffTimeout))
-	// Test that we didn't take forever (be very forgiving).
-	// Theoretically this test could fail very occasionally if the
-	// OS task swaps or locks up for a second at the wrong moment.
-	assert.True(t, delta < (dmp.DiffTimeout*100), fmt.Sprintf("%v !< %v", delta, dmp.DiffTimeout*100))
-	dmp.DiffTimeout = 0
-
-	// Test the linemode speedup.
-	// Must be long to pass the 100 char cutoff.
-	a = "1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n"
-	b = "abcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\n"
-	assertDiffEqual(t, dmp.DiffMain(a, b, true), dmp.DiffMain(a, b, false))
-
-	a = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
-	b = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
-	assertDiffEqual(t, dmp.DiffMain(a, b, true), dmp.DiffMain(a, b, false))
-
-	a = "1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n"
-	b = "abcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n"
-	textsLinemode := diffRebuildtexts(dmp.DiffMain(a, b, true))
-	textsTextmode := diffRebuildtexts(dmp.DiffMain(a, b, false))
-	assertStrEqual(t, textsTextmode, textsLinemode)
-
-	// Test null inputs -- not needed because nulls can't be passed in Go.
-}
-
-func Test_match_alphabet(t *testing.T) {
-	dmp := New()
-
-	bitmask := map[byte]int{
-		'a': 4,
-		'b': 2,
-		'c': 1,
-	}
-	assert.Equal(t, bitmask, dmp.MatchAlphabet("abc"))
-
-	bitmask = map[byte]int{
-		'a': 37,
-		'b': 18,
-		'c': 8,
-	}
-	assert.Equal(t, bitmask, dmp.MatchAlphabet("abcaba"))
-}
-
-func Test_match_bitap(t *testing.T) {
-	dmp := New()
-
-	// Bitap algorithm.
-	dmp.MatchDistance = 100
-	dmp.MatchThreshold = 0.5
-	assert.Equal(t, 5, dmp.MatchBitap("abcdefghijk", "fgh", 5), "match_bitap: Exact match #1.")
-
-	assert.Equal(t, 5, dmp.MatchBitap("abcdefghijk", "fgh", 0), "match_bitap: Exact match #2.")
-
-	assert.Equal(t, 4, dmp.MatchBitap("abcdefghijk", "efxhi", 0), "match_bitap: Fuzzy match #1.")
-
-	assert.Equal(t, 2, dmp.MatchBitap("abcdefghijk", "cdefxyhijk", 5), "match_bitap: Fuzzy match #2.")
-
-	assert.Equal(t, -1, dmp.MatchBitap("abcdefghijk", "bxy", 1), "match_bitap: Fuzzy match #3.")
-
-	assert.Equal(t, 2, dmp.MatchBitap("123456789xx0", "3456789x0", 2), "match_bitap: Overflow.")
-
-	assert.Equal(t, 0, dmp.MatchBitap("abcdef", "xxabc", 4), "match_bitap: Before start match.")
-
-	assert.Equal(t, 3, dmp.MatchBitap("abcdef", "defyy", 4), "match_bitap: Beyond end match.")
-
-	assert.Equal(t, 0, dmp.MatchBitap("abcdef", "xabcdefy", 0), "match_bitap: Oversized pattern.")
-
-	dmp.MatchThreshold = 0.4
-	assert.Equal(t, 4, dmp.MatchBitap("abcdefghijk", "efxyhi", 1), "match_bitap: Threshold #1.")
-
-	dmp.MatchThreshold = 0.3
-	assert.Equal(t, -1, dmp.MatchBitap("abcdefghijk", "efxyhi", 1), "match_bitap: Threshold #2.")
-
-	dmp.MatchThreshold = 0.0
-	assert.Equal(t, 1, dmp.MatchBitap("abcdefghijk", "bcdef", 1), "match_bitap: Threshold #3.")
-
-	dmp.MatchThreshold = 0.5
-	assert.Equal(t, 0, dmp.MatchBitap("abcdexyzabcde", "abccde", 3), "match_bitap: Multiple select #1.")
-
-	assert.Equal(t, 8, dmp.MatchBitap("abcdexyzabcde", "abccde", 5), "match_bitap: Multiple select #2.")
-
-	dmp.MatchDistance = 10 // Strict location.
-	assert.Equal(t, -1, dmp.MatchBitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24), "match_bitap: Distance test #1.")
-
-	assert.Equal(t, 0, dmp.MatchBitap("abcdefghijklmnopqrstuvwxyz", "abcdxxefg", 1), "match_bitap: Distance test #2.")
-
-	dmp.MatchDistance = 1000 // Loose location.
-	assert.Equal(t, 0, dmp.MatchBitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24), "match_bitap: Distance test #3.")
-}
-
-func Test_MatchMain(t *testing.T) {
-	dmp := New()
-	// Full match.
-	assert.Equal(t, 0, dmp.MatchMain("abcdef", "abcdef", 1000), "MatchMain: Equality.")
-
-	assert.Equal(t, -1, dmp.MatchMain("", "abcdef", 1), "MatchMain: Null text.")
-
-	assert.Equal(t, 3, dmp.MatchMain("abcdef", "", 3), "MatchMain: Null pattern.")
-
-	assert.Equal(t, 3, dmp.MatchMain("abcdef", "de", 3), "MatchMain: Exact match.")
-
-	assert.Equal(t, 3, dmp.MatchMain("abcdef", "defy", 4), "MatchMain: Beyond end match.")
-
-	assert.Equal(t, 0, dmp.MatchMain("abcdef", "abcdefy", 0), "MatchMain: Oversized pattern.")
-
-	dmp.MatchThreshold = 0.7
-	assert.Equal(t, 4, dmp.MatchMain("I am the very model of a modern major general.", " that berry ", 5), "MatchMain: Complex match.")
-	dmp.MatchThreshold = 0.5
-
-	// Test null inputs -- not needed because nulls can't be passed in C#.
-}
-
-func Test_patch_patchObj(t *testing.T) {
-	// Patch Object.
-	p := Patch{}
-	p.start1 = 20
-	p.start2 = 21
-	p.length1 = 18
-	p.length2 = 17
-	p.diffs = []Diff{
-		Diff{DiffEqual, "jump"},
-		Diff{DiffDelete, "s"},
-		Diff{DiffInsert, "ed"},
-		Diff{DiffEqual, " over "},
-		Diff{DiffDelete, "the"},
-		Diff{DiffInsert, "a"},
-		Diff{DiffEqual, "\nlaz"}}
-	strp := "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n %0Alaz\n"
-
-	assert.Equal(t, strp, p.String(), "Patch: toString.")
-}
-
-func Test_patch_fromText(t *testing.T) {
-	dmp := New()
-
-	_v1, _ := dmp.PatchFromText("")
-	assert.True(t, len(_v1) == 0, "patch_fromText: #0.")
-	strp := "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n %0Alaz\n"
-	_v2, _ := dmp.PatchFromText(strp)
-	assert.Equal(t, strp, _v2[0].String(), "patch_fromText: #1.")
-
-	_v3, _ := dmp.PatchFromText("@@ -1 +1 @@\n-a\n+b\n")
-	assert.Equal(t, "@@ -1 +1 @@\n-a\n+b\n", _v3[0].String(), "patch_fromText: #2.")
-
-	_v4, _ := dmp.PatchFromText("@@ -1,3 +0,0 @@\n-abc\n")
-	assert.Equal(t, "@@ -1,3 +0,0 @@\n-abc\n", _v4[0].String(), "patch_fromText: #3.")
-
-	_v5, _ := dmp.PatchFromText("@@ -0,0 +1,3 @@\n+abc\n")
-	assert.Equal(t, "@@ -0,0 +1,3 @@\n+abc\n", _v5[0].String(), "patch_fromText: #4.")
-
-	// Generates error.
-	_, err := dmp.PatchFromText("Bad\nPatch\n")
-	assert.True(t, err != nil, "There should be an error")
-}
-
-func Test_patch_toText(t *testing.T) {
-	dmp := New()
-	strp := "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"
-	var patches []Patch
-	patches, _ = dmp.PatchFromText(strp)
-	result := dmp.PatchToText(patches)
-	assert.Equal(t, strp, result)
-
-	strp = "@@ -1,9 +1,9 @@\n-f\n+F\n oo+fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n  tes\n"
-	patches, _ = dmp.PatchFromText(strp)
-	result = dmp.PatchToText(patches)
-	assert.Equal(t, strp, result)
-}
-
-func Test_patch_addContext(t *testing.T) {
-	dmp := New()
-	dmp.PatchMargin = 4
-	var p Patch
-	_p, _ := dmp.PatchFromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")
-	p = _p[0]
-	p = dmp.PatchAddContext(p, "The quick brown fox jumps over the lazy dog.")
-	assert.Equal(t, "@@ -17,12 +17,18 @@\n fox \n-jump\n+somersault\n s ov\n", p.String(), "patch_addContext: Simple case.")
-
-	_p, _ = dmp.PatchFromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")
-	p = _p[0]
-	p = dmp.PatchAddContext(p, "The quick brown fox jumps.")
-	assert.Equal(t, "@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n", p.String(), "patch_addContext: Not enough trailing context.")
-
-	_p, _ = dmp.PatchFromText("@@ -3 +3,2 @@\n-e\n+at\n")
-	p = _p[0]
-	p = dmp.PatchAddContext(p, "The quick brown fox jumps.")
-	assert.Equal(t, "@@ -1,7 +1,8 @@\n Th\n-e\n+at\n  qui\n", p.String(), "patch_addContext: Not enough leading context.")
-
-	_p, _ = dmp.PatchFromText("@@ -3 +3,2 @@\n-e\n+at\n")
-	p = _p[0]
-	p = dmp.PatchAddContext(p, "The quick brown fox jumps.  The quick brown fox crashes.")
-	assert.Equal(t, "@@ -1,27 +1,28 @@\n Th\n-e\n+at\n  quick brown fox jumps. \n", p.String(), "patch_addContext: Ambiguity.")
-}
-
-func Test_patch_make(t *testing.T) {
-	dmp := New()
-	var patches []Patch
-	patches = dmp.PatchMake("", "")
-	assert.Equal(t, "", dmp.PatchToText(patches), "patch_make: Null case.")
-
-	text1 := "The quick brown fox jumps over the lazy dog."
-	text2 := "That quick brown fox jumped over a lazy dog."
-	expectedPatch := "@@ -1,8 +1,7 @@\n Th\n-at\n+e\n  qui\n@@ -21,17 +21,18 @@\n jump\n-ed\n+s\n  over \n-a\n+the\n  laz\n"
-	// The second patch must be "-21,17 +21,18", not "-22,17 +21,18" due to rolling context.
-	patches = dmp.PatchMake(text2, text1)
-	assert.Equal(t, expectedPatch, dmp.PatchToText(patches), "patch_make: Text2+Text1 inputs.")
-
-	expectedPatch = "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"
-	patches = dmp.PatchMake(text1, text2)
-	assert.Equal(t, expectedPatch, dmp.PatchToText(patches), "patch_make: Text1+Text2 inputs.")
-
-	diffs := dmp.DiffMain(text1, text2, false)
-	patches = dmp.PatchMake(diffs)
-	assert.Equal(t, expectedPatch, dmp.PatchToText(patches), "patch_make: Diff input.")
-
-	patches = dmp.PatchMake(text1, diffs)
-	assert.Equal(t, expectedPatch, dmp.PatchToText(patches), "patch_make: Text1+Diff inputs.")
-
-	patches = dmp.PatchMake(text1, text2, diffs)
-	assert.Equal(t, expectedPatch, dmp.PatchToText(patches), "patch_make: Text1+Text2+Diff inputs (deprecated).")
-
-	patches = dmp.PatchMake("`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?")
-	assert.Equal(t, "@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n",
-		dmp.PatchToText(patches),
-		"patch_toText: Character encoding.")
-
-	diffs = []Diff{
-		Diff{DiffDelete, "`1234567890-=[]\\;',./"},
-		Diff{DiffInsert, "~!@#$%^&*()_+{}|:\"<>?"}}
-
-	_p1, _ := dmp.PatchFromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n")
-	assertDiffEqual(t, diffs,
-		_p1[0].diffs,
-	)
-
-	text1 = ""
-	for x := 0; x < 100; x++ {
-		text1 += "abcdef"
-	}
-	text2 = text1 + "123"
-	expectedPatch = "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n"
-	patches = dmp.PatchMake(text1, text2)
-	assert.Equal(t, expectedPatch, dmp.PatchToText(patches), "patch_make: Long string with repeats.")
-
-	patches = dmp.PatchMake("2016-09-01T03:07:14.807830741Z", "2016-09-01T03:07:15.154800781Z")
-	assert.Equal(t, "@@ -15,16 +15,16 @@\n 07:1\n+5.15\n 4\n-.\n 80\n+0\n 78\n-3074\n 1Z\n", dmp.PatchToText(patches), "patch_make: Corner case of #31 fixed by #32")
-
-	text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ut risus et enim consectetur convallis a non ipsum. Sed nec nibh cursus, interdum libero vel."
-	text2 = "Lorem a ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ut risus et enim consectetur convallis a non ipsum. Sed nec nibh cursus, interdum liberovel."
-	dmp2 := New()
-	dmp2.DiffTimeout = 0
-	diffs = dmp2.DiffMain(text1, text2, true)
-	patches = dmp2.PatchMake(text1, diffs)
-	assert.Equal(t, "@@ -1,14 +1,16 @@\n Lorem \n+a \n ipsum do\n@@ -148,13 +148,12 @@\n m libero\n- \n vel.\n", dmp2.PatchToText(patches), "patch_make: Corner case of #28 wrong patch with timeout of 0")
-
-	// Additional check that the diff texts are equal to the originals even if we are using DiffMain with checklines=true #29
-	assert.Equal(t, text1, dmp2.DiffText1(diffs))
-	assert.Equal(t, text2, dmp2.DiffText2(diffs))
-}
-
-func Test_PatchSplitMax(t *testing.T) {
-	// Assumes that Match_MaxBits is 32.
-	dmp := New()
-	var patches []Patch
-
-	patches = dmp.PatchMake("abcdefghijklmnopqrstuvwxyz01234567890", "XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0")
-	patches = dmp.PatchSplitMax(patches)
-	assert.Equal(t, "@@ -1,32 +1,46 @@\n+X\n ab\n+X\n cd\n+X\n ef\n+X\n gh\n+X\n ij\n+X\n kl\n+X\n mn\n+X\n op\n+X\n qr\n+X\n st\n+X\n uv\n+X\n wx\n+X\n yz\n+X\n 012345\n@@ -25,13 +39,18 @@\n zX01\n+X\n 23\n+X\n 45\n+X\n 67\n+X\n 89\n+X\n 0\n", dmp.PatchToText(patches))
-
-	patches = dmp.PatchMake("abcdef1234567890123456789012345678901234567890123456789012345678901234567890uvwxyz", "abcdefuvwxyz")
-	oldToText := dmp.PatchToText(patches)
-	dmp.PatchSplitMax(patches)
-	assert.Equal(t, oldToText, dmp.PatchToText(patches))
-
-	patches = dmp.PatchMake("1234567890123456789012345678901234567890123456789012345678901234567890", "abc")
-	patches = dmp.PatchSplitMax(patches)
-	assert.Equal(t, "@@ -1,32 +1,4 @@\n-1234567890123456789012345678\n 9012\n@@ -29,32 +1,4 @@\n-9012345678901234567890123456\n 7890\n@@ -57,14 +1,3 @@\n-78901234567890\n+abc\n", dmp.PatchToText(patches))
-
-	patches = dmp.PatchMake("abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1", "abcdefghij , h : 1 , t : 1 abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1")
-	dmp.PatchSplitMax(patches)
-	assert.Equal(t, "@@ -2,32 +2,32 @@\n bcdefghij , h : \n-0\n+1\n  , t : 1 abcdef\n@@ -29,32 +29,32 @@\n bcdefghij , h : \n-0\n+1\n  , t : 1 abcdef\n", dmp.PatchToText(patches))
-}
-
-func Test_PatchAddPadding(t *testing.T) {
-	dmp := New()
-	var patches []Patch
-	patches = dmp.PatchMake("", "test")
-	pass := assert.Equal(t, "@@ -0,0 +1,4 @@\n+test\n",
-		dmp.PatchToText(patches),
-		"PatchAddPadding: Both edges full.")
-	if !pass {
-		t.FailNow()
-	}
-
-	dmp.PatchAddPadding(patches)
-	assert.Equal(t, "@@ -1,8 +1,12 @@\n %01%02%03%04\n+test\n %01%02%03%04\n",
-		dmp.PatchToText(patches),
-		"PatchAddPadding: Both edges full.")
-
-	patches = dmp.PatchMake("XY", "XtestY")
-	assert.Equal(t, "@@ -1,2 +1,6 @@\n X\n+test\n Y\n",
-		dmp.PatchToText(patches),
-		"PatchAddPadding: Both edges partial.")
-	dmp.PatchAddPadding(patches)
-	assert.Equal(t, "@@ -2,8 +2,12 @@\n %02%03%04X\n+test\n Y%01%02%03\n",
-		dmp.PatchToText(patches),
-		"PatchAddPadding: Both edges partial.")
-
-	patches = dmp.PatchMake("XXXXYYYY", "XXXXtestYYYY")
-	assert.Equal(t, "@@ -1,8 +1,12 @@\n XXXX\n+test\n YYYY\n",
-		dmp.PatchToText(patches),
-		"PatchAddPadding: Both edges none.")
-	dmp.PatchAddPadding(patches)
-	assert.Equal(t, "@@ -5,8 +5,12 @@\n XXXX\n+test\n YYYY\n",
-		dmp.PatchToText(patches),
-		"PatchAddPadding: Both edges none.")
-}
-
-func Test_patchApply(t *testing.T) {
-	dmp := New()
-	dmp.MatchDistance = 1000
-	dmp.MatchThreshold = 0.5
-	dmp.PatchDeleteThreshold = 0.5
-	patches := []Patch{}
-	patches = dmp.PatchMake("", "")
-	results0, results1 := dmp.PatchApply(patches, "Hello world.")
-	boolArray := results1
-	resultStr := fmt.Sprintf("%v\t%v", results0, len(boolArray))
-	pass := assert.Equal(t, "Hello world.\t0", resultStr, "patch_apply: Null case.")
-	if !pass {
-		t.FailNow()
-	}
-
-	patches = dmp.PatchMake("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.")
-	results0, results1 = dmp.PatchApply(patches, "The quick brown fox jumps over the lazy dog.")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "That quick brown fox jumped over a lazy dog.\ttrue\ttrue", resultStr, "patch_apply: Exact match.")
-
-	results0, results1 = dmp.PatchApply(patches, "The quick red rabbit jumps over the tired tiger.")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "That quick red rabbit jumped over a tired tiger.\ttrue\ttrue", resultStr, "patch_apply: Partial match.")
-
-	results0, results1 = dmp.PatchApply(patches, "I am the very model of a modern major general.")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "I am the very model of a modern major general.\tfalse\tfalse", resultStr, "patch_apply: Failed match.")
-
-	patches = dmp.PatchMake("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy")
-	results0, results1 = dmp.PatchApply(patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "xabcy\ttrue\ttrue", resultStr, "patch_apply: Big delete, small Diff.")
-
-	patches = dmp.PatchMake("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy")
-	results0, results1 = dmp.PatchApply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "xabc12345678901234567890---------------++++++++++---------------12345678901234567890y\tfalse\ttrue", resultStr, "patch_apply: Big delete, big Diff 1.")
-
-	dmp.PatchDeleteThreshold = 0.6
-	patches = dmp.PatchMake("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy")
-	results0, results1 = dmp.PatchApply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "xabcy\ttrue\ttrue", resultStr, "patch_apply: Big delete, big Diff 2.")
-	dmp.PatchDeleteThreshold = 0.5
-
-	dmp.MatchThreshold = 0.0
-	dmp.MatchDistance = 0
-	patches = dmp.PatchMake("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890")
-	results0, results1 = dmp.PatchApply(patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0]) + "\t" + strconv.FormatBool(boolArray[1])
-	assert.Equal(t, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890\tfalse\ttrue", resultStr, "patch_apply: Compensate for failed patch.")
-	dmp.MatchThreshold = 0.5
-	dmp.MatchDistance = 1000
-
-	patches = dmp.PatchMake("", "test")
-	patchStr := dmp.PatchToText(patches)
-	dmp.PatchApply(patches, "")
-	assert.Equal(t, patchStr, dmp.PatchToText(patches), "patch_apply: No side effects.")
-
-	patches = dmp.PatchMake("The quick brown fox jumps over the lazy dog.", "Woof")
-	patchStr = dmp.PatchToText(patches)
-	dmp.PatchApply(patches, "The quick brown fox jumps over the lazy dog.")
-	assert.Equal(t, patchStr, dmp.PatchToText(patches), "patch_apply: No side effects with major delete.")
-
-	patches = dmp.PatchMake("", "test")
-	results0, results1 = dmp.PatchApply(patches, "")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0])
-	assert.Equal(t, "test\ttrue", resultStr, "patch_apply: Edge exact match.")
-
-	patches = dmp.PatchMake("XY", "XtestY")
-	results0, results1 = dmp.PatchApply(patches, "XY")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0])
-	assert.Equal(t, "XtestY\ttrue", resultStr, "patch_apply: Near edge exact match.")
-
-	patches = dmp.PatchMake("y", "y123")
-	results0, results1 = dmp.PatchApply(patches, "x")
-	boolArray = results1
-	resultStr = results0 + "\t" + strconv.FormatBool(boolArray[0])
-	assert.Equal(t, "x123\ttrue", resultStr, "patch_apply: Edge partial match.")
-}
-
-func TestIndexOf(t *testing.T) {
-	type TestCase struct {
-		String   string
-		Pattern  string
-		Position int
-		Expected int
-	}
-	cases := []TestCase{
-		{"hi world", "world", -1, 3},
-		{"hi world", "world", 0, 3},
-		{"hi world", "world", 1, 3},
-		{"hi world", "world", 2, 3},
-		{"hi world", "world", 3, 3},
-		{"hi world", "world", 4, -1},
-		{"abbc", "b", -1, 1},
-		{"abbc", "b", 0, 1},
-		{"abbc", "b", 1, 1},
-		{"abbc", "b", 2, 2},
-		{"abbc", "b", 3, -1},
-		{"abbc", "b", 4, -1},
-		// The greek letter beta is the two-byte sequence of "\u03b2".
-		{"a\u03b2\u03b2c", "\u03b2", -1, 1},
-		{"a\u03b2\u03b2c", "\u03b2", 0, 1},
-		{"a\u03b2\u03b2c", "\u03b2", 1, 1},
-		{"a\u03b2\u03b2c", "\u03b2", 3, 3},
-		{"a\u03b2\u03b2c", "\u03b2", 5, -1},
-		{"a\u03b2\u03b2c", "\u03b2", 6, -1},
-	}
-	for i, c := range cases {
-		actual := indexOf(c.String, c.Pattern, c.Position)
-		assert.Equal(t, c.Expected, actual, fmt.Sprintf("TestIndex case %d", i))
-	}
-}
-
-func TestLastIndexOf(t *testing.T) {
-	type TestCase struct {
-		String   string
-		Pattern  string
-		Position int
-		Expected int
-	}
-	cases := []TestCase{
-		{"hi world", "world", -1, -1},
-		{"hi world", "world", 0, -1},
-		{"hi world", "world", 1, -1},
-		{"hi world", "world", 2, -1},
-		{"hi world", "world", 3, -1},
-		{"hi world", "world", 4, -1},
-		{"hi world", "world", 5, -1},
-		{"hi world", "world", 6, -1},
-		{"hi world", "world", 7, 3},
-		{"hi world", "world", 8, 3},
-		{"abbc", "b", -1, -1},
-		{"abbc", "b", 0, -1},
-		{"abbc", "b", 1, 1},
-		{"abbc", "b", 2, 2},
-		{"abbc", "b", 3, 2},
-		{"abbc", "b", 4, 2},
-		// The greek letter beta is the two-byte sequence of "\u03b2".
-		{"a\u03b2\u03b2c", "\u03b2", -1, -1},
-		{"a\u03b2\u03b2c", "\u03b2", 0, -1},
-		{"a\u03b2\u03b2c", "\u03b2", 1, 1},
-		{"a\u03b2\u03b2c", "\u03b2", 3, 3},
-		{"a\u03b2\u03b2c", "\u03b2", 5, 3},
-		{"a\u03b2\u03b2c", "\u03b2", 6, 3},
-	}
-
-	for i, c := range cases {
-		actual := lastIndexOf(c.String, c.Pattern, c.Position)
-		assert.Equal(t, c.Expected, actual,
-			fmt.Sprintf("TestLastIndex case %d", i))
-	}
-}
-
-func Benchmark_DiffMain(bench *testing.B) {
-	dmp := New()
-	dmp.DiffTimeout = time.Second
-	a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
-	b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
-	// Increase the text lengths by 1024 times to ensure a timeout.
-	for x := 0; x < 10; x++ {
-		a = a + a
-		b = b + b
-	}
-	bench.ResetTimer()
-	for i := 0; i < bench.N; i++ {
-		dmp.DiffMain(a, b, true)
-	}
-}
-
-func Benchmark_DiffCommonPrefix(b *testing.B) {
-	dmp := New()
-	a := "ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ"
-	for i := 0; i < b.N; i++ {
-		dmp.DiffCommonPrefix(a, a)
-	}
-}
-
-func Benchmark_DiffCommonSuffix(b *testing.B) {
-	dmp := New()
-	a := "ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ"
-	for i := 0; i < b.N; i++ {
-		dmp.DiffCommonSuffix(a, a)
-	}
-}
-
-func Benchmark_DiffMainLarge(b *testing.B) {
-	s1 := readFile("speedtest1.txt", b)
-	s2 := readFile("speedtest2.txt", b)
-	dmp := New()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		dmp.DiffMain(s1, s2, true)
-	}
-}
-
-func Benchmark_DiffMainLargeLines(b *testing.B) {
-	s1 := readFile("speedtest1.txt", b)
-	s2 := readFile("speedtest2.txt", b)
-	dmp := New()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		text1, text2, linearray := dmp.DiffLinesToRunes(s1, s2)
-		diffs := dmp.DiffMainRunes(text1, text2, false)
-		diffs = dmp.DiffCharsToLines(diffs, linearray)
-	}
-}
-
-func Benchmark_DiffHalfMatch(b *testing.B) {
-	s1 := readFile("speedtest1.txt", b)
-	s2 := readFile("speedtest2.txt", b)
-	dmp := New()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		dmp.DiffHalfMatch(s1, s2)
-	}
-}
-
-func Benchmark_DiffCleanupSemantic(b *testing.B) {
-	s1 := readFile("speedtest1.txt", b)
-	s2 := readFile("speedtest2.txt", b)
-
-	dmp := New()
-
-	diffs := dmp.DiffMain(s1, s2, false)
-
-	b.ResetTimer()
-
-	for i := 0; i < b.N; i++ {
-		dmp.DiffCleanupSemantic(diffs)
-	}
-}
-
-func readFile(filename string, b *testing.B) string {
-	bytes, err := ioutil.ReadFile(filename)
-	if err != nil {
-		b.Fatal(err)
-	}
-	return string(bytes)
-}
diff --git a/diffmatchpatch/match.go b/diffmatchpatch/match.go
new file mode 100644
index 0000000..17374e1
--- /dev/null
+++ b/diffmatchpatch/match.go
@@ -0,0 +1,160 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"math"
+)
+
+// MatchMain locates the best instance of 'pattern' in 'text' near 'loc'.
+// Returns -1 if no match found.
+func (dmp *DiffMatchPatch) MatchMain(text, pattern string, loc int) int {
+	// Check for null inputs not needed since null can't be passed in C#.
+
+	loc = int(math.Max(0, math.Min(float64(loc), float64(len(text)))))
+	if text == pattern {
+		// Shortcut (potentially not guaranteed by the algorithm)
+		return 0
+	} else if len(text) == 0 {
+		// Nothing to match.
+		return -1
+	} else if loc+len(pattern) <= len(text) && text[loc:loc+len(pattern)] == pattern {
+		// Perfect match at the perfect spot!  (Includes case of null pattern)
+		return loc
+	}
+	// Do a fuzzy compare.
+	return dmp.MatchBitap(text, pattern, loc)
+}
+
+// MatchBitap locates the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
+// Returns -1 if no match was found.
+func (dmp *DiffMatchPatch) MatchBitap(text, pattern string, loc int) int {
+	// Initialise the alphabet.
+	s := dmp.MatchAlphabet(pattern)
+
+	// Highest score beyond which we give up.
+	scoreThreshold := dmp.MatchThreshold
+	// Is there a nearby exact match? (speedup)
+	bestLoc := indexOf(text, pattern, loc)
+	if bestLoc != -1 {
+		scoreThreshold = math.Min(dmp.matchBitapScore(0, bestLoc, loc,
+			pattern), scoreThreshold)
+		// What about in the other direction? (speedup)
+		bestLoc = lastIndexOf(text, pattern, loc+len(pattern))
+		if bestLoc != -1 {
+			scoreThreshold = math.Min(dmp.matchBitapScore(0, bestLoc, loc,
+				pattern), scoreThreshold)
+		}
+	}
+
+	// Initialise the bit arrays.
+	matchmask := 1 << uint((len(pattern) - 1))
+	bestLoc = -1
+
+	var binMin, binMid int
+	binMax := len(pattern) + len(text)
+	lastRd := []int{}
+	for d := 0; d < len(pattern); d++ {
+		// Scan for the best match; each iteration allows for one more error. Run a binary search to determine how far from 'loc' we can stray at this error level.
+		binMin = 0
+		binMid = binMax
+		for binMin < binMid {
+			if dmp.matchBitapScore(d, loc+binMid, loc, pattern) <= scoreThreshold {
+				binMin = binMid
+			} else {
+				binMax = binMid
+			}
+			binMid = (binMax-binMin)/2 + binMin
+		}
+		// Use the result from this iteration as the maximum for the next.
+		binMax = binMid
+		start := int(math.Max(1, float64(loc-binMid+1)))
+		finish := int(math.Min(float64(loc+binMid), float64(len(text))) + float64(len(pattern)))
+
+		rd := make([]int, finish+2)
+		rd[finish+1] = (1 << uint(d)) - 1
+
+		for j := finish; j >= start; j-- {
+			var charMatch int
+			if len(text) <= j-1 {
+				// Out of range.
+				charMatch = 0
+			} else if _, ok := s[text[j-1]]; !ok {
+				charMatch = 0
+			} else {
+				charMatch = s[text[j-1]]
+			}
+
+			if d == 0 {
+				// First pass: exact match.
+				rd[j] = ((rd[j+1] << 1) | 1) & charMatch
+			} else {
+				// Subsequent passes: fuzzy match.
+				rd[j] = ((rd[j+1]<<1)|1)&charMatch | (((lastRd[j+1] | lastRd[j]) << 1) | 1) | lastRd[j+1]
+			}
+			if (rd[j] & matchmask) != 0 {
+				score := dmp.matchBitapScore(d, j-1, loc, pattern)
+				// This match will almost certainly be better than any existing match.  But check anyway.
+				if score <= scoreThreshold {
+					// Told you so.
+					scoreThreshold = score
+					bestLoc = j - 1
+					if bestLoc > loc {
+						// When passing loc, don't exceed our current distance from loc.
+						start = int(math.Max(1, float64(2*loc-bestLoc)))
+					} else {
+						// Already passed loc, downhill from here on in.
+						break
+					}
+				}
+			}
+		}
+		if dmp.matchBitapScore(d+1, loc, loc, pattern) > scoreThreshold {
+			// No hope for a (better) match at greater error levels.
+			break
+		}
+		lastRd = rd
+	}
+	return bestLoc
+}
+
+// matchBitapScore computes and returns the score for a match with e errors and x location.
+func (dmp *DiffMatchPatch) matchBitapScore(e, x, loc int, pattern string) float64 {
+	accuracy := float64(e) / float64(len(pattern))
+	proximity := math.Abs(float64(loc - x))
+	if dmp.MatchDistance == 0 {
+		// Dodge divide by zero error.
+		if proximity == 0 {
+			return accuracy
+		}
+
+		return 1.0
+	}
+	return accuracy + (proximity / float64(dmp.MatchDistance))
+}
+
+// MatchAlphabet initialises the alphabet for the Bitap algorithm.
+func (dmp *DiffMatchPatch) MatchAlphabet(pattern string) map[byte]int {
+	s := map[byte]int{}
+	charPattern := []byte(pattern)
+	for _, c := range charPattern {
+		_, ok := s[c]
+		if !ok {
+			s[c] = 0
+		}
+	}
+	i := 0
+
+	for _, c := range charPattern {
+		value := s[c] | int(uint(1)<<uint((len(pattern)-i-1)))
+		s[c] = value
+		i++
+	}
+	return s
+}
diff --git a/diffmatchpatch/match_test.go b/diffmatchpatch/match_test.go
new file mode 100644
index 0000000..f9abe60
--- /dev/null
+++ b/diffmatchpatch/match_test.go
@@ -0,0 +1,174 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"fmt"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestMatchAlphabet(t *testing.T) {
+	type TestCase struct {
+		Pattern string
+
+		Expected map[byte]int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{
+			Pattern: "abc",
+
+			Expected: map[byte]int{
+				'a': 4,
+				'b': 2,
+				'c': 1,
+			},
+		},
+		{
+			Pattern: "abcaba",
+
+			Expected: map[byte]int{
+				'a': 37,
+				'b': 18,
+				'c': 8,
+			},
+		},
+	} {
+		actual := dmp.MatchAlphabet(tc.Pattern)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestMatchBitap(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text     string
+		Pattern  string
+		Location int
+
+		Expected int
+	}
+
+	dmp := New()
+	dmp.MatchDistance = 100
+	dmp.MatchThreshold = 0.5
+
+	for i, tc := range []TestCase{
+		{"Exact match #1", "abcdefghijk", "fgh", 5, 5},
+		{"Exact match #2", "abcdefghijk", "fgh", 0, 5},
+		{"Fuzzy match #1", "abcdefghijk", "efxhi", 0, 4},
+		{"Fuzzy match #2", "abcdefghijk", "cdefxyhijk", 5, 2},
+		{"Fuzzy match #3", "abcdefghijk", "bxy", 1, -1},
+		{"Overflow", "123456789xx0", "3456789x0", 2, 2},
+		{"Before start match", "abcdef", "xxabc", 4, 0},
+		{"Beyond end match", "abcdef", "defyy", 4, 3},
+		{"Oversized pattern", "abcdef", "xabcdefy", 0, 0},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchThreshold = 0.4
+
+	for i, tc := range []TestCase{
+		{"Threshold #1", "abcdefghijk", "efxyhi", 1, 4},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchThreshold = 0.3
+
+	for i, tc := range []TestCase{
+		{"Threshold #2", "abcdefghijk", "efxyhi", 1, -1},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchThreshold = 0.0
+
+	for i, tc := range []TestCase{
+		{"Threshold #3", "abcdefghijk", "bcdef", 1, 1},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchThreshold = 0.5
+
+	for i, tc := range []TestCase{
+		{"Multiple select #1", "abcdexyzabcde", "abccde", 3, 0},
+		{"Multiple select #2", "abcdexyzabcde", "abccde", 5, 8},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	// Strict location.
+	dmp.MatchDistance = 10
+
+	for i, tc := range []TestCase{
+		{"Distance test #1", "abcdefghijklmnopqrstuvwxyz", "abcdefg", 24, -1},
+		{"Distance test #2", "abcdefghijklmnopqrstuvwxyz", "abcdxxefg", 1, 0},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	// Loose location.
+	dmp.MatchDistance = 1000
+
+	for i, tc := range []TestCase{
+		{"Distance test #3", "abcdefghijklmnopqrstuvwxyz", "abcdefg", 24, 0},
+	} {
+		actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestMatchMain(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text1    string
+		Text2    string
+		Location int
+
+		Expected int
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Equality", "abcdef", "abcdef", 1000, 0},
+		{"Null text", "", "abcdef", 1, -1},
+		{"Null pattern", "abcdef", "", 3, 3},
+		{"Exact match", "abcdef", "de", 3, 3},
+		{"Beyond end match", "abcdef", "defy", 4, 3},
+		{"Oversized pattern", "abcdef", "abcdefy", 0, 0},
+	} {
+		actual := dmp.MatchMain(tc.Text1, tc.Text2, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchThreshold = 0.7
+
+	for i, tc := range []TestCase{
+		{"Complex match", "I am the very model of a modern major general.", " that berry ", 5, 4},
+	} {
+		actual := dmp.MatchMain(tc.Text1, tc.Text2, tc.Location)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
diff --git a/diffmatchpatch/mathutil.go b/diffmatchpatch/mathutil.go
new file mode 100644
index 0000000..aed242b
--- /dev/null
+++ b/diffmatchpatch/mathutil.go
@@ -0,0 +1,23 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+func min(x, y int) int {
+	if x < y {
+		return x
+	}
+	return y
+}
+
+func max(x, y int) int {
+	if x > y {
+		return x
+	}
+	return y
+}
diff --git a/diffmatchpatch/patch.go b/diffmatchpatch/patch.go
new file mode 100644
index 0000000..116c043
--- /dev/null
+++ b/diffmatchpatch/patch.go
@@ -0,0 +1,556 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"bytes"
+	"errors"
+	"math"
+	"net/url"
+	"regexp"
+	"strconv"
+	"strings"
+)
+
+// Patch represents one patch operation.
+type Patch struct {
+	diffs   []Diff
+	start1  int
+	start2  int
+	length1 int
+	length2 int
+}
+
+// String emulates GNU diff's format.
+// Header: @@ -382,8 +481,9 @@
+// Indicies are printed as 1-based, not 0-based.
+func (p *Patch) String() string {
+	var coords1, coords2 string
+
+	if p.length1 == 0 {
+		coords1 = strconv.Itoa(p.start1) + ",0"
+	} else if p.length1 == 1 {
+		coords1 = strconv.Itoa(p.start1 + 1)
+	} else {
+		coords1 = strconv.Itoa(p.start1+1) + "," + strconv.Itoa(p.length1)
+	}
+
+	if p.length2 == 0 {
+		coords2 = strconv.Itoa(p.start2) + ",0"
+	} else if p.length2 == 1 {
+		coords2 = strconv.Itoa(p.start2 + 1)
+	} else {
+		coords2 = strconv.Itoa(p.start2+1) + "," + strconv.Itoa(p.length2)
+	}
+
+	var text bytes.Buffer
+	_, _ = text.WriteString("@@ -" + coords1 + " +" + coords2 + " @@\n")
+
+	// Escape the body of the patch with %xx notation.
+	for _, aDiff := range p.diffs {
+		switch aDiff.Type {
+		case DiffInsert:
+			_, _ = text.WriteString("+")
+		case DiffDelete:
+			_, _ = text.WriteString("-")
+		case DiffEqual:
+			_, _ = text.WriteString(" ")
+		}
+
+		_, _ = text.WriteString(strings.Replace(url.QueryEscape(aDiff.Text), "+", " ", -1))
+		_, _ = text.WriteString("\n")
+	}
+
+	return unescaper.Replace(text.String())
+}
+
+// PatchAddContext increases the context until it is unique, but doesn't let the pattern expand beyond MatchMaxBits.
+func (dmp *DiffMatchPatch) PatchAddContext(patch Patch, text string) Patch {
+	if len(text) == 0 {
+		return patch
+	}
+
+	pattern := text[patch.start2 : patch.start2+patch.length1]
+	padding := 0
+
+	// Look for the first and last matches of pattern in text.  If two different matches are found, increase the pattern length.
+	for strings.Index(text, pattern) != strings.LastIndex(text, pattern) &&
+		len(pattern) < dmp.MatchMaxBits-2*dmp.PatchMargin {
+		padding += dmp.PatchMargin
+		maxStart := max(0, patch.start2-padding)
+		minEnd := min(len(text), patch.start2+patch.length1+padding)
+		pattern = text[maxStart:minEnd]
+	}
+	// Add one chunk for good luck.
+	padding += dmp.PatchMargin
+
+	// Add the prefix.
+	prefix := text[max(0, patch.start2-padding):patch.start2]
+	if len(prefix) != 0 {
+		patch.diffs = append([]Diff{Diff{DiffEqual, prefix}}, patch.diffs...)
+	}
+	// Add the suffix.
+	suffix := text[patch.start2+patch.length1 : min(len(text), patch.start2+patch.length1+padding)]
+	if len(suffix) != 0 {
+		patch.diffs = append(patch.diffs, Diff{DiffEqual, suffix})
+	}
+
+	// Roll back the start points.
+	patch.start1 -= len(prefix)
+	patch.start2 -= len(prefix)
+	// Extend the lengths.
+	patch.length1 += len(prefix) + len(suffix)
+	patch.length2 += len(prefix) + len(suffix)
+
+	return patch
+}
+
+// PatchMake computes a list of patches.
+func (dmp *DiffMatchPatch) PatchMake(opt ...interface{}) []Patch {
+	if len(opt) == 1 {
+		diffs, _ := opt[0].([]Diff)
+		text1 := dmp.DiffText1(diffs)
+		return dmp.PatchMake(text1, diffs)
+	} else if len(opt) == 2 {
+		text1 := opt[0].(string)
+		switch t := opt[1].(type) {
+		case string:
+			diffs := dmp.DiffMain(text1, t, true)
+			if len(diffs) > 2 {
+				diffs = dmp.DiffCleanupSemantic(diffs)
+				diffs = dmp.DiffCleanupEfficiency(diffs)
+			}
+			return dmp.PatchMake(text1, diffs)
+		case []Diff:
+			return dmp.patchMake2(text1, t)
+		}
+	} else if len(opt) == 3 {
+		return dmp.PatchMake(opt[0], opt[2])
+	}
+	return []Patch{}
+}
+
+// patchMake2 computes a list of patches to turn text1 into text2.
+// text2 is not provided, diffs are the delta between text1 and text2.
+func (dmp *DiffMatchPatch) patchMake2(text1 string, diffs []Diff) []Patch {
+	// Check for null inputs not needed since null can't be passed in C#.
+	patches := []Patch{}
+	if len(diffs) == 0 {
+		return patches // Get rid of the null case.
+	}
+
+	patch := Patch{}
+	charCount1 := 0 // Number of characters into the text1 string.
+	charCount2 := 0 // Number of characters into the text2 string.
+	// Start with text1 (prepatchText) and apply the diffs until we arrive at text2 (postpatchText). We recreate the patches one by one to determine context info.
+	prepatchText := text1
+	postpatchText := text1
+
+	for i, aDiff := range diffs {
+		if len(patch.diffs) == 0 && aDiff.Type != DiffEqual {
+			// A new patch starts here.
+			patch.start1 = charCount1
+			patch.start2 = charCount2
+		}
+
+		switch aDiff.Type {
+		case DiffInsert:
+			patch.diffs = append(patch.diffs, aDiff)
+			patch.length2 += len(aDiff.Text)
+			postpatchText = postpatchText[:charCount2] +
+				aDiff.Text + postpatchText[charCount2:]
+		case DiffDelete:
+			patch.length1 += len(aDiff.Text)
+			patch.diffs = append(patch.diffs, aDiff)
+			postpatchText = postpatchText[:charCount2] + postpatchText[charCount2+len(aDiff.Text):]
+		case DiffEqual:
+			if len(aDiff.Text) <= 2*dmp.PatchMargin &&
+				len(patch.diffs) != 0 && i != len(diffs)-1 {
+				// Small equality inside a patch.
+				patch.diffs = append(patch.diffs, aDiff)
+				patch.length1 += len(aDiff.Text)
+				patch.length2 += len(aDiff.Text)
+			}
+			if len(aDiff.Text) >= 2*dmp.PatchMargin {
+				// Time for a new patch.
+				if len(patch.diffs) != 0 {
+					patch = dmp.PatchAddContext(patch, prepatchText)
+					patches = append(patches, patch)
+					patch = Patch{}
+					// Unlike Unidiff, our patch lists have a rolling context. http://code.google.com/p/google-diff-match-patch/wiki/Unidiff Update prepatch text & pos to reflect the application of the just completed patch.
+					prepatchText = postpatchText
+					charCount1 = charCount2
+				}
+			}
+		}
+
+		// Update the current character count.
+		if aDiff.Type != DiffInsert {
+			charCount1 += len(aDiff.Text)
+		}
+		if aDiff.Type != DiffDelete {
+			charCount2 += len(aDiff.Text)
+		}
+	}
+
+	// Pick up the leftover patch if not empty.
+	if len(patch.diffs) != 0 {
+		patch = dmp.PatchAddContext(patch, prepatchText)
+		patches = append(patches, patch)
+	}
+
+	return patches
+}
+
+// PatchDeepCopy returns an array that is identical to a given an array of patches.
+func (dmp *DiffMatchPatch) PatchDeepCopy(patches []Patch) []Patch {
+	patchesCopy := []Patch{}
+	for _, aPatch := range patches {
+		patchCopy := Patch{}
+		for _, aDiff := range aPatch.diffs {
+			patchCopy.diffs = append(patchCopy.diffs, Diff{
+				aDiff.Type,
+				aDiff.Text,
+			})
+		}
+		patchCopy.start1 = aPatch.start1
+		patchCopy.start2 = aPatch.start2
+		patchCopy.length1 = aPatch.length1
+		patchCopy.length2 = aPatch.length2
+		patchesCopy = append(patchesCopy, patchCopy)
+	}
+	return patchesCopy
+}
+
+// PatchApply merges a set of patches onto the text.  Returns a patched text, as well as an array of true/false values indicating which patches were applied.
+func (dmp *DiffMatchPatch) PatchApply(patches []Patch, text string) (string, []bool) {
+	if len(patches) == 0 {
+		return text, []bool{}
+	}
+
+	// Deep copy the patches so that no changes are made to originals.
+	patches = dmp.PatchDeepCopy(patches)
+
+	nullPadding := dmp.PatchAddPadding(patches)
+	text = nullPadding + text + nullPadding
+	patches = dmp.PatchSplitMax(patches)
+
+	x := 0
+	// delta keeps track of the offset between the expected and actual location of the previous patch.  If there are patches expected at positions 10 and 20, but the first patch was found at 12, delta is 2 and the second patch has an effective expected position of 22.
+	delta := 0
+	results := make([]bool, len(patches))
+	for _, aPatch := range patches {
+		expectedLoc := aPatch.start2 + delta
+		text1 := dmp.DiffText1(aPatch.diffs)
+		var startLoc int
+		endLoc := -1
+		if len(text1) > dmp.MatchMaxBits {
+			// PatchSplitMax will only provide an oversized pattern in the case of a monster delete.
+			startLoc = dmp.MatchMain(text, text1[:dmp.MatchMaxBits], expectedLoc)
+			if startLoc != -1 {
+				endLoc = dmp.MatchMain(text,
+					text1[len(text1)-dmp.MatchMaxBits:], expectedLoc+len(text1)-dmp.MatchMaxBits)
+				if endLoc == -1 || startLoc >= endLoc {
+					// Can't find valid trailing context.  Drop this patch.
+					startLoc = -1
+				}
+			}
+		} else {
+			startLoc = dmp.MatchMain(text, text1, expectedLoc)
+		}
+		if startLoc == -1 {
+			// No match found.  :(
+			results[x] = false
+			// Subtract the delta for this failed patch from subsequent patches.
+			delta -= aPatch.length2 - aPatch.length1
+		} else {
+			// Found a match.  :)
+			results[x] = true
+			delta = startLoc - expectedLoc
+			var text2 string
+			if endLoc == -1 {
+				text2 = text[startLoc:int(math.Min(float64(startLoc+len(text1)), float64(len(text))))]
+			} else {
+				text2 = text[startLoc:int(math.Min(float64(endLoc+dmp.MatchMaxBits), float64(len(text))))]
+			}
+			if text1 == text2 {
+				// Perfect match, just shove the Replacement text in.
+				text = text[:startLoc] + dmp.DiffText2(aPatch.diffs) + text[startLoc+len(text1):]
+			} else {
+				// Imperfect match.  Run a diff to get a framework of equivalent indices.
+				diffs := dmp.DiffMain(text1, text2, false)
+				if len(text1) > dmp.MatchMaxBits && float64(dmp.DiffLevenshtein(diffs))/float64(len(text1)) > dmp.PatchDeleteThreshold {
+					// The end points match, but the content is unacceptably bad.
+					results[x] = false
+				} else {
+					diffs = dmp.DiffCleanupSemanticLossless(diffs)
+					index1 := 0
+					for _, aDiff := range aPatch.diffs {
+						if aDiff.Type != DiffEqual {
+							index2 := dmp.DiffXIndex(diffs, index1)
+							if aDiff.Type == DiffInsert {
+								// Insertion
+								text = text[:startLoc+index2] + aDiff.Text + text[startLoc+index2:]
+							} else if aDiff.Type == DiffDelete {
+								// Deletion
+								startIndex := startLoc + index2
+								text = text[:startIndex] +
+									text[startIndex+dmp.DiffXIndex(diffs, index1+len(aDiff.Text))-index2:]
+							}
+						}
+						if aDiff.Type != DiffDelete {
+							index1 += len(aDiff.Text)
+						}
+					}
+				}
+			}
+		}
+		x++
+	}
+	// Strip the padding off.
+	text = text[len(nullPadding) : len(nullPadding)+(len(text)-2*len(nullPadding))]
+	return text, results
+}
+
+// PatchAddPadding adds some padding on text start and end so that edges can match something.
+// Intended to be called only from within patchApply.
+func (dmp *DiffMatchPatch) PatchAddPadding(patches []Patch) string {
+	paddingLength := dmp.PatchMargin
+	nullPadding := ""
+	for x := 1; x <= paddingLength; x++ {
+		nullPadding += string(x)
+	}
+
+	// Bump all the patches forward.
+	for i := range patches {
+		patches[i].start1 += paddingLength
+		patches[i].start2 += paddingLength
+	}
+
+	// Add some padding on start of first diff.
+	if len(patches[0].diffs) == 0 || patches[0].diffs[0].Type != DiffEqual {
+		// Add nullPadding equality.
+		patches[0].diffs = append([]Diff{Diff{DiffEqual, nullPadding}}, patches[0].diffs...)
+		patches[0].start1 -= paddingLength // Should be 0.
+		patches[0].start2 -= paddingLength // Should be 0.
+		patches[0].length1 += paddingLength
+		patches[0].length2 += paddingLength
+	} else if paddingLength > len(patches[0].diffs[0].Text) {
+		// Grow first equality.
+		extraLength := paddingLength - len(patches[0].diffs[0].Text)
+		patches[0].diffs[0].Text = nullPadding[len(patches[0].diffs[0].Text):] + patches[0].diffs[0].Text
+		patches[0].start1 -= extraLength
+		patches[0].start2 -= extraLength
+		patches[0].length1 += extraLength
+		patches[0].length2 += extraLength
+	}
+
+	// Add some padding on end of last diff.
+	last := len(patches) - 1
+	if len(patches[last].diffs) == 0 || patches[last].diffs[len(patches[last].diffs)-1].Type != DiffEqual {
+		// Add nullPadding equality.
+		patches[last].diffs = append(patches[last].diffs, Diff{DiffEqual, nullPadding})
+		patches[last].length1 += paddingLength
+		patches[last].length2 += paddingLength
+	} else if paddingLength > len(patches[last].diffs[len(patches[last].diffs)-1].Text) {
+		// Grow last equality.
+		lastDiff := patches[last].diffs[len(patches[last].diffs)-1]
+		extraLength := paddingLength - len(lastDiff.Text)
+		patches[last].diffs[len(patches[last].diffs)-1].Text += nullPadding[:extraLength]
+		patches[last].length1 += extraLength
+		patches[last].length2 += extraLength
+	}
+
+	return nullPadding
+}
+
+// PatchSplitMax looks through the patches and breaks up any which are longer than the maximum limit of the match algorithm.
+// Intended to be called only from within patchApply.
+func (dmp *DiffMatchPatch) PatchSplitMax(patches []Patch) []Patch {
+	patchSize := dmp.MatchMaxBits
+	for x := 0; x < len(patches); x++ {
+		if patches[x].length1 <= patchSize {
+			continue
+		}
+		bigpatch := patches[x]
+		// Remove the big old patch.
+		patches = append(patches[:x], patches[x+1:]...)
+		x--
+
+		start1 := bigpatch.start1
+		start2 := bigpatch.start2
+		precontext := ""
+		for len(bigpatch.diffs) != 0 {
+			// Create one of several smaller patches.
+			patch := Patch{}
+			empty := true
+			patch.start1 = start1 - len(precontext)
+			patch.start2 = start2 - len(precontext)
+			if len(precontext) != 0 {
+				patch.length1 = len(precontext)
+				patch.length2 = len(precontext)
+				patch.diffs = append(patch.diffs, Diff{DiffEqual, precontext})
+			}
+			for len(bigpatch.diffs) != 0 && patch.length1 < patchSize-dmp.PatchMargin {
+				diffType := bigpatch.diffs[0].Type
+				diffText := bigpatch.diffs[0].Text
+				if diffType == DiffInsert {
+					// Insertions are harmless.
+					patch.length2 += len(diffText)
+					start2 += len(diffText)
+					patch.diffs = append(patch.diffs, bigpatch.diffs[0])
+					bigpatch.diffs = bigpatch.diffs[1:]
+					empty = false
+				} else if diffType == DiffDelete && len(patch.diffs) == 1 && patch.diffs[0].Type == DiffEqual && len(diffText) > 2*patchSize {
+					// This is a large deletion.  Let it pass in one chunk.
+					patch.length1 += len(diffText)
+					start1 += len(diffText)
+					empty = false
+					patch.diffs = append(patch.diffs, Diff{diffType, diffText})
+					bigpatch.diffs = bigpatch.diffs[1:]
+				} else {
+					// Deletion or equality.  Only take as much as we can stomach.
+					diffText = diffText[:min(len(diffText), patchSize-patch.length1-dmp.PatchMargin)]
+
+					patch.length1 += len(diffText)
+					start1 += len(diffText)
+					if diffType == DiffEqual {
+						patch.length2 += len(diffText)
+						start2 += len(diffText)
+					} else {
+						empty = false
+					}
+					patch.diffs = append(patch.diffs, Diff{diffType, diffText})
+					if diffText == bigpatch.diffs[0].Text {
+						bigpatch.diffs = bigpatch.diffs[1:]
+					} else {
+						bigpatch.diffs[0].Text =
+							bigpatch.diffs[0].Text[len(diffText):]
+					}
+				}
+			}
+			// Compute the head context for the next patch.
+			precontext = dmp.DiffText2(patch.diffs)
+			precontext = precontext[max(0, len(precontext)-dmp.PatchMargin):]
+
+			postcontext := ""
+			// Append the end context for this patch.
+			if len(dmp.DiffText1(bigpatch.diffs)) > dmp.PatchMargin {
+				postcontext = dmp.DiffText1(bigpatch.diffs)[:dmp.PatchMargin]
+			} else {
+				postcontext = dmp.DiffText1(bigpatch.diffs)
+			}
+
+			if len(postcontext) != 0 {
+				patch.length1 += len(postcontext)
+				patch.length2 += len(postcontext)
+				if len(patch.diffs) != 0 && patch.diffs[len(patch.diffs)-1].Type == DiffEqual {
+					patch.diffs[len(patch.diffs)-1].Text += postcontext
+				} else {
+					patch.diffs = append(patch.diffs, Diff{DiffEqual, postcontext})
+				}
+			}
+			if !empty {
+				x++
+				patches = append(patches[:x], append([]Patch{patch}, patches[x:]...)...)
+			}
+		}
+	}
+	return patches
+}
+
+// PatchToText takes a list of patches and returns a textual representation.
+func (dmp *DiffMatchPatch) PatchToText(patches []Patch) string {
+	var text bytes.Buffer
+	for _, aPatch := range patches {
+		_, _ = text.WriteString(aPatch.String())
+	}
+	return text.String()
+}
+
+// PatchFromText parses a textual representation of patches and returns a List of Patch objects.
+func (dmp *DiffMatchPatch) PatchFromText(textline string) ([]Patch, error) {
+	patches := []Patch{}
+	if len(textline) == 0 {
+		return patches, nil
+	}
+	text := strings.Split(textline, "\n")
+	textPointer := 0
+	patchHeader := regexp.MustCompile("^@@ -(\\d+),?(\\d*) \\+(\\d+),?(\\d*) @@$")
+
+	var patch Patch
+	var sign uint8
+	var line string
+	for textPointer < len(text) {
+
+		if !patchHeader.MatchString(text[textPointer]) {
+			return patches, errors.New("Invalid patch string: " + text[textPointer])
+		}
+
+		patch = Patch{}
+		m := patchHeader.FindStringSubmatch(text[textPointer])
+
+		patch.start1, _ = strconv.Atoi(m[1])
+		if len(m[2]) == 0 {
+			patch.start1--
+			patch.length1 = 1
+		} else if m[2] == "0" {
+			patch.length1 = 0
+		} else {
+			patch.start1--
+			patch.length1, _ = strconv.Atoi(m[2])
+		}
+
+		patch.start2, _ = strconv.Atoi(m[3])
+
+		if len(m[4]) == 0 {
+			patch.start2--
+			patch.length2 = 1
+		} else if m[4] == "0" {
+			patch.length2 = 0
+		} else {
+			patch.start2--
+			patch.length2, _ = strconv.Atoi(m[4])
+		}
+		textPointer++
+
+		for textPointer < len(text) {
+			if len(text[textPointer]) > 0 {
+				sign = text[textPointer][0]
+			} else {
+				textPointer++
+				continue
+			}
+
+			line = text[textPointer][1:]
+			line = strings.Replace(line, "+", "%2b", -1)
+			line, _ = url.QueryUnescape(line)
+			if sign == '-' {
+				// Deletion.
+				patch.diffs = append(patch.diffs, Diff{DiffDelete, line})
+			} else if sign == '+' {
+				// Insertion.
+				patch.diffs = append(patch.diffs, Diff{DiffInsert, line})
+			} else if sign == ' ' {
+				// Minor equality.
+				patch.diffs = append(patch.diffs, Diff{DiffEqual, line})
+			} else if sign == '@' {
+				// Start of next patch.
+				break
+			} else {
+				// WTF?
+				return patches, errors.New("Invalid patch mode '" + string(sign) + "' in: " + string(line))
+			}
+			textPointer++
+		}
+
+		patches = append(patches, patch)
+	}
+	return patches, nil
+}
diff --git a/diffmatchpatch/patch_test.go b/diffmatchpatch/patch_test.go
new file mode 100644
index 0000000..12d1441
--- /dev/null
+++ b/diffmatchpatch/patch_test.go
@@ -0,0 +1,334 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"fmt"
+	"strings"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestPatchString(t *testing.T) {
+	type TestCase struct {
+		Patch Patch
+
+		Expected string
+	}
+
+	for i, tc := range []TestCase{
+		{
+			Patch: Patch{
+				start1:  20,
+				start2:  21,
+				length1: 18,
+				length2: 17,
+
+				diffs: []Diff{
+					{DiffEqual, "jump"},
+					{DiffDelete, "s"},
+					{DiffInsert, "ed"},
+					{DiffEqual, " over "},
+					{DiffDelete, "the"},
+					{DiffInsert, "a"},
+					{DiffEqual, "\nlaz"},
+				},
+			},
+
+			Expected: "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n %0Alaz\n",
+		},
+	} {
+		actual := tc.Patch.String()
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestPatchFromText(t *testing.T) {
+	type TestCase struct {
+		Patch string
+
+		ErrorMessagePrefix string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"", ""},
+		{"@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n %0Alaz\n", ""},
+		{"@@ -1 +1 @@\n-a\n+b\n", ""},
+		{"@@ -1,3 +0,0 @@\n-abc\n", ""},
+		{"@@ -0,0 +1,3 @@\n+abc\n", ""},
+		{"Bad\nPatch\n", "Invalid patch string"},
+	} {
+		patches, err := dmp.PatchFromText(tc.Patch)
+		if tc.ErrorMessagePrefix == "" {
+			assert.Nil(t, err)
+
+			if tc.Patch == "" {
+				assert.Equal(t, []Patch{}, patches, fmt.Sprintf("Test case #%d, %#v", i, tc))
+			} else {
+				assert.Equal(t, tc.Patch, patches[0].String(), fmt.Sprintf("Test case #%d, %#v", i, tc))
+			}
+		} else {
+			e := err.Error()
+			if strings.HasPrefix(e, tc.ErrorMessagePrefix) {
+				e = tc.ErrorMessagePrefix
+			}
+			assert.Equal(t, tc.ErrorMessagePrefix, e)
+		}
+	}
+
+	diffs := []Diff{
+		{DiffDelete, "`1234567890-=[]\\;',./"},
+		{DiffInsert, "~!@#$%^&*()_+{}|:\"<>?"},
+	}
+
+	patches, err := dmp.PatchFromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n")
+	assert.Len(t, patches, 1)
+	assert.Equal(t, diffs,
+		patches[0].diffs,
+	)
+	assert.Nil(t, err)
+}
+
+func TestPatchToText(t *testing.T) {
+	type TestCase struct {
+		Patch string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"},
+		{"@@ -1,9 +1,9 @@\n-f\n+F\n oo+fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n  tes\n"},
+	} {
+		patches, err := dmp.PatchFromText(tc.Patch)
+		assert.Nil(t, err)
+
+		actual := dmp.PatchToText(patches)
+		assert.Equal(t, tc.Patch, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestPatchAddContext(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Patch string
+		Text  string
+
+		Expected string
+	}
+
+	dmp := New()
+	dmp.PatchMargin = 4
+
+	for i, tc := range []TestCase{
+		{"Simple case", "@@ -21,4 +21,10 @@\n-jump\n+somersault\n", "The quick brown fox jumps over the lazy dog.", "@@ -17,12 +17,18 @@\n fox \n-jump\n+somersault\n s ov\n"},
+		{"Not enough trailing context", "@@ -21,4 +21,10 @@\n-jump\n+somersault\n", "The quick brown fox jumps.", "@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n"},
+		{"Not enough leading context", "@@ -3 +3,2 @@\n-e\n+at\n", "The quick brown fox jumps.", "@@ -1,7 +1,8 @@\n Th\n-e\n+at\n  qui\n"},
+		{"Ambiguity", "@@ -3 +3,2 @@\n-e\n+at\n", "The quick brown fox jumps.  The quick brown fox crashes.", "@@ -1,27 +1,28 @@\n Th\n-e\n+at\n  quick brown fox jumps. \n"},
+	} {
+		patches, err := dmp.PatchFromText(tc.Patch)
+		assert.Nil(t, err)
+
+		actual := dmp.PatchAddContext(patches[0], tc.Text)
+		assert.Equal(t, tc.Expected, actual.String(), fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestPatchMakeAndPatchToText(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Input1 interface{}
+		Input2 interface{}
+		Input3 interface{}
+
+		Expected string
+	}
+
+	dmp := New()
+
+	text1 := "The quick brown fox jumps over the lazy dog."
+	text2 := "That quick brown fox jumped over a lazy dog."
+
+	for i, tc := range []TestCase{
+		{"Null case", "", "", nil, ""},
+		{"Text2+Text1 inputs", text2, text1, nil, "@@ -1,8 +1,7 @@\n Th\n-at\n+e\n  qui\n@@ -21,17 +21,18 @@\n jump\n-ed\n+s\n  over \n-a\n+the\n  laz\n"},
+		{"Text1+Text2 inputs", text1, text2, nil, "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"},
+		{"Diff input", dmp.DiffMain(text1, text2, false), nil, nil, "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"},
+		{"Text1+Diff inputs", text1, dmp.DiffMain(text1, text2, false), nil, "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"},
+		{"Text1+Text2+Diff inputs (deprecated)", text1, text2, dmp.DiffMain(text1, text2, false), "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"},
+		{"Character encoding", "`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?", nil, "@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n"},
+		{"Long string with repeats", strings.Repeat("abcdef", 100), strings.Repeat("abcdef", 100) + "123", nil, "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n"},
+		{"Corner case of #31 fixed by #32", "2016-09-01T03:07:14.807830741Z", "2016-09-01T03:07:15.154800781Z", nil, "@@ -15,16 +15,16 @@\n 07:1\n+5.15\n 4\n-.\n 80\n+0\n 78\n-3074\n 1Z\n"},
+	} {
+		var patches []Patch
+		if tc.Input3 != nil {
+			patches = dmp.PatchMake(tc.Input1, tc.Input2, tc.Input3)
+		} else if tc.Input2 != nil {
+			patches = dmp.PatchMake(tc.Input1, tc.Input2)
+		} else if ps, ok := tc.Input1.([]Patch); ok {
+			patches = ps
+		} else {
+			patches = dmp.PatchMake(tc.Input1)
+		}
+
+		actual := dmp.PatchToText(patches)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	// Corner case of #28 wrong patch with timeout of 0
+	dmp.DiffTimeout = 0
+
+	text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ut risus et enim consectetur convallis a non ipsum. Sed nec nibh cursus, interdum libero vel."
+	text2 = "Lorem a ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ut risus et enim consectetur convallis a non ipsum. Sed nec nibh cursus, interdum liberovel."
+
+	diffs := dmp.DiffMain(text1, text2, true)
+	// Additional check that the diff texts are equal to the originals even if we are using DiffMain with checklines=true #29
+	assert.Equal(t, text1, dmp.DiffText1(diffs))
+	assert.Equal(t, text2, dmp.DiffText2(diffs))
+
+	patches := dmp.PatchMake(text1, diffs)
+
+	actual := dmp.PatchToText(patches)
+	assert.Equal(t, "@@ -1,14 +1,16 @@\n Lorem \n+a \n ipsum do\n@@ -148,13 +148,12 @@\n m libero\n- \n vel.\n", actual)
+}
+
+func TestPatchSplitMax(t *testing.T) {
+	type TestCase struct {
+		Text1 string
+		Text2 string
+
+		Expected string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"abcdefghijklmnopqrstuvwxyz01234567890", "XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0", "@@ -1,32 +1,46 @@\n+X\n ab\n+X\n cd\n+X\n ef\n+X\n gh\n+X\n ij\n+X\n kl\n+X\n mn\n+X\n op\n+X\n qr\n+X\n st\n+X\n uv\n+X\n wx\n+X\n yz\n+X\n 012345\n@@ -25,13 +39,18 @@\n zX01\n+X\n 23\n+X\n 45\n+X\n 67\n+X\n 89\n+X\n 0\n"},
+		{"abcdef1234567890123456789012345678901234567890123456789012345678901234567890uvwxyz", "abcdefuvwxyz", "@@ -3,78 +3,8 @@\n cdef\n-1234567890123456789012345678901234567890123456789012345678901234567890\n uvwx\n"},
+		{"1234567890123456789012345678901234567890123456789012345678901234567890", "abc", "@@ -1,32 +1,4 @@\n-1234567890123456789012345678\n 9012\n@@ -29,32 +1,4 @@\n-9012345678901234567890123456\n 7890\n@@ -57,14 +1,3 @@\n-78901234567890\n+abc\n"},
+		{"abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1", "abcdefghij , h : 1 , t : 1 abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1", "@@ -2,32 +2,32 @@\n bcdefghij , h : \n-0\n+1\n  , t : 1 abcdef\n@@ -29,32 +29,32 @@\n bcdefghij , h : \n-0\n+1\n  , t : 1 abcdef\n"},
+	} {
+		patches := dmp.PatchMake(tc.Text1, tc.Text2)
+		patches = dmp.PatchSplitMax(patches)
+
+		actual := dmp.PatchToText(patches)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestPatchAddPadding(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text1 string
+		Text2 string
+
+		Expected            string
+		ExpectedWithPadding string
+	}
+
+	dmp := New()
+
+	for i, tc := range []TestCase{
+		{"Both edges full", "", "test", "@@ -0,0 +1,4 @@\n+test\n", "@@ -1,8 +1,12 @@\n %01%02%03%04\n+test\n %01%02%03%04\n"},
+		{"Both edges partial", "XY", "XtestY", "@@ -1,2 +1,6 @@\n X\n+test\n Y\n", "@@ -2,8 +2,12 @@\n %02%03%04X\n+test\n Y%01%02%03\n"},
+		{"Both edges none", "XXXXYYYY", "XXXXtestYYYY", "@@ -1,8 +1,12 @@\n XXXX\n+test\n YYYY\n", "@@ -5,8 +5,12 @@\n XXXX\n+test\n YYYY\n"},
+	} {
+		patches := dmp.PatchMake(tc.Text1, tc.Text2)
+
+		actual := dmp.PatchToText(patches)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+
+		dmp.PatchAddPadding(patches)
+
+		actualWithPadding := dmp.PatchToText(patches)
+		assert.Equal(t, tc.ExpectedWithPadding, actualWithPadding, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
+
+func TestPatchApply(t *testing.T) {
+	type TestCase struct {
+		Name string
+
+		Text1    string
+		Text2    string
+		TextBase string
+
+		Expected        string
+		ExpectedApplies []bool
+	}
+
+	dmp := New()
+	dmp.MatchDistance = 1000
+	dmp.MatchThreshold = 0.5
+	dmp.PatchDeleteThreshold = 0.5
+
+	for i, tc := range []TestCase{
+		{"Null case", "", "", "Hello world.", "Hello world.", []bool{}},
+		{"Exact match", "The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.", "The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.", []bool{true, true}},
+		{"Partial match", "The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.", "The quick red rabbit jumps over the tired tiger.", "That quick red rabbit jumped over a tired tiger.", []bool{true, true}},
+		{"Failed match", "The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.", "I am the very model of a modern major general.", "I am the very model of a modern major general.", []bool{false, false}},
+		{"Big delete, small Diff", "x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy", "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y", "xabcy", []bool{true, true}},
+		{"Big delete, big Diff 1", "x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy", "x12345678901234567890---------------++++++++++---------------12345678901234567890y", "xabc12345678901234567890---------------++++++++++---------------12345678901234567890y", []bool{false, true}},
+	} {
+		patches := dmp.PatchMake(tc.Text1, tc.Text2)
+
+		actual, actualApplies := dmp.PatchApply(patches, tc.TextBase)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+		assert.Equal(t, tc.ExpectedApplies, actualApplies, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.PatchDeleteThreshold = 0.6
+
+	for i, tc := range []TestCase{
+		{"Big delete, big Diff 2", "x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy", "x12345678901234567890---------------++++++++++---------------12345678901234567890y", "xabcy", []bool{true, true}},
+	} {
+		patches := dmp.PatchMake(tc.Text1, tc.Text2)
+
+		actual, actualApplies := dmp.PatchApply(patches, tc.TextBase)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+		assert.Equal(t, tc.ExpectedApplies, actualApplies, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchDistance = 0
+	dmp.MatchThreshold = 0.0
+	dmp.PatchDeleteThreshold = 0.5
+
+	for i, tc := range []TestCase{
+		{"Compensate for failed patch", "abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890", "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890", "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890", []bool{false, true}},
+	} {
+		patches := dmp.PatchMake(tc.Text1, tc.Text2)
+
+		actual, actualApplies := dmp.PatchApply(patches, tc.TextBase)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+		assert.Equal(t, tc.ExpectedApplies, actualApplies, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+
+	dmp.MatchThreshold = 0.5
+	dmp.MatchDistance = 1000
+
+	for i, tc := range []TestCase{
+		{"No side effects", "", "test", "", "test", []bool{true}},
+		{"No side effects with major delete", "The quick brown fox jumps over the lazy dog.", "Woof", "The quick brown fox jumps over the lazy dog.", "Woof", []bool{true, true}},
+		{"Edge exact match", "", "test", "", "test", []bool{true}},
+		{"Near edge exact match", "XY", "XtestY", "XY", "XtestY", []bool{true}},
+		{"Edge partial match", "y", "y123", "x", "x123", []bool{true}},
+	} {
+		patches := dmp.PatchMake(tc.Text1, tc.Text2)
+
+		actual, actualApplies := dmp.PatchApply(patches, tc.TextBase)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+		assert.Equal(t, tc.ExpectedApplies, actualApplies, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
+	}
+}
diff --git a/diffmatchpatch/stringutil.go b/diffmatchpatch/stringutil.go
new file mode 100644
index 0000000..265f29c
--- /dev/null
+++ b/diffmatchpatch/stringutil.go
@@ -0,0 +1,88 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"strings"
+	"unicode/utf8"
+)
+
+// unescaper unescapes selected chars for compatibility with JavaScript's encodeURI.
+// In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive.  Thus "%3F" would not be unescaped.  But this is ok because it is only called with the output of HttpUtility.UrlEncode which returns lowercase hex. Example: "%3f" -> "?", "%24" -> "$", etc.
+var unescaper = strings.NewReplacer(
+	"%21", "!", "%7E", "~", "%27", "'",
+	"%28", "(", "%29", ")", "%3B", ";",
+	"%2F", "/", "%3F", "?", "%3A", ":",
+	"%40", "@", "%26", "&", "%3D", "=",
+	"%2B", "+", "%24", "$", "%2C", ",", "%23", "#", "%2A", "*")
+
+// indexOf returns the first index of pattern in str, starting at str[i].
+func indexOf(str string, pattern string, i int) int {
+	if i > len(str)-1 {
+		return -1
+	}
+	if i <= 0 {
+		return strings.Index(str, pattern)
+	}
+	ind := strings.Index(str[i:], pattern)
+	if ind == -1 {
+		return -1
+	}
+	return ind + i
+}
+
+// lastIndexOf returns the last index of pattern in str, starting at str[i].
+func lastIndexOf(str string, pattern string, i int) int {
+	if i < 0 {
+		return -1
+	}
+	if i >= len(str) {
+		return strings.LastIndex(str, pattern)
+	}
+	_, size := utf8.DecodeRuneInString(str[i:])
+	return strings.LastIndex(str[:i+size], pattern)
+}
+
+// runesIndexOf returns the index of pattern in target, starting at target[i].
+func runesIndexOf(target, pattern []rune, i int) int {
+	if i > len(target)-1 {
+		return -1
+	}
+	if i <= 0 {
+		return runesIndex(target, pattern)
+	}
+	ind := runesIndex(target[i:], pattern)
+	if ind == -1 {
+		return -1
+	}
+	return ind + i
+}
+
+func runesEqual(r1, r2 []rune) bool {
+	if len(r1) != len(r2) {
+		return false
+	}
+	for i, c := range r1 {
+		if c != r2[i] {
+			return false
+		}
+	}
+	return true
+}
+
+// runesIndex is the equivalent of strings.Index for rune slices.
+func runesIndex(r1, r2 []rune) int {
+	last := len(r1) - len(r2)
+	for i := 0; i <= last; i++ {
+		if runesEqual(r1[i:i+len(r2)], r2) {
+			return i
+		}
+	}
+	return -1
+}
diff --git a/diffmatchpatch/stringutil_test.go b/diffmatchpatch/stringutil_test.go
new file mode 100644
index 0000000..ab2bc10
--- /dev/null
+++ b/diffmatchpatch/stringutil_test.go
@@ -0,0 +1,116 @@
+// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
+// https://github.com/sergi/go-diff
+// See the included LICENSE file for license details.
+//
+// go-diff is a Go implementation of Google's Diff, Match, and Patch library
+// Original library is Copyright (c) 2006 Google Inc.
+// http://code.google.com/p/google-diff-match-patch/
+
+package diffmatchpatch
+
+import (
+	"fmt"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRunesIndexOf(t *testing.T) {
+	type TestCase struct {
+		Pattern string
+		Start   int
+
+		Expected int
+	}
+
+	for i, tc := range []TestCase{
+		{"abc", 0, 0},
+		{"cde", 0, 2},
+		{"e", 0, 4},
+		{"cdef", 0, -1},
+		{"abcdef", 0, -1},
+		{"abc", 2, -1},
+		{"cde", 2, 2},
+		{"e", 2, 4},
+		{"cdef", 2, -1},
+		{"abcdef", 2, -1},
+		{"e", 6, -1},
+	} {
+		actual := runesIndexOf([]rune("abcde"), []rune(tc.Pattern), tc.Start)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestIndexOf(t *testing.T) {
+	type TestCase struct {
+		String   string
+		Pattern  string
+		Position int
+
+		Expected int
+	}
+
+	for i, tc := range []TestCase{
+		{"hi world", "world", -1, 3},
+		{"hi world", "world", 0, 3},
+		{"hi world", "world", 1, 3},
+		{"hi world", "world", 2, 3},
+		{"hi world", "world", 3, 3},
+		{"hi world", "world", 4, -1},
+		{"abbc", "b", -1, 1},
+		{"abbc", "b", 0, 1},
+		{"abbc", "b", 1, 1},
+		{"abbc", "b", 2, 2},
+		{"abbc", "b", 3, -1},
+		{"abbc", "b", 4, -1},
+		// The greek letter beta is the two-byte sequence of "\u03b2".
+		{"a\u03b2\u03b2c", "\u03b2", -1, 1},
+		{"a\u03b2\u03b2c", "\u03b2", 0, 1},
+		{"a\u03b2\u03b2c", "\u03b2", 1, 1},
+		{"a\u03b2\u03b2c", "\u03b2", 3, 3},
+		{"a\u03b2\u03b2c", "\u03b2", 5, -1},
+		{"a\u03b2\u03b2c", "\u03b2", 6, -1},
+	} {
+		actual := indexOf(tc.String, tc.Pattern, tc.Position)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
+
+func TestLastIndexOf(t *testing.T) {
+	type TestCase struct {
+		String   string
+		Pattern  string
+		Position int
+
+		Expected int
+	}
+
+	for i, tc := range []TestCase{
+		{"hi world", "world", -1, -1},
+		{"hi world", "world", 0, -1},
+		{"hi world", "world", 1, -1},
+		{"hi world", "world", 2, -1},
+		{"hi world", "world", 3, -1},
+		{"hi world", "world", 4, -1},
+		{"hi world", "world", 5, -1},
+		{"hi world", "world", 6, -1},
+		{"hi world", "world", 7, 3},
+		{"hi world", "world", 8, 3},
+		{"abbc", "b", -1, -1},
+		{"abbc", "b", 0, -1},
+		{"abbc", "b", 1, 1},
+		{"abbc", "b", 2, 2},
+		{"abbc", "b", 3, 2},
+		{"abbc", "b", 4, 2},
+		// The greek letter beta is the two-byte sequence of "\u03b2".
+		{"a\u03b2\u03b2c", "\u03b2", -1, -1},
+		{"a\u03b2\u03b2c", "\u03b2", 0, -1},
+		{"a\u03b2\u03b2c", "\u03b2", 1, 1},
+		{"a\u03b2\u03b2c", "\u03b2", 3, 3},
+		{"a\u03b2\u03b2c", "\u03b2", 5, 3},
+		{"a\u03b2\u03b2c", "\u03b2", 6, 3},
+	} {
+		actual := lastIndexOf(tc.String, tc.Pattern, tc.Position)
+		assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
+	}
+}
diff --git a/diffmatchpatch/speedtest1.txt b/testdata/speedtest1.txt
similarity index 100%
rename from diffmatchpatch/speedtest1.txt
rename to testdata/speedtest1.txt
diff --git a/diffmatchpatch/speedtest2.txt b/testdata/speedtest2.txt
similarity index 100%
rename from diffmatchpatch/speedtest2.txt
rename to testdata/speedtest2.txt