-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfsearch_test_example.go
51 lines (44 loc) · 1.05 KB
/
fsearch_test_example.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
package fsearch
import (
"fmt"
"testing"
)
func TestFSearchExample(t *testing.T) {
t.Run("test example", func(t *testing.T) {
const maxResultSize = 50 // the upper bound of matched results size
const pathSeparator = "/"
fs := New(pathSeparator, maxResultSize)
// add paths
path1 := "a/keyword/c"
path2 := "a/b/keyword"
err := fs.AddPath(path1)
if err != nil {
t.Fatal(err)
}
err = fs.AddPath(path2)
if err != nil {
t.Fatal(err)
}
// search for a key word
matchedPaths, err := fs.Search("keyword") // matchedPaths should contain both path1 and path2
if err != nil {
t.Fatal(err)
}
fmt.Printf("%+v", matchedPaths)
// move a path
err = fs.MovePath("a/keyword", "a/b/keyword") // "a/keyword", "a/keyword/c" will be under path2
if err != nil {
t.Fatal(err)
}
// rename a path
err = fs.RenamePath("a/b/keyword", "keyword2") // entry "a/b/keyword" is renamed to "a/b/keyword2"
if err != nil {
t.Fatal(err)
}
// delete paths
err = fs.DelPath("a/b/keyworde")
if err != nil {
t.Fatal(err)
}
})
}