You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git_diff_test.go 804B

1234567891011121314151617181920212223242526272829
  1. package models
  2. import (
  3. dmp "github.com/sergi/go-diff/diffmatchpatch"
  4. "html/template"
  5. "testing"
  6. )
  7. func assertEqual(t *testing.T, s1 string, s2 template.HTML) {
  8. if s1 != string(s2) {
  9. t.Errorf("%s should be equal %s", s2, s1)
  10. }
  11. }
  12. func TestDiffToHtml(t *testing.T) {
  13. assertEqual(t, "foo <span class=\"added-code\">bar</span> biz", diffToHtml([]dmp.Diff{
  14. dmp.Diff{dmp.DiffEqual, "foo "},
  15. dmp.Diff{dmp.DiffInsert, "bar"},
  16. dmp.Diff{dmp.DiffDelete, " baz"},
  17. dmp.Diff{dmp.DiffEqual, " biz"},
  18. }, DIFF_LINE_ADD))
  19. assertEqual(t, "foo <span class=\"removed-code\">bar</span> biz", diffToHtml([]dmp.Diff{
  20. dmp.Diff{dmp.DiffEqual, "foo "},
  21. dmp.Diff{dmp.DiffDelete, "bar"},
  22. dmp.Diff{dmp.DiffInsert, " baz"},
  23. dmp.Diff{dmp.DiffEqual, " biz"},
  24. }, DIFF_LINE_DEL))
  25. }