showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
highlight_test.go
851 B · 31 lines
1package render23import (4 "html"5 "regexp"6 "strings"7 "testing"8)910// TestHighlightKeepsText: the lines' text, joined, gives back the source,11// trailing blank lines included, so line counts are right.12func TestHighlightKeepsText(t *testing.T) {13 tags := regexp.MustCompile(`<[^>]*>`)14 for _, src := range []string{"a\nb", "a\nb\n", "a\n\n", "a\n\n\n", "\n", "\tif x {\n\t\treturn\n\t}\n", "<b>&</b>\n", "x\r\ny\r\n"} {15 var lines []string16 for _, l := range Highlight("f.go", "", src) {17 lines = append(lines, html.UnescapeString(tags.ReplaceAllString(string(l), "")))18 }19 nl := "\n"20 if strings.Contains(src, "\r\n") {21 nl = "\r\n" // chroma drops the \r22 }23 got := strings.Join(lines, nl)24 if strings.HasSuffix(src, "\n") {25 got += nl26 }27 if got != src {28 t.Errorf("%q: %d lines give back %q", src, len(lines), got)29 }30 }31}