-
Notifications
You must be signed in to change notification settings - Fork 0
/
golconv_test.go
50 lines (46 loc) · 1.3 KB
/
golconv_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
package golconv
import (
"testing"
)
func TestStringToInt(t *testing.T) {
if result := StringToInt("0", 1); result != 0 {
t.Fatal("StringToInt failed for 0")
}
if result := StringToInt("100", 1); result != 100 {
t.Fatal("StringToInt failed for 100")
}
if result := StringToInt("-1", 1); result != -1 {
t.Fatal("StringToInt failed for -1")
}
if result := StringToInt("-", 1); result != 1 {
t.Fatal("StringToInt failed for -")
}
}
func TestStringToUint64(t *testing.T) {
if result := StringToUint64("0", 1); result != 0 {
t.Fatal("StringToUint64 failed for 0")
}
if result := StringToUint64("100", 1); result != 100 {
t.Fatal("StringToUint64 failed for 100")
}
if result := StringToUint64("-1", 1); result < 0 {
t.Fatal("StringToUint64 failed for -1")
}
if result := StringToUint64("-", 1); result != 1 {
t.Fatal("StringToUint64 failed for -")
}
}
func TestStringToBool(t *testing.T) {
if result := StringToBool("false", true); result != false {
t.Fatal("StringToBool failed for false")
}
if result := StringToBool("true", false); result != true {
t.Fatal("StringToBool failed for true")
}
if result := StringToBool("0", true); result != true {
t.Fatal("StringToBool failed for 0")
}
if result := StringToBool("", true); result != true {
t.Fatal("StringToBool failed for <empty>")
}
}