-
Notifications
You must be signed in to change notification settings - Fork 18
/
result_test.go
120 lines (102 loc) · 2.84 KB
/
result_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
115
116
117
118
119
120
package floc
import (
"fmt"
"testing"
)
func TestResult_IsNone(t *testing.T) {
r := None
if r.IsNone() == false {
t.Fatalf("%s expects None but has %s", t.Name(), r.String())
} else if r.IsValid() == false {
t.Fatalf("%s expects None to be valid", t.Name())
}
}
func TestResult_IsCanceled(t *testing.T) {
r := Canceled
if r.IsCanceled() == false {
t.Fatalf("%s expects Canceled but has %s", t.Name(), r.String())
} else if r.IsValid() == false {
t.Fatalf("%s expects Canceled to be valid", t.Name())
}
}
func TestResult_IsCompleted(t *testing.T) {
r := Completed
if r.IsCompleted() == false {
t.Fatalf("%s expects Completed but has %s", t.Name(), r.String())
} else if r.IsValid() == false {
t.Fatalf("%s expects Completed to be valid", t.Name())
}
}
func TestResult_IsFailed(t *testing.T) {
r := Failed
if r.IsFailed() == false {
t.Fatalf("%s expects Failed but has %s", t.Name(), r.String())
} else if r.IsValid() == false {
t.Fatalf("%s expects Failed to be valid", t.Name())
}
}
func TestResult_IsValid(t *testing.T) {
const n = 1000
r := Result(n)
if r.IsValid() == true {
t.Fatalf("%s expects %s to be invalid", t.Name(), r.String())
}
s := fmt.Sprintf("Result(%d)", n)
if r.String() != s {
t.Fatalf("%s expects %s but has %s", t.Name(), s, r.String())
}
}
func TestResult_IsFinished(t *testing.T) {
if None.IsFinished() == true {
t.Fatalf("%s expects None to be not finished", t.Name())
}
if Completed.IsFinished() == false {
t.Fatalf("%s expects Completed to be finished", t.Name())
}
if Canceled.IsFinished() == false {
t.Fatalf("%s expects Canceled to be finished", t.Name())
}
if Failed.IsFinished() == false {
t.Fatalf("%s expects Failed to be finished", t.Name())
}
}
func TestResult_Mask(t *testing.T) {
var all = []Result{None, Completed, Canceled, Failed}
for _, result := range all {
mask := result.Mask()
for _, r := range all {
if r == result {
if !mask.IsMasked(r) {
t.Fatalf("%s expects result %s to be masked by %s", t.Name(), r.String(), mask.String())
}
} else {
if mask.IsMasked(r) {
t.Fatalf("%s expects result %s to be not masked by %s", t.Name(), r.String(), mask.String())
}
}
}
}
}
func TestResult_i32(t *testing.T) {
var n int32
for n = 0; n < 1000; n++ {
r := Result(n)
if r.i32() != n {
t.Fatalf("%s expects Result to be %d but has %d", t.Name(), n, r.i32())
}
}
}
func TestResult_String(t *testing.T) {
if None.String() != "None" {
t.Fatalf("%s expects None bu has %s", t.Name(), None.String())
}
if Completed.String() != "Completed" {
t.Fatalf("%s expects Completed bu has %s", t.Name(), Completed.String())
}
if Canceled.String() != "Canceled" {
t.Fatalf("%s expects Canceled bu has %s", t.Name(), Canceled.String())
}
if Failed.String() != "Failed" {
t.Fatalf("%s expects Failed bu has %s", t.Name(), Failed.String())
}
}