Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
simplify some, remove duplicate ExampleGetContextDiffString()
  • Loading branch information
martinlindhe committed Oct 21, 2016
commit ab6db4727bf1ee948cccbc8e0246d84bd758e984
16 changes: 8 additions & 8 deletions difflib/difflib.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ func (m *SequenceMatcher) chainB() {
m.bJunk = map[string]struct{}{}
if m.IsJunk != nil {
junk := m.bJunk
for s, _ := range b2j {
for s := range b2j {
if m.IsJunk(s) {
junk[s] = struct{}{}
}
}
for s, _ := range junk {
for s := range junk {
delete(b2j, s)
}
}
Expand All @@ -181,7 +181,7 @@ func (m *SequenceMatcher) chainB() {
popular[s] = struct{}{}
}
}
for s, _ := range popular {
for s := range popular {
delete(b2j, s)
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (m *SequenceMatcher) findLongestMatch(alo, ahi, blo, bhi int) Match {
for besti+bestsize < ahi && bestj+bestsize < bhi &&
!m.isBJunk(m.b[bestj+bestsize]) &&
m.a[besti+bestsize] == m.b[bestj+bestsize] {
bestsize += 1
bestsize++
}

// Now that we have a wholly interesting match (albeit possibly
Expand All @@ -285,7 +285,7 @@ func (m *SequenceMatcher) findLongestMatch(alo, ahi, blo, bhi int) Match {
for besti+bestsize < ahi && bestj+bestsize < bhi &&
m.isBJunk(m.b[bestj+bestsize]) &&
m.a[besti+bestsize] == m.b[bestj+bestsize] {
bestsize += 1
bestsize++
}

return Match{A: besti, B: bestj, Size: bestsize}
Expand Down Expand Up @@ -496,7 +496,7 @@ func (m *SequenceMatcher) QuickRatio() float64 {
}
avail[s] = n - 1
if n > 0 {
matches += 1
matches++
}
}
return calculateRatio(matches, len(m.a)+len(m.b))
Expand All @@ -520,7 +520,7 @@ func formatRangeUnified(start, stop int) string {
return fmt.Sprintf("%d", beginning)
}
if length == 0 {
beginning -= 1 // empty ranges begin at line just before the range
beginning-- // empty ranges begin at line just before the range
}
return fmt.Sprintf("%d,%d", beginning, length)
}
Expand Down Expand Up @@ -644,7 +644,7 @@ func formatRangeContext(start, stop int) string {
beginning := start + 1 // lines start numbering with one
length := stop - start
if length == 0 {
beginning -= 1 // empty ranges begin at line just before the range
beginning-- // empty ranges begin at line just before the range
}
if length <= 1 {
return fmt.Sprintf("%d", beginning)
Expand Down
39 changes: 2 additions & 37 deletions difflib/difflib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ group
}
}

func ExampleGetUnifiedDiffCode() {
func ExampleGetUnifiedDiffString() {
a := `one
two
three
Expand Down Expand Up @@ -138,7 +138,7 @@ four`
// -fmt.Printf("%s,%T",a,b)
}

func ExampleGetContextDiffCode() {
func ExampleGetContextDiffString() {
a := `one
two
three
Expand Down Expand Up @@ -175,41 +175,6 @@ four`
// four
}

func ExampleGetContextDiffString() {
a := `one
two
three
four`
b := `zero
one
tree
four`
diff := ContextDiff{
A: SplitLines(a),
B: SplitLines(b),
FromFile: "Original",
ToFile: "Current",
Context: 3,
Eol: "\n",
}
result, _ := GetContextDiffString(diff)
fmt.Printf(strings.Replace(result, "\t", " ", -1))
// Output:
// *** Original
// --- Current
// ***************
// *** 1,4 ****
// one
// ! two
// ! three
// four
// --- 1,4 ----
// + zero
// one
// ! tree
// four
}

func rep(s string, count int) string {
return strings.Repeat(s, count)
}
Expand Down