File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ package fsearch
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+ )
7
+
8
+ func TestFSearchExample (t * testing.T ) {
9
+ t .Run ("test example" , func (t * testing.T ) {
10
+ const maxResultSize = 50 // the upper bound of matched results size
11
+ const pathSeparator = "/"
12
+ fs := New (pathSeparator , maxResultSize )
13
+
14
+ // add paths
15
+ path1 := "a/keyword/c"
16
+ path2 := "a/b/keyword"
17
+ err := fs .AddPath (path1 )
18
+ if err != nil {
19
+ t .Fatal (err )
20
+ }
21
+ err = fs .AddPath (path2 )
22
+ if err != nil {
23
+ t .Fatal (err )
24
+ }
25
+
26
+ // search for a key word
27
+ matchedPaths , err := fs .Search ("keyword" ) // matchedPaths should contain both path1 and path2
28
+ if err != nil {
29
+ t .Fatal (err )
30
+ }
31
+ fmt .Printf ("%+v" , matchedPaths )
32
+
33
+ // move a path
34
+ err = fs .MovePath ("a/keyword" , "a/b/keyword" ) // "a/keyword", "a/keyword/c" will be under path2
35
+ if err != nil {
36
+ t .Fatal (err )
37
+ }
38
+
39
+ // rename a path
40
+ err = fs .RenamePath ("a/b/keyword" , "keyword2" ) // entry "a/b/keyword" is renamed to "a/b/keyword2"
41
+ if err != nil {
42
+ t .Fatal (err )
43
+ }
44
+
45
+ // delete paths
46
+ err = fs .DelPath ("a/b/keyworde" )
47
+ if err != nil {
48
+ t .Fatal (err )
49
+ }
50
+ })
51
+ }
You can’t perform that action at this time.
0 commit comments