Skip to content

Commit

Permalink
moved generic removeEmptyTokens func into a common package
Browse files Browse the repository at this point in the history
  • Loading branch information
Preslav Mihaylov committed Jul 18, 2020
1 parent 465c326 commit 8cd87dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 14 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Package common contains a bunch of small utility functions used throughout different independent other packages
package common

// RemoveEmptyTokens of a splitted string. Tokens such as "" are removed.
func RemoveEmptyTokens(ss []string) []string {
res := []string{}
for _, s := range ss {
if s != "" {
res = append(res, s)
}
}

return res
}
15 changes: 3 additions & 12 deletions testing/scenariobuilder/todoerr_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package scenariobuilder
import (
"fmt"
"strings"

"github.com/preslavmihaylov/todocheck/common"
)

func validateTodoErrs(programOutput string, scenarios []*TodoErrScenario) validateFunc {
return func() error {
chunks := removeEmptyTokens(strings.Split(programOutput, "\n\n"))
chunks := common.RemoveEmptyTokens(strings.Split(programOutput, "\n\n"))
if len(chunks) != len(scenarios) {
return fmt.Errorf("Invalid amount of todo errors detected.\nExpected: %d, Actual: %d\n\n"+
"(program output follows...)\n%s",
Expand All @@ -30,17 +32,6 @@ func validateTodoErrs(programOutput string, scenarios []*TodoErrScenario) valida
}
}

func removeEmptyTokens(ss []string) []string {
res := []string{}
for _, s := range ss {
if s != "" {
res = append(res, s)
}
}

return res
}

func indexOfMatchingTodoScenario(scenarios []*TodoErrScenario, target string) int {
for i := range scenarios {
if scenarios[i].String() == target {
Expand Down

0 comments on commit 8cd87dc

Please sign in to comment.