summaryrefslogtreecommitdiffstats
path: root/src/go/pkg/matcher/doc_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/pkg/matcher/doc_test.go')
-rw-r--r--src/go/pkg/matcher/doc_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/go/pkg/matcher/doc_test.go b/src/go/pkg/matcher/doc_test.go
new file mode 100644
index 000000000..46c7467ac
--- /dev/null
+++ b/src/go/pkg/matcher/doc_test.go
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package matcher_test
+
+import (
+ "github.com/netdata/netdata/go/plugins/pkg/matcher"
+)
+
+func ExampleNew_string_format() {
+ // create a string matcher, which perform full text match
+ m, err := matcher.New(matcher.FmtString, "hello")
+ if err != nil {
+ panic(err)
+ }
+ m.MatchString("hello") // => true
+ m.MatchString("hello world") // => false
+}
+
+func ExampleNew_glob_format() {
+ // create a glob matcher, which perform wildcard match
+ m, err := matcher.New(matcher.FmtString, "hello*")
+ if err != nil {
+ panic(err)
+ }
+ m.MatchString("hello") // => true
+ m.MatchString("hello world") // => true
+ m.MatchString("Hello world") // => false
+}
+
+func ExampleNew_simple_patterns_format() {
+ // create a simple patterns matcher, which perform wildcard match
+ m, err := matcher.New(matcher.FmtSimplePattern, "hello* !*world *")
+ if err != nil {
+ panic(err)
+ }
+ m.MatchString("hello") // => true
+ m.MatchString("hello world") // => true
+ m.MatchString("Hello world") // => false
+ m.MatchString("Hello world!") // => false
+}
+
+func ExampleNew_regexp_format() {
+ // create a regexp matcher, which perform wildcard match
+ m, err := matcher.New(matcher.FmtRegExp, "[0-9]+")
+ if err != nil {
+ panic(err)
+ }
+ m.MatchString("1") // => true
+ m.MatchString("1a") // => true
+ m.MatchString("a") // => false
+}