-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpkgtrim_test.go
More file actions
56 lines (49 loc) · 1.85 KB
/
pkgtrim_test.go
File metadata and controls
56 lines (49 loc) · 1.85 KB
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
// Note that most tests are done in dump.go.
// This contains effect tests for simpler functionality.
package main
import (
"os"
"testing"
"github.com/ypsu/efftesting"
)
func TestAbspath(t *testing.T) {
et := efftesting.New(t)
wd = "/home/user/"
et.Expect("empty", abspath(""), "home/user")
et.Expect("root", abspath("/"), "")
et.Expect("abs under wd", abspath("/home/user/.pkgtrim"), "home/user/.pkgtrim")
et.Expect("abs not under wd", abspath("/var/lib/package"), "var/lib/package")
et.Expect("relative under wd", abspath("settings/pkgtrim"), "home/user/settings/pkgtrim")
et.Expect("relative not under wd", abspath("../../var/lib/package"), "var/lib/package")
}
func TestHumanize(t *testing.T) {
et := efftesting.New(t)
et.Expect("", humanize(0), " 0.0 MB")
et.Expect("", humanize(-1), " -0.0 MB")
et.Expect("", humanize(-123456), " -0.1 MB")
et.Expect("", humanize(1), " 0.0 MB")
et.Expect("", humanize(12), " 0.0 MB")
et.Expect("", humanize(123), " 0.0 MB")
et.Expect("", humanize(1234), " 0.0 MB")
et.Expect("", humanize(12345), " 0.0 MB")
et.Expect("", humanize(123456), " 0.1 MB")
et.Expect("", humanize(1234567), " 1.2 MB")
et.Expect("", humanize(12345678), " 12.3 MB")
et.Expect("", humanize(123456789), " 123.5 MB")
et.Expect("", humanize(1234567890), " 1234.6 MB")
et.Expect("", humanize(12345678901), "12345.7 MB")
et.Expect("", humanize(123456789012), "123456.8 MB")
et.Expect("", humanize(1234567890123), "1234567.9 MB")
et.Expect("", humanize(12345678901234), "12345678.9 MB")
}
func TestGlobs(t *testing.T) {
et := efftesting.New(t)
et.Expect("", makeRE(), "^()$")
et.Expect("", makeRE("a"), "^(a)$")
et.Expect("", makeRE("a*b"), "^(a.*b)$")
et.Expect("", makeRE("a", "b", "c"), "^(a|b|c)$")
et.Expect("", makeRE("a", "b*", "c"), "^(a|b.*|c)$")
}
func TestMain(m *testing.M) {
os.Exit(efftesting.Main(m))
}