Преглед на файлове

skip empty lines to avoid issue of #630 (#631)

* skip empty lines to avoid issue of #630

* add tests on empty lines and comms
Thibault "bui" Koechlin преди 4 години
родител
ревизия
a3d00fe130
променени са 3 файла, в които са добавени 21 реда и са изтрити 0 реда
  1. 3 0
      pkg/exprhelpers/exprlib.go
  2. 6 0
      pkg/exprhelpers/exprlib_test.go
  3. 12 0
      pkg/exprhelpers/tests/test_empty_line.txt

+ 3 - 0
pkg/exprhelpers/exprlib.go

@@ -73,6 +73,9 @@ func FileInit(fileFolder string, filename string, fileType string) error {
 		if strings.HasPrefix(scanner.Text(), "#") { // allow comments
 			continue
 		}
+		if len(scanner.Text()) == 0 { //skip empty lines
+			continue
+		}
 		switch fileType {
 		case "regex", "regexp":
 			dataFileRegex[filename] = append(dataFileRegex[filename], regexp.MustCompile(scanner.Text()))

+ 6 - 0
pkg/exprhelpers/exprlib_test.go

@@ -178,6 +178,12 @@ func TestFileInit(t *testing.T) {
 			types:    "string",
 			result:   3,
 		},
+		{
+			name:     "file with type:string and empty lines + commentaries",
+			filename: "test_empty_line.txt",
+			types:    "string",
+			result:   3,
+		},
 		{
 			name:     "file with type:re",
 			filename: "test_data_re.txt",

+ 12 - 0
pkg/exprhelpers/tests/test_empty_line.txt

@@ -0,0 +1,12 @@
+foo
+
+#toto
+
+
+bar
+
+
+
+
+
+baz