From 7a35bef7ac9dd94216777466b8fcfb65243c865c Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 2 Jul 2024 13:24:55 -0400 Subject: [PATCH] test: Improve comment parser to skip code blocks It might be nicer to have some code blocks all by themselves on a single line. --- test/comment_parser.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/comment_parser.go b/test/comment_parser.go index 8e578d22..131f77b8 100644 --- a/test/comment_parser.go +++ b/test/comment_parser.go @@ -141,12 +141,12 @@ func Check(filename string) error { // TODO: how do we deal with multiline comments? if strings.HasPrefix(s, CommentMultilinePrefix) { - break // skip + break // skip to the end of this block } // skip the magic compiler comments if strings.HasPrefix(s, CommentGolangPrefix) { - break // skip + break // skip to the end of this block } if s != commentPrefixTrimmed && !strings.HasPrefix(s, CommentPrefix) { @@ -265,6 +265,9 @@ func IsNewStart(word string) bool { if IsNumberBullet(word) { return true } + if IsCodeBlock(word) { + return true + } return false } @@ -293,3 +296,11 @@ func IsNumberBullet(word string) bool { } return matched } + +// IsCodeBlock returns true if the word starts with a code block backtick. +func IsCodeBlock(word string) bool { + if strings.HasPrefix(word, "`") { + return true + } + return false +}