Skip to content

Commit

Permalink
Add an additional test around Map and nil nodes
Browse files Browse the repository at this point in the history
This tests both deleting an entire document's children and skipping
over nil children in a document.
  • Loading branch information
nilium committed Sep 28, 2018
1 parent e6ce13f commit dd252e3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,31 @@ func TestWalkMapper(t *testing.T) {
}
}

func TestMapDelete(t *testing.T) {
const DocSource = `stmt 1; section arg {}`

defer setlogf(t)()

doc := mustParseNamed(t, "root.conf", DocSource)
err := Walk(doc, mapFunc(func(Node) (Node, error) { return nil, nil }))
if err != nil {
t.Fatalf("err = %v; want nil", err)
}

if got := doc.Children; len(got) != 0 {
t.Fatalf("children = %#v; want an empty slice", got)
}
}

func TestMapError(t *testing.T) {
const wantErrMessage = `[1:1:0] root.conf: stmt in main: expected error`
const DocSource = `stmt 1; section arg {}`

defer setlogf(t)()

doc := mustParseNamed(t, "root.conf", DocSource)
doc.Children = append([]Node{nil}, doc.Children...)

wantErr := errors.New("expected error")
err := Walk(doc, mapFunc(func(Node) (Node, error) { return nil, wantErr }))

Expand Down

0 comments on commit dd252e3

Please sign in to comment.