summaryrefslogtreecommitdiffstats
path: root/models/git_diff_test.go
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2016-01-03 19:26:46 -0200
committerAndrey Nering <andrey.nering@gmail.com>2016-01-06 17:46:56 -0200
commit73474c043bfdeeb33cd58bdfe42592fea3083422 (patch)
tree0aab45170a12b50e2f10c2125cb11ae18c879f87 /models/git_diff_test.go
parent0cb739684096396e26595ac70817a2a05b61b443 (diff)
downloadgitea-73474c043bfdeeb33cd58bdfe42592fea3083422.tar.gz
gitea-73474c043bfdeeb33cd58bdfe42592fea3083422.zip
Highlighting differences of lines in the diff view.
Diffstat (limited to 'models/git_diff_test.go')
-rw-r--r--models/git_diff_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/models/git_diff_test.go b/models/git_diff_test.go
new file mode 100644
index 0000000000..4f4d47bf9d
--- /dev/null
+++ b/models/git_diff_test.go
@@ -0,0 +1,29 @@
+package models
+
+import (
+ dmp "github.com/sergi/go-diff/diffmatchpatch"
+ "html/template"
+ "testing"
+)
+
+func assertEqual(t *testing.T, s1 string, s2 template.HTML) {
+ if s1 != string(s2) {
+ t.Errorf("%s should be equal %s", s2, s1)
+ }
+}
+
+func TestDiffToHtml(t *testing.T) {
+ assertEqual(t, "foo <span class=\"added-code\">bar</span> biz", diffToHtml([]dmp.Diff{
+ dmp.Diff{dmp.DiffEqual, "foo "},
+ dmp.Diff{dmp.DiffInsert, "bar"},
+ dmp.Diff{dmp.DiffDelete, " baz"},
+ dmp.Diff{dmp.DiffEqual, " biz"},
+ }, DIFF_LINE_ADD))
+
+ assertEqual(t, "foo <span class=\"removed-code\">bar</span> biz", diffToHtml([]dmp.Diff{
+ dmp.Diff{dmp.DiffEqual, "foo "},
+ dmp.Diff{dmp.DiffDelete, "bar"},
+ dmp.Diff{dmp.DiffInsert, " baz"},
+ dmp.Diff{dmp.DiffEqual, " biz"},
+ }, DIFF_LINE_DEL))
+}