Add test to find out malformed separators. (#1564)
Fix all links failed the test.
This commit is contained in:
committed by
Avelino
parent
8065a515cc
commit
3d9d9d0d3c
32
repo_test.go
32
repo_test.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user