From 1e521f2136da04412f34cddd972a0c711f1dfe52 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 11 Jul 2017 18:08:03 +1200 Subject: [PATCH] diff: unit tests --- diff/diff_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 diff/diff_test.go 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) + } + } + +}