-
Notifications
You must be signed in to change notification settings - Fork 0
/
promise_test.go
45 lines (40 loc) · 1.14 KB
/
promise_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
/**********************************************************\
* *
* promise/promise_test.go *
* *
* promise test for Go. *
* *
* LastModified: Aug 13, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
package promise
import (
"fmt"
"testing"
)
func TestNew(t *testing.T) {
p := New()
if p.State() != PENDING {
t.Error("p.State must be PENDING")
}
}
func TestResolve(t *testing.T) {
p := Resolve(123)
if p.State() != FULFILLED {
t.Error("p.State must be FULFILLED")
}
if v, _ := p.Get(); v.(int) != 123 {
t.Error("p.Get value be 123")
}
}
func TestAll(t *testing.T) {
p := All(Resolve(1), 2, Resolve(3))
if v, err := p.Get(); err == nil {
if fmt.Sprintf("%v", v) != "[1 2 3]" {
t.Error("v must be [1 2 3]")
}
} else {
t.Error(err)
}
}