-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc_test.go
77 lines (67 loc) · 1.51 KB
/
misc_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
package wee
import (
"testing"
"github.com/pterm/pterm"
"github.com/stretchr/testify/suite"
)
type MiscSuite struct {
suite.Suite
}
func TestMisc(t *testing.T) {
suite.Run(t, new(MiscSuite))
}
func (s *MiscSuite) SetupSuite() {
}
func (s *MiscSuite) TearDownSuite() {
}
func (s *MiscSuite) Test_00_log() {
pterm.PrintDebugMessages = true
pterm.Debug.Printf("hello %s debug\n", "golang")
pterm.Description.Printf("hello %s description\n", "golang")
pterm.Info.Printf("hello %s info\n", "golang")
pterm.Warning.Printf("hello %s warning\n", "golang")
pterm.Error.Printf("hello %s error\n", "golang")
// pterm.Fatal.Printf("hello %s fatal\n", "golang")
}
func (s *MiscSuite) Test_01_strToNum() {
tests := []struct {
raw string
kept string
wantS string
wantF float64
}{
{"398 ofert pracy", "", "398", 398},
{"398.1 ofert pracy", ".", "398.1", 398.1},
{"ofert pracy", ".", "", 0},
{"1,398.1 ofert pracy", ".", "1398.1", 1398.1},
}
for _, tt := range tests {
v := StrToNumChars(tt.raw, tt.kept)
s.Equal(tt.wantS, v)
f := MustStrToFloat(tt.raw, tt.kept)
s.InEpsilon(tt.wantF, f, 0.002)
}
}
func (s *MiscSuite) TestUniqueName() {
tests := []struct {
raw string
want string
}{
{
raw: "https://en.wikipedia.org/wiki/Main_Page",
want: "wiki_Main_Page",
},
{
raw: "https://en.wikipedia.org",
want: "homepage",
},
{
raw: "https://en.wikipedia.org/",
want: "homepage",
},
}
for _, tt := range tests {
got := NameFromURL(tt.raw)
s.Equal(tt.want, got, tt.raw)
}
}