forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu_test.go
75 lines (61 loc) · 1.71 KB
/
menu_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
package fyne
import (
"reflect"
"testing"
)
func testFunc1() {}
func testFunc2() {}
func testFunc3() {}
func testFunc4() {}
var menuItemsTest = []struct {
Label string
Action func()
Item *MenuItem
}{
{"item1", testFunc1, &MenuItem{Label: "item1", Action: testFunc1}},
{"item2", testFunc2, &MenuItem{Label: "item2", Action: testFunc2}},
{"item3", testFunc3, &MenuItem{Label: "item3", Action: testFunc3}},
{"item4", testFunc4, &MenuItem{Label: "item4", Action: testFunc4}},
}
var menuTest = []struct {
Label string
}{
{"menu1"},
{"menu2"},
}
func TestNewMainMenu(t *testing.T) {
var items []*MenuItem
var menus []*Menu
for _, tt := range menuItemsTest {
t.Run(tt.Label, func(t *testing.T) {
item := NewMenuItem(tt.Label, tt.Action)
// Compare sprinted address
if reflect.ValueOf(item.Action) != reflect.ValueOf(tt.Action) {
t.Errorf("Expected %v but got %v", reflect.ValueOf(tt.Action), reflect.ValueOf(item.Action))
}
if item.Label != tt.Label {
t.Errorf("Expected %v but got %v", tt.Label, item.Label)
}
items = append(items, item)
})
}
if len(items) < 4 {
t.Errorf("Expected %d menu items but got %d", len(menuItemsTest), len(items))
}
for _, tt := range menuTest {
t.Run(tt.Label, func(t *testing.T) {
menu := NewMenu(tt.Label, items...)
if menu.Label != tt.Label {
t.Errorf("Expected menu label %s but got %s", tt.Label, menu.Label)
}
if !reflect.DeepEqual(menu.Items, items) {
t.Errorf("Expected items to resemble what was inputted, but got %v", menu.Items)
}
menus = append(menus, menu)
})
}
mm := NewMainMenu(menus...)
if !reflect.DeepEqual(mm.Items, menus) {
t.Errorf("Expected main menu to contain all submenus but got %v", mm.Items)
}
}