-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathscene_test.go
62 lines (57 loc) · 1.29 KB
/
scene_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
package oak
import (
"context"
"errors"
"testing"
"github.com/oakmound/oak/v4/oakerr"
"github.com/oakmound/oak/v4/scene"
)
func TestSceneTransition(t *testing.T) {
c1 := NewWindow()
c1.AddScene("1", scene.Scene{
Start: func(context *scene.Context) {
go context.Window.NextScene()
},
End: func() (nextScene string, result *scene.Result) {
return "2", &scene.Result{
Transition: scene.Fade(1, 10),
}
},
})
c1.AddScene("2", scene.Scene{
Start: func(context *scene.Context) {
context.Window.Quit()
},
})
c1.Init("1")
}
func TestLoadingSceneClaimed(t *testing.T) {
c1 := NewWindow()
c1.AddScene(oakLoadingScene, scene.Scene{})
err := c1.Init("1")
var wantErr oakerr.ExistingElement
if !errors.As(err, &wantErr) {
t.Fatalf("expected existing element error, got %v", err)
}
}
func TestSceneGoTo(t *testing.T) {
c1 := NewWindow()
var cancel func()
c1.ParentContext, cancel = context.WithCancel(c1.ParentContext)
c1.AddScene("1", scene.Scene{
Start: func(context *scene.Context) {
context.Window.GoToScene("good")
},
End: func() (nextScene string, result *scene.Result) {
return "bad", &scene.Result{
Transition: scene.Fade(1, 10),
}
},
})
c1.AddScene("good", scene.Scene{
Start: func(ctx *scene.Context) {
cancel()
},
})
c1.Init("1")
}