Add test to find out malformed separators. (#1564)

Fix all links failed the test.
This commit is contained in:
Viet Hung Nguyen
2017-08-31 11:18:01 +07:00
committed by Avelino
parent 8065a515cc
commit 3d9d9d0d3c
2 changed files with 41 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"bytes"
"io/ioutil"
"regexp"
"sort"
"strings"
"testing"
@@ -39,6 +40,37 @@ func TestDuplicatedLinks(t *testing.T) {
})
}
var (
reContainsLink = regexp.MustCompile(`\* \[.*\]\(.*\)`)
reOnlyLink = regexp.MustCompile(`\* \[.*\]\(.*\)$`)
reLinkWithDescription = regexp.MustCompile(`\* \[.*\]\(.*\) - \S`)
)
// Test if an entry has description, it must be separated from link with ` - `
func TestSeparator(t *testing.T) {
var matched, containsLink, noDescription bool
input, err := ioutil.ReadFile("./README.md")
if err != nil {
panic(err)
}
lines := strings.Split(string(input), "\n")
for _, line := range lines {
line = strings.Trim(line, " ")
containsLink = reContainsLink.MatchString(line)
if containsLink {
noDescription = reOnlyLink.MatchString(line)
if noDescription {
continue
}
matched = reLinkWithDescription.MatchString(line)
if !matched {
t.Errorf("expected entry to be in form of `* [link] - description`, got '%s'", line)
}
}
}
}
func testList(t *testing.T, list *goquery.Selection) {
list.Find("ul").Each(func(_ int, items *goquery.Selection) {
testList(t, items)