Skip to content

Commit

Permalink
Added IsEmptyLines.
Browse files Browse the repository at this point in the history
  • Loading branch information
janpfeifer committed Apr 5, 2024
1 parent b5e395d commit a47c72e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func handleExecuteRequest(msg kernel.Message, goExec *goexec.State) error {
if err := specialcmd.Parse(msg, goExec, true, lines, specialLines); err != nil {
executionErr = errors.WithMessagef(err, "executing special commands in cell")
}
hasMoreToRun := len(specialLines) < len(lines) || goExec.CellIsTest
hasMoreToRun := !goexec.IsEmptyLines(lines, specialLines) || goExec.CellIsTest
if executionErr == nil && !msg.Kernel().Interrupted.Load() && hasMoreToRun {
executionErr = goExec.ExecuteCell(msg, msg.Kernel().ExecCounter, lines, specialLines)
}
Expand Down
20 changes: 20 additions & 0 deletions internal/goexec/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/fs"
"math/rand"
"os"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -554,3 +555,22 @@ func (s *State) DefaultCellTestArgs() (args []string) {
klog.V(2).Infof("DefaultCellTestArgs: %v", args)
return
}

var regexpAllSpaces = regexp.MustCompile(`^\s*$`)

// IsEmptyLines returns true is all lines are marked to skip, or if all lines not marked as skip are empty.
func IsEmptyLines(lines []string, skipLines Set[int]) bool {
if len(skipLines) >= len(lines) {
return true
}
for ii, line := range lines {
if skipLines.Has(ii) {
continue
}
if len(line) == 0 || regexpAllSpaces.MatchString(line) {
continue
}
return false
}
return true
}

0 comments on commit a47c72e

Please sign in to comment.