diff: unit tests

This commit is contained in:
mappu 2017-07-11 18:08:03 +12:00
parent 1938e659ab
commit 1e521f2136

60
diff/diff_test.go Normal file
View File

@ -0,0 +1,60 @@
package diff_test
import (
"fmt"
"reflect"
"testing"
"code.ivysaur.me/yatwiki3/diff"
)
func TestDiff(t *testing.T) {
type testCase struct {
o, n []string
expect []diff.Instruction
}
testCases := []testCase{
{
[]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()
fmt.Printf("==EXPECTED==\n%#v\n==GOT==\n%#v\n", testCase.expect, output)
}
}
}