-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_test.go
108 lines (98 loc) · 2.5 KB
/
basic_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
package iokit
import (
"fmt"
"go4ml.xyz/fu"
"gotest.tools/assert"
"io/ioutil"
"math/rand"
"os"
"strings"
"testing"
)
func Test_Version(t *testing.T) {
assert.Assert(t, Version.Major() == 1)
assert.Assert(t, Version.Minor() == 0)
assert.Assert(t, Version.Patch() == 0)
assert.Assert(t, Version.String() == "1.0.0")
}
func Test_Open(t *testing.T) {
S := `test`
w, err := os.Create(CacheFile("go-iokit/tests/create.txt"))
assert.NilError(t, err)
_, err = w.WriteString(S)
assert.NilError(t, err)
err = w.Close()
assert.NilError(t, err)
r := File(CacheFile("go-iokit/tests/create.txt")).MustOpen()
defer r.Close()
x := r.MustReadAll()
assert.Assert(t, string(x) == S)
r2 := Cache("go-iokit/tests/create.txt").MustOpen()
defer r2.Close()
x = r2.MustReadAll()
assert.Assert(t, string(x) == S)
}
func Test_CreateOpen(t *testing.T) {
S := `test`
file := File(CacheFile("go-iokit/tests/createopen.txt"))
w, err := file.Create()
assert.NilError(t, err)
defer w.End()
_, err = w.Write([]byte(S))
assert.NilError(t, err)
err = w.Commit()
assert.NilError(t, err)
r, err := file.Open()
assert.NilError(t, err)
defer r.Close()
x, err := ioutil.ReadAll(r)
assert.NilError(t, err)
assert.Assert(t, string(x) == S)
}
func Test_CacheOpen(t *testing.T) {
S := `test`
file := Cache("go-iokit/tests/createopen.txt").File()
w, err := file.Create()
assert.NilError(t, err)
defer w.End()
_, err = w.Write([]byte(S))
assert.NilError(t, err)
err = w.Commit()
assert.NilError(t, err)
r, err := file.Open()
assert.NilError(t, err)
defer r.Close()
x, err := ioutil.ReadAll(r)
assert.NilError(t, err)
assert.Assert(t, string(x) == S)
}
func findSkills(s string) []string {
j := strings.Index(s, "SKILLS")
j = strings.Index(s[j:], "<!--") + j
k := strings.Index(s[j:], "-->") + j
return strings.Split(s[j+4:k], ",")
}
func Test_PathHttp(t *testing.T) {
cache := Cache("go-iokit/test_httppath.txt")
cache.Remove()
file := Url("http://sudachen.github.io/cv", cache)
r, err := file.Open()
assert.NilError(t, err)
defer r.Close()
x, err := ioutil.ReadAll(r)
assert.NilError(t, err)
u := findSkills(string(x))
assert.Assert(t, fu.Contains(u,"Go"))
r, err = Url("file://" + cache.Path()).Open()
assert.NilError(t, err)
defer r.Close()
x, err = ioutil.ReadAll(r)
assert.NilError(t, err)
u = findSkills(string(x))
assert.Assert(t, fu.Contains(u,"Go"))
}
func Test_StringIO(t *testing.T) {
S := fmt.Sprintf(`test text %v`, rand.Int())
r := StringIO(S).MustOpen()
assert.Assert(t, S == string(r.MustReadAll()))
}