-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnumentry_test.go
138 lines (115 loc) · 2.11 KB
/
numentry_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package wx
import (
"testing"
"fyne.io/fyne/v2/test"
)
func TestNumEntryType(t *testing.T) {
n := NewNumEntry()
test.Type(n, "some text with number in it 123\nother line without numbers...")
if n.Text != "123" {
t.Fatal("n.Text != 123")
}
if n.GetInt() != 123 {
t.Fatal("n.GetInt() != 123")
}
if n.GetFloat() != 123 {
t.Fatal("n.GetFloat() != 123")
}
}
func TestNumEntrySetText(t *testing.T) {
n := NewNumEntry()
n.SetText("some text with number in it 123\nother line without numbers...")
if n.Text != "123" {
t.Fatal("n.Text != 123")
}
if n.GetInt() != 123 {
t.Fatal("n.GetInt() != 123")
}
if n.GetFloat() != 123 {
t.Fatal("n.GetFloat() != 123")
}
n.SetText("45")
if n.Text != "45" {
t.Fatal("n.Text != 45")
}
}
func TestNumEntrySetInt(t *testing.T) {
n := NewNumEntry()
n.SetInt(123)
if n.Text != "123" {
t.Fatal("n.Text != 123")
}
if n.GetInt() != 123 {
t.Fatal("n.GetInt() != 123")
}
if n.GetFloat() != 123 {
t.Fatal("n.GetFloat() != 123")
}
}
func TestNumEntryOnChanged(t *testing.T) {
n := NewNumEntry()
n.Float = true
n.Signed = true
chkStr := ""
chkInt := 0
chkFlt := 0.0
n.OnChanged = func(s string) {
if s != chkStr {
t.Error("n.OnChanged != " + chkStr)
}
}
n.OnChangedInt = func(i int) {
if i != chkInt {
t.Errorf("n.OnChangedInt != %v", i)
}
}
n.OnChangedFloat = func(f float64) {
if f != chkFlt {
t.Errorf("n.OnChangedFloat != %v", f)
}
}
chkStr = "1"
chkInt = 1
chkFlt = 1.0
test.Type(n, "1")
chkStr = "12"
chkInt = 12
chkFlt = 12.0
test.Type(n, "2")
chkStr = "123"
chkInt = 123
chkFlt = 123.0
test.Type(n, "3")
chkStr = "123,"
chkInt = 123
chkFlt = 123.0
test.Type(n, ".")
chkStr = "123,5"
chkInt = 123
chkFlt = 123.5
test.Type(n, "5")
chkStr = "-123,5"
chkInt = -123
chkFlt = -123.5
test.Type(n, "-")
chkStr = "+123,5"
chkInt = 123
chkFlt = 123.5
test.Type(n, "+")
chkStr = "10"
chkInt = 10
chkFlt = 10
n.SetText("10")
chkStr = "-20"
chkInt = -20
chkFlt = -20.0
n.SetText("-20")
chkStr = "15"
chkInt = 15
chkFlt = 15
n.SetInt(15)
chkStr = "-30,5"
chkInt = -30
chkFlt = -30.5
n.SetFloat(-30.5)
}