This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace_test.go
96 lines (74 loc) · 2.28 KB
/
workspace_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
i3 "go.i3wm.org/i3/v4"
)
func newWs(t *testing.T, name string) workspace {
t.Helper()
return workspace{Workspace: i3.Workspace{Name: name}, extensionPrefix: "_"}
}
func TestWorkspace(t *testing.T) {
t.Run(`i3msg`, func(t *testing.T) {
original := i3msg
defer func() { i3msg = original }()
var cmd string
i3msg = func(i3cmd string) ([]i3.CommandResult, error) {
cmd = i3cmd
return nil, nil
}
t.Run(`focus`, func(t *testing.T) {
ws := newWs(t, `1:work`)
require.NoError(t, ws.Focus())
assert.Equal(t, `workspace 1:work`, cmd)
nextWs, err := ws.Extension()
require.NoError(t, err)
require.NoError(t, nextWs.Focus())
assert.Equal(t, `workspace _1:work`, cmd)
})
t.Run(`flip container`, func(t *testing.T) {
ws := newWs(t, `1:work`)
require.NoError(t, ws.FlipFocusedContainer())
assert.Equal(t, `move container to workspace 1:work`, cmd)
nextWs, err := ws.Extension()
require.NoError(t, err)
require.NoError(t, nextWs.FlipFocusedContainer())
assert.Equal(t, `move container to workspace _1:work`, cmd)
})
})
t.Run(`main`, func(t *testing.T) {
ws := newWs(t, "1:work")
t.Run(`predicates`, func(t *testing.T) {
assert.True(t, ws.IsMain())
assert.False(t, ws.IsExtension())
})
t.Run(`fails on another main`, func(t *testing.T) {
_, err := ws.Main()
assert.EqualError(t, err, "workspace num=0:name=1:work is already main")
})
t.Run(`returns extension`, func(t *testing.T) {
wsExt, err := ws.Extension()
require.NoError(t, err)
assert.True(t, wsExt.IsExtension() && !wsExt.IsMain())
assert.Equal(t, "_1:work", wsExt.Name)
})
})
t.Run(`extension`, func(t *testing.T) {
ws := newWs(t, "_1:work")
t.Run(`predicates`, func(t *testing.T) {
assert.True(t, ws.IsExtension())
assert.False(t, ws.IsMain())
})
t.Run(`fails on another extension`, func(t *testing.T) {
_, err := ws.Extension()
assert.EqualError(t, err, "workspace num=0:name=_1:work is already an extension")
})
t.Run(`returns main`, func(t *testing.T) {
wsMain, err := ws.Main()
require.NoError(t, err)
assert.True(t, wsMain.IsMain() && !wsMain.IsExtension())
assert.Equal(t, "1:work", wsMain.Name)
})
})
}