test(11.1-06): branch-level tests for every docsite stage (94.8% coverage)
- load, render, emit, snippet, highlight, serve and checker branch tests; docs:build --check, docs:sync and docs:serve output tests in cmd/summer - fix: a CRLF or BOM page is reported as such, not as a page without a frontmatter block (TestFrontmatterEncodingProblems) - fix: src=#Type.Method finds a method with a parenthesised receiver (TestSnippetGenericsAndGroups, Box.Paren) - fix: docs:serve adds its watches before announcing the server, so an edit made right after the serving line rebuilds (TestServeWatchRebuilds)
This commit is contained in:
@@ -369,7 +369,7 @@ func (s *site) loadGuides() ([]*Page, []Problem, error) {
|
||||
}
|
||||
fmRaw, body, bodyLine, ok := splitFrontmatter(raw)
|
||||
if !ok {
|
||||
fail(`the file must start with a "---" frontmatter block closed by a "---" line`)
|
||||
fail(frontmatterBlockProblem(raw))
|
||||
continue
|
||||
}
|
||||
fm, details := parseFrontmatter(fmRaw)
|
||||
@@ -488,6 +488,20 @@ func splitFrontmatter(raw []byte) (fm, body []byte, bodyLine int, ok bool) {
|
||||
return nil, nil, 0, false
|
||||
}
|
||||
|
||||
// frontmatterBlockProblem explains why a page has no frontmatter block. A
|
||||
// byte order mark or CRLF line endings hide a block the file does have, so
|
||||
// they are named instead of the missing block.
|
||||
func frontmatterBlockProblem(raw []byte) string {
|
||||
first, _, _ := bytes.Cut(raw, []byte("\n"))
|
||||
switch {
|
||||
case bytes.HasPrefix(raw, []byte("\xef\xbb\xbf")):
|
||||
return "the file starts with a UTF-8 byte order mark; save it without one"
|
||||
case bytes.HasSuffix(first, []byte("\r")):
|
||||
return "the file uses CRLF line endings; save it with LF line endings"
|
||||
}
|
||||
return `the file must start with a "---" frontmatter block closed by a "---" line`
|
||||
}
|
||||
|
||||
// parseFrontmatter decodes a frontmatter block strictly. It returns the
|
||||
// UI-SPEC problem details: unknown and missing fields first, then decode
|
||||
// errors.
|
||||
|
||||
Reference in New Issue
Block a user