Skip to content

Commit 6a182ea

Browse files
author
Jia He
committed
chore: add example test
1 parent ce81f4b commit 6a182ea

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

fsearch_test_example.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

0 commit comments

Comments
 (0)