-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabel_test.go
74 lines (65 loc) · 1.73 KB
/
label_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
package goey
import (
"math/rand"
"reflect"
"testing"
"testing/quick"
"bitbucket.org/rj/goey/base"
)
func labelValues(values []reflect.Value, rand *rand.Rand) {
const complexSize = 50
// This is copied from the testing/quick package, but modified somewhat.
// The function in the standard library will create strings using all
// code points in the range up to 0x10FFFF. This works fine on Linux,
// but on Windows unrecognized codepoints are replaced with 0xFFFD,
// which is appropriate but breaks the tests. Here, we restrict code
// points to ASCII less the control characters.
numChars := rand.Intn(complexSize)
codePoints := make([]rune, numChars)
for i := 0; i < numChars; i++ {
codePoints[i] = rune(0x20 + rand.Intn(0x7F-0x20))
}
values[0] = reflect.ValueOf(string(codePoints))
}
func TestLabelMount(t *testing.T) {
testingMountWidgets(t,
&Label{Text: "A"},
&Label{Text: "B"},
&Label{Text: "C"},
&Label{Text: ""},
&Label{Text: "ABCD\nEDFG"},
)
t.Run("QuickCheck", func(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
f := func(text string) bool {
return testingMountWidget(t, &Label{Text: text})
}
if err := quick.Check(f, &quick.Config{Values: labelValues}); err != nil {
t.Errorf("quick: %s", err)
}
})
}
func TestLabelClose(t *testing.T) {
testingCloseWidgets(t,
&Label{Text: "A"},
&Label{Text: "B"},
&Label{Text: "C"},
)
}
func TestLabelUpdateProps(t *testing.T) {
testingUpdateWidgets(t, []base.Widget{
&Label{Text: "A"},
&Label{Text: "B"},
&Label{Text: "C"},
&Label{Text: ""},
&Label{Text: "ABCD\nEDFG"},
}, []base.Widget{
&Label{Text: ""},
&Label{Text: "ABCD\nEDFG"},
&Label{Text: "AB"},
&Label{Text: "BC"},
&Label{Text: "CD"},
})
}