Files
himewiki/internal/format/diff_test.go

30 lines
1.2 KiB
Go
Raw Permalink Normal View History

2025-11-17 20:12:10 +09:00
package format
import "testing"
func TestDiff(t *testing.T) {
tests := []struct {
2025-11-21 23:32:55 +09:00
name string
text string
want string
2025-11-17 20:12:10 +09:00
}{
{"zero", "--- old\r\n+++ new\r\n", ""},
2025-12-01 20:38:13 +09:00
{"plus", "--- old\r\n+++ new\r\n+test\r\n", "<strong class=\"plus\">+</strong><strong class=\"plus-line\">test</strong><br />\n"},
{"minus", "--- old\r\n+++ new\r\n-test\r\n", "<em class=\"minus\">-</em><em class=\"minus-line\">test</em><br />\n"},
2025-11-17 20:12:10 +09:00
{"hunk", "--- old\r\n+++ new\r\n@@ -0,0 +0,0 @@\r\n", "<span class=\"hunk\">@@ -0,0 +0,0 @@</span><br />\n"},
{"text", "--- old\r\n+++ new\r\n test\r\n", "&nbsp;test<br />\n"},
2025-12-01 20:38:13 +09:00
{"plus indent", "--- old\r\n+++ new\r\n+ test\r\n", "<strong class=\"plus\">+</strong><strong class=\"plus-line\">&nbsp;&nbsp;test</strong><br />\n"},
{"minus indent", "--- old\r\n+++ new\r\n- test\r\n", "<em class=\"minus\">-</em><em class=\"minus-line\">&nbsp;&nbsp;test</em><br />\n"},
2025-11-18 18:49:40 +09:00
{"text indent", "--- old\r\n+++ new\r\n test\r\n", "&nbsp;&nbsp;&nbsp;test<br />\n"},
2025-11-17 20:12:10 +09:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Diff(tt.text)
if got != tt.want {
t.Errorf("Diff(\"%s\") = %s; want %s", tt.text, got, tt.want)
}
})
}
}