Skip to content

Commit

Permalink
fix: properly clear lines on final scan
Browse files Browse the repository at this point in the history
  • Loading branch information
joerdav committed Sep 16, 2024
1 parent b3eb0e1 commit 4b1c472
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func (p *parser) Parse() (tasks models.Tasks, err error) {
}

func (p *parser) scan() bool {
p.currentLine = p.nextLine
if p.reachedEnd {
return false
}
p.currentLine = p.nextLine
if !p.scanner.Scan() {
p.reachedEnd = true
p.nextLine = ""
return true
}
p.nextLine = p.scanner.Text()
Expand Down
21 changes: 17 additions & 4 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser

import (
"bufio"
"bytes"
_ "embed"
"errors"
Expand Down Expand Up @@ -132,7 +133,10 @@ func TestParseFileNoTasks(t *testing.T) {
}

func TestMultipleDirs(t *testing.T) {
p, _ := NewParser(strings.NewReader("dir: some dir"), "tasks")
var p parser
p.scanner = bufio.NewScanner(strings.NewReader("dir: some dir"))
p.scan()
p.scan()
p.currTask.Dir = "an existing dir"
_, err := p.parseAttribute()
if err == nil {
Expand All @@ -141,7 +145,10 @@ func TestMultipleDirs(t *testing.T) {
}

func TestInvalidRun(t *testing.T) {
p, _ := NewParser(strings.NewReader("run: never"), "tasks")
var p parser
p.scanner = bufio.NewScanner(strings.NewReader("run: never"))
p.scan()
p.scan()
_, err := p.parseAttribute()
if err == nil {
t.Fatal("expected error got nil")
Expand Down Expand Up @@ -222,7 +229,10 @@ some code
}

func TestMultipleCodeBlocks(t *testing.T) {
p, _ := NewParser(strings.NewReader("```\ncode\n```"), "tasks")
var p parser
p.scanner = bufio.NewScanner(strings.NewReader("```\ncode\n```"))
p.scan()
p.scan()
p.currTask.Script = "an existing script"
err := p.parseCodeBlock()
if err == nil {
Expand Down Expand Up @@ -371,7 +381,10 @@ func TestParseAttribute(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
p, _ := NewParser(strings.NewReader(tt.in), "tasks")
var p parser
p.scanner = bufio.NewScanner(strings.NewReader(tt.in))
p.scan()
p.scan()
ok, err := p.parseAttribute()
if err != nil {
t.Fatal(err)
Expand Down
3 changes: 2 additions & 1 deletion parser/testdata/till-eof.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ go run ./i18n/generate

### generate-all

Requires: generate-templ, generate-translations
RunDeps: async

Requires: generate-templ, generate-translations

0 comments on commit 4b1c472

Please sign in to comment.