-
Notifications
You must be signed in to change notification settings - Fork 2
/
flatten_example_test.go
80 lines (67 loc) · 1.16 KB
/
flatten_example_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package karma_test
import (
"fmt"
"io"
"github.com/reconquest/karma-go"
)
func foo(a int) error {
return karma.Format(io.EOF, "eof or something")
}
func bar(quz int) error {
wox := quz * 2
err := foo(wox)
if err != nil {
return karma.
Describe("wox", wox).
Format(err, "foo")
}
return nil
}
func twix() error {
err := bar(42)
if err != nil {
return karma.Describe("barval", 42).Format(err, "bar")
}
return nil
}
func run() error {
err := twix()
if err != nil {
return karma.Format(err, "twix")
}
return nil
}
func ExampleFlatten() {
{
err := io.EOF
fmt.Println("regular:")
fmt.Println(err)
fmt.Println("flatten:")
fmt.Println(karma.Flatten(err))
}
{
err := run()
fmt.Println("regular (hierarchical):")
fmt.Println(err)
fmt.Println("flatten:")
fmt.Println(karma.Flatten(err))
}
// Output:
//
// regular:
// EOF
// flatten:
// EOF
// regular (hierarchical):
// twix
// └─ bar
// ├─ foo
// │ ├─ eof or something
// │ │ └─ EOF
// │ │
// │ └─ wox: 84
// │
// └─ barval: 42
// flatten:
// twix: bar: foo: eof or something: EOF | barval=42 wox=84
}