in internal/chunkedfile/chunkedfile.go [58:110]
func Read(filename string, report Reporter) (chunks []Chunk) {
data, err := ioutil.ReadFile(filename)
if err != nil {
report.Errorf("%s", err)
return
}
linenum := 1
eol := "\n"
if runtime.GOOS == "windows" {
eol = "\r\n"
}
for i, chunk := range strings.Split(string(data), eol+"---"+eol) {
if debug {
fmt.Printf("chunk %d at line %d: %s\n", i, linenum, chunk)
}
// Pad with newlines so the line numbers match the original file.
src := strings.Repeat("\n", linenum-1) + chunk
wantErrs := make(map[int]*regexp.Regexp)
// Parse comments of the form:
// ### "expected error".
lines := strings.Split(chunk, "\n")
for j := 0; j < len(lines); j, linenum = j+1, linenum+1 {
line := lines[j]
hashes := strings.Index(line, "###")
if hashes < 0 {
continue
}
rest := strings.TrimSpace(line[hashes+len("###"):])
pattern, err := strconv.Unquote(rest)
if err != nil {
report.Errorf("\n%s:%d: not a quoted regexp: %s", filename, linenum, rest)
continue
}
rx, err := regexp.Compile(pattern)
if err != nil {
report.Errorf("\n%s:%d: %v", filename, linenum, err)
continue
}
wantErrs[linenum] = rx
if debug {
fmt.Printf("\t%d\t%s\n", linenum, rx)
}
}
linenum++
chunks = append(chunks, Chunk{src, filename, report, wantErrs})
}
return chunks
}