diff --git a/diff/diff_test.go b/diff/diff_test.go new file mode 100644 index 0000000..27f2910 --- /dev/null +++ b/diff/diff_test.go @@ -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) + } + } + +}