-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
biff_test.go
114 lines (78 loc) · 1.96 KB
/
biff_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package biff
import (
"testing"
)
func Test_isolation(t *testing.T) {
Alternative("test a", func(a *A) {
words := []string{}
words = append(words, a.Title)
a.AssertEqual(words, []string{"test a"})
a.Alternative("test a1", func(a *A) {
words = append(words, a.Title)
a.AssertEqual(words, []string{"test a", "test a1"})
})
a.Alternative("test a2", func(a *A) {
words = append(words, a.Title)
a.AssertEqual(words, []string{"test a", "test a2"})
})
})
}
func Test_scope(t *testing.T) {
sequence := []string{"zero"}
Alternative("test a", func(a *A) {
sequence = append(sequence, "one")
a.Alternative("test b", func(a *A) {
sequence = append(sequence, "two")
a.AssertEqual(sequence, []string{"zero", "one", "two"})
})
sequence := []string{"three"}
a.Alternative("test c", func(a *A) {
sequence = append(sequence, "four")
a.AssertEqual(sequence, []string{"three", "four"})
})
})
}
func Example_basicUsage() {
Alternative("Initial value", func(a *A) {
value := 10
a.AssertEqual(value, 10)
a.Alternative("Plus 50", func(a *A) {
// Here value == 10
value += 50
a.AssertEqual(value, 60)
})
a.Alternative("Multiply by 2", func(a *A) {
// Here value == 10 again (it is an alternative from the parent)
value *= 2
a.AssertEqual(value, 20)
})
})
// Output:
// Case: Initial value
// value is 10
// Case: Plus 50
// value is 60
// -------------------------------
// Case: Initial value
// value is 10
// Case: Multiply by 2
// value is 20
// -------------------------------
// Case: Initial value
// value is 10
// -------------------------------
}
func Test_trimMultiline(t *testing.T) {
Alternative("TrimMultiline", func(a *A) {
a.Alternative("empty", func(a *A) {
a.AssertEqual("", trimMultiline(""))
})
a.Alternative("multiple lines", func(a *A) {
a.AssertEqual(trimMultiline(`
one
two
three
`), "\none\ntwo\nthree\n\n")
})
})
}