mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-07 16:33:40 +00:00
markdown structure improvements
- removing duplicate content menu - enabling vscode editing with markdown lint on - previously it was automatically correcting the content menu swapping, messing up the order and making it fail the tests - markdown lint Signed-off-by: Avelino <avelinorun@gmail.com>
This commit is contained in:
parent
720deee8c6
commit
781ae15086
32
repo_test.go
32
repo_test.go
@ -10,40 +10,42 @@ import (
|
|||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
reContainsLink = regexp.MustCompile(`\* \[.*\]\(.*\)`)
|
||||||
|
reOnlyLink = regexp.MustCompile(`\* \[.*\]\([^()]*\)$`)
|
||||||
|
reLinkWithDescription = regexp.MustCompile(`\* \[.*\]\(.*\) - \S.*[\.\!]`)
|
||||||
|
)
|
||||||
|
|
||||||
func TestAlpha(t *testing.T) {
|
func TestAlpha(t *testing.T) {
|
||||||
query := startQuery()
|
query := startQuery()
|
||||||
|
query.Find("body > ul").Each(func(i int, s *goquery.Selection) {
|
||||||
query.Find("body > ul").Each(func(_ int, s *goquery.Selection) {
|
if i != 0 {
|
||||||
|
// skip content menu
|
||||||
|
// TODO: the sub items (with 3 hash marks `###`) are staying in
|
||||||
|
// the main list, not respecting the hierarchy and making it
|
||||||
|
// impossible to test the alphabetical order
|
||||||
testList(t, s)
|
testList(t, s)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDuplicatedLinks(t *testing.T) {
|
func TestDuplicatedLinks(t *testing.T) {
|
||||||
query := startQuery()
|
query := startQuery()
|
||||||
links := make(map[string]bool, 0)
|
links := make(map[string]bool, 0)
|
||||||
|
|
||||||
query.Find("body li > a:first-child").Each(func(_ int, s *goquery.Selection) {
|
query.Find("body li > a:first-child").Each(func(_ int, s *goquery.Selection) {
|
||||||
t.Run(s.Text(), func(t *testing.T) {
|
t.Run(s.Text(), func(t *testing.T) {
|
||||||
href, ok := s.Attr("href")
|
href, ok := s.Attr("href")
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("expected to have href")
|
t.Error("expected to have href")
|
||||||
}
|
}
|
||||||
|
|
||||||
if links[href] {
|
if links[href] {
|
||||||
t.Fatalf("duplicated link '%s'", href)
|
t.Fatalf("duplicated link '%s'", href)
|
||||||
}
|
}
|
||||||
|
|
||||||
links[href] = true
|
links[href] = true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
reContainsLink = regexp.MustCompile(`\* \[.*\]\(.*\)`)
|
|
||||||
reOnlyLink = regexp.MustCompile(`\* \[.*\]\([^()]*\)$`)
|
|
||||||
reLinkWithDescription = regexp.MustCompile(`\* \[.*\]\(.*\) - \S.*[\.\!]`)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Test if an entry has description, it must be separated from link with ` - `
|
// Test if an entry has description, it must be separated from link with ` - `
|
||||||
func TestSeparator(t *testing.T) {
|
func TestSeparator(t *testing.T) {
|
||||||
var matched, containsLink, noDescription bool
|
var matched, containsLink, noDescription bool
|
||||||
@ -60,7 +62,6 @@ func TestSeparator(t *testing.T) {
|
|||||||
if noDescription {
|
if noDescription {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
matched = reLinkWithDescription.MatchString(line)
|
matched = reLinkWithDescription.MatchString(line)
|
||||||
if !matched {
|
if !matched {
|
||||||
t.Errorf("expected entry to be in form of `* [link] - description.`, got '%s'", line)
|
t.Errorf("expected entry to be in form of `* [link] - description.`, got '%s'", line)
|
||||||
@ -80,10 +81,7 @@ func testList(t *testing.T, list *goquery.Selection) {
|
|||||||
testList(t, items)
|
testList(t, items)
|
||||||
items.RemoveFiltered("ul")
|
items.RemoveFiltered("ul")
|
||||||
})
|
})
|
||||||
|
t.Run(list.Prev().Text(), func(t *testing.T) {
|
||||||
category := list.Prev().Text()
|
|
||||||
|
|
||||||
t.Run(category, func(t *testing.T) {
|
|
||||||
checkAlphabeticOrder(t, list)
|
checkAlphabeticOrder(t, list)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -92,11 +90,9 @@ func checkAlphabeticOrder(t *testing.T, s *goquery.Selection) {
|
|||||||
items := s.Find("li > a:first-child").Map(func(_ int, li *goquery.Selection) string {
|
items := s.Find("li > a:first-child").Map(func(_ int, li *goquery.Selection) string {
|
||||||
return strings.ToLower(li.Text())
|
return strings.ToLower(li.Text())
|
||||||
})
|
})
|
||||||
|
|
||||||
sorted := make([]string, len(items))
|
sorted := make([]string, len(items))
|
||||||
copy(sorted, items)
|
copy(sorted, items)
|
||||||
sort.Strings(sorted)
|
sort.Strings(sorted)
|
||||||
|
|
||||||
for k, item := range items {
|
for k, item := range items {
|
||||||
if item != sorted[k] {
|
if item != sorted[k] {
|
||||||
t.Errorf("expected '%s' but actual is '%s'", sorted[k], item)
|
t.Errorf("expected '%s' but actual is '%s'", sorted[k], item)
|
||||||
|
Loading…
Reference in New Issue
Block a user