yatwiki/diff/diff_test.go

61 lines
1.1 KiB
Go
Raw Normal View History

2017-07-11 06:08:03 +00:00
package diff_test
import (
"reflect"
"testing"
"code.ivysaur.me/yatwiki3/diff"
)
func TestDiff(t *testing.T) {
type testCase struct {
o, n []string
expect []diff.Instruction
}
testCases := []testCase{
2017-07-11 06:25:38 +00:00
2017-07-11 06:08:03 +00:00
{
[]string{},
[]string{},
[]diff.Instruction{},
},
{
[]string{"a"},
[]string{"b"},
[]diff.Instruction{
{diff.OP_REMOVED, []string{"a"}},
{diff.OP_INSERTED, []string{"b"}},
},
},
{
[]string{"a", "b", "c"},
[]string{"a", "b", "c", "d"},
[]diff.Instruction{
{diff.OP_UNCHANGED, []string{"a", "b", "c"}},
{diff.OP_INSERTED, []string{"d"}},
},
},
{
[]string{"a", "b", "c", "d"},
[]string{"a", "b", "X", "Y", "Z", "d"},
[]diff.Instruction{
{diff.OP_UNCHANGED, []string{"a", "b"}},
{diff.OP_REMOVED, []string{"c"}},
{diff.OP_INSERTED, []string{"X", "Y", "Z"}},
{diff.OP_UNCHANGED, []string{"d"}},
},
},
}
for _, testCase := range testCases {
output := diff.Diff(testCase.o, testCase.n)
if !reflect.DeepEqual(output, testCase.expect) {
t.Fail()
2017-07-11 06:25:38 +00:00
t.Errorf("==EXPECTED==\n%#v\n==GOT==\n%#v\n", testCase.expect, output)
2017-07-11 06:08:03 +00:00
}
}
}