-
Notifications
You must be signed in to change notification settings - Fork 0
/
xFileUtil_test.go
74 lines (63 loc) · 1.92 KB
/
xFileUtil_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
//(c) softland 2019-2023
//softlandia@gmail.com
package xlib
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
//
func TestReadFileStop(t *testing.T) {
s, err := ReadFileStop("", "")
assert.Nil(t, err)
assert.Empty(t, s)
_, err = ReadFileStop("utils.go", "")
assert.Nil(t, err)
_, err = ReadFileStop("", "*")
assert.NotNil(t, err)
s, err = ReadFileStop("test_files/empty_file.txt", "*")
assert.Nil(t, err)
assert.Equal(t, 0, len(s))
s, err = ReadFileStop("test_files/rune_encode_error.txt", "4")
assert.Nil(t, err)
assert.Equal(t, "123", s)
s, err = ReadFileStop("test_files/2line.txt", " ")
assert.Nil(t, err)
assert.Equal(t, "1234", s)
}
//SeekFileToString
func TestSeekFileStop(t *testing.T) {
_, _, err := SeekFileStop("-.-", "-")
assert.NotNil(t, err)
index, scanner, _ := SeekFileStop("test_files/866&1251.txt", "~A")
assert.NotNil(t, scanner)
scanner.Scan()
assert.Equal(t, "<OK>", scanner.Text())
index, _, _ = SeekFileStop("test_files/866&1251.txt", "")
assert.Less(t, index, 0, fmt.Sprintf("1: %d", index))
index, _, _ = SeekFileStop("test_files/empty_file.txt", "~")
assert.Less(t, index, 0, fmt.Sprintf("2: %d", index))
index, _, err = SeekFileStop("test_files/rune_error_1251.txt", "#")
assert.Nil(t, err)
assert.Equal(t, 1, index)
}
//FileExists
func TestFileExists(t *testing.T) {
if FileExists("test_files") {
t.Errorf("<FileExist> return true on folder")
}
if FileExists("-.-") {
t.Errorf("<FileExists> return true on non exist file '-.-'")
}
if !FileExists("test_files/866&1251.txt") || !FileExists("test_files/2line.txt") || !FileExists("test_files/empty_file.txt") {
t.Error("<FileExists> return false on exist files: 866&1251.txt, 866to1251.txt, empty_file.txt")
}
}
//FindFilesExt
func TestFindFilesExt(t *testing.T) {
_, err := FindFilesExt(nil, ".", "txt")
assert.NotNil(t, err)
fl := make([]string, 0, 10)
n, _ := FindFilesExt(&fl, ".", ".txt")
assert.Equal(t, n, 5)
}