-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions for source and destination diff texts (#1)
- Loading branch information
1 parent
d0cc49b
commit 33820cf
Showing
2 changed files
with
201 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Package patience implements the Patience Diff algorithm. | ||
package patience | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestDiffText(t *testing.T) { | ||
type args struct { | ||
diffs []DiffLine | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "TestDiffText", | ||
args: args{ | ||
diffs: []DiffLine{ | ||
{ | ||
Type: Equal, | ||
Text: "a", | ||
}, | ||
{ | ||
Type: Insert, | ||
Text: "b", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "c", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "", | ||
}, | ||
{ | ||
Type: Delete, | ||
Text: "d", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "e", | ||
}, | ||
}, | ||
}, | ||
want: " a\n+b\n c\n\n-d\n e", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := DiffText(tt.args.diffs); got != tt.want { | ||
t.Errorf("DiffText() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDiffTextA(t *testing.T) { | ||
type args struct { | ||
diffs []DiffLine | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "TestDiffText", | ||
args: args{ | ||
diffs: []DiffLine{ | ||
{ | ||
Type: Equal, | ||
Text: "a", | ||
}, | ||
{ | ||
Type: Insert, | ||
Text: "b", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "c", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "", | ||
}, | ||
{ | ||
Type: Delete, | ||
Text: "d", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "e", | ||
}, | ||
}, | ||
}, | ||
want: " a\n c\n\n-d\n e", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := DiffTextA(tt.args.diffs); got != tt.want { | ||
t.Errorf("DiffTextA() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDiffTextB(t *testing.T) { | ||
type args struct { | ||
diffs []DiffLine | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "TestDiffText", | ||
args: args{ | ||
diffs: []DiffLine{ | ||
{ | ||
Type: Equal, | ||
Text: "a", | ||
}, | ||
{ | ||
Type: Insert, | ||
Text: "b", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "c", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "", | ||
}, | ||
{ | ||
Type: Equal, | ||
Text: "e", | ||
}, | ||
}, | ||
}, | ||
want: " a\n+b\n c\n\n e", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := DiffTextB(tt.args.diffs); got != tt.want { | ||
t.Errorf("DiffTextB() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |