-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
48 lines (41 loc) · 855 Bytes
/
common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This is Free Software covered by the terms of the MIT license.
// See LICENSE file for details.
// Copyright 2017 by Intevation GmbH
// linkChildren repairs the parent/child relations.
package main
import (
"bytes"
"io"
"testing"
)
func linkChildren(n, p *node) {
if n != nil {
n.parent = p
for _, c := range n.children {
linkChildren(c, n)
}
}
}
type testCase struct {
have *node
want string
}
func runCases(
cases []testCase,
exporter func(*document, io.Writer, bool) error,
t *testing.T) {
var buf bytes.Buffer
var doc document
for i := range cases {
c := &cases[i]
buf.Reset()
linkChildren(c.have, nil)
doc.root = c.have
if err := exporter(&doc, &buf, false); err != nil {
t.Fatalf("failed: %v", err)
}
if got := buf.String(); got != c.want {
t.Errorf("got '%s': want '%s'\n", got, c.want)
}
}
}