forked from hmarr/codeowners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
64 lines (53 loc) · 1.37 KB
/
example_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
package codeowners_test
import (
"bytes"
"fmt"
"github.com/hmarr/codeowners"
)
func Example() {
f := bytes.NewBufferString("src/**/*.c @acme/c-developers")
ruleset, err := codeowners.ParseFile(f)
if err != nil {
panic(err)
}
match, err := ruleset.Match("src/foo.c")
fmt.Println(match.Owners)
match, err = ruleset.Match("src/foo.rs")
fmt.Println(match)
// Output:
// [@acme/c-developers]
// <nil>
}
func ExampleParseFile() {
f := bytes.NewBufferString("src/**/*.[hc] @acme/c-developers # C headers and source")
ruleset, err := codeowners.ParseFile(f)
if err != nil {
panic(err)
}
fmt.Println(len(ruleset))
fmt.Println(ruleset[0].RawPattern())
fmt.Println(ruleset[0].Owners[0].String())
fmt.Println(ruleset[0].Comment)
// Output:
// 1
// src/**/*.[hc]
// @acme/c-developers
// C headers and source
}
func ExampleRuleset_Match() {
f := bytes.NewBufferString("src/**/*.[hc] @acme/c-developers # C headers and source")
ruleset, _ := codeowners.ParseFile(f)
match, _ := ruleset.Match("src")
fmt.Println("src", match != nil)
match, _ = ruleset.Match("src/foo.c")
fmt.Println("src/foo.c", match != nil)
match, _ = ruleset.Match("src/foo/bar.h")
fmt.Println("src/foo/bar.h", match != nil)
match, _ = ruleset.Match("src/foo.rs")
fmt.Println("src/foo.rs", match != nil)
// Output:
// src false
// src/foo.c true
// src/foo/bar.h true
// src/foo.rs false
}