test: Improve our test for long lines

This now allows long URL's to start part way through a sentence instead
of requiring them to start on the beginning of a new line.
This commit is contained in:
James Shubin
2020-04-03 01:15:08 -04:00
parent fc839d2983
commit c9d5c50402

View File

@@ -191,16 +191,25 @@ func IsWrappedProperly(lines []string, length int) error {
return fmt.Errorf("line %d contained multiple spaces", lineno) return fmt.Errorf("line %d contained multiple spaces", lineno)
} }
if len(line) > length && !IsSpecialLine(line) {
return fmt.Errorf("line %d is too long", lineno)
}
fields := strings.Fields(line) fields := strings.Fields(line)
if len(fields) == 0 { if len(fields) == 0 {
//continue // should not happen with above check //continue // should not happen with above check
return fmt.Errorf("line %d had an unexpected empty list of fields", lineno) return fmt.Errorf("line %d had an unexpected empty list of fields", lineno)
} }
lastIndex := len(fields) - 1
lastChunk := fields[lastIndex]
beginning := strings.Join(fields[0:lastIndex], " ")
// !strings.Contains(lastChunk, " ") // redundant
// Either of these conditions is a reason we can skip this test.
skip1 := IsSpecialLine(line)
skip2 := (len(beginning) <= length && IsSpecialLine(lastChunk))
if len(line) > length && (!skip1) && (!skip2) {
return fmt.Errorf("line %d is too long", lineno)
}
// If we have a new start word, then we don't need to reflow it // If we have a new start word, then we don't need to reflow it
// back to the previous line, and if not, then we check the fit. // back to the previous line, and if not, then we check the fit.
if !IsNewStart(fields[0]) && previous+len(" ")+len(fields[0]) <= length { if !IsNewStart(fields[0]) && previous+len(" ")+len(fields[0]) <= length {