| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package matcher_test |
| 4 | |
| 5 | import ( |
| 6 | "github.com/netdata/netdata/go/plugins/pkg/matcher" |
| 7 | ) |
| 8 | |
| 9 | func ExampleNew_string_format() { |
| 10 | // create a string matcher, which perform full text match |
| 11 | m, err := matcher.New(matcher.FmtString, "hello") |
| 12 | if err != nil { |
| 13 | panic(err) |
| 14 | } |
| 15 | m.MatchString("hello") // => true |
| 16 | m.MatchString("hello world") // => false |
| 17 | } |
| 18 | |
| 19 | func ExampleNew_glob_format() { |
| 20 | // create a glob matcher, which perform wildcard match |
| 21 | m, err := matcher.New(matcher.FmtString, "hello*") |
| 22 | if err != nil { |
| 23 | panic(err) |
| 24 | } |
| 25 | m.MatchString("hello") // => true |
| 26 | m.MatchString("hello world") // => true |
| 27 | m.MatchString("Hello world") // => false |
| 28 | } |
| 29 | |
| 30 | func ExampleNew_simple_patterns_format() { |
| 31 | // create a simple patterns matcher, which perform wildcard match |
| 32 | m, err := matcher.New(matcher.FmtSimplePattern, "hello* !*world *") |
| 33 | if err != nil { |
| 34 | panic(err) |
| 35 | } |
| 36 | m.MatchString("hello") // => true |
| 37 | m.MatchString("hello world") // => true |
| 38 | m.MatchString("Hello world") // => false |
| 39 | m.MatchString("Hello world!") // => false |
| 40 | } |
| 41 | |
| 42 | func ExampleNew_regexp_format() { |
| 43 | // create a regexp matcher, which perform wildcard match |
| 44 | m, err := matcher.New(matcher.FmtRegExp, "[0-9]+") |
| 45 | if err != nil { |
| 46 | panic(err) |
| 47 | } |
| 48 | m.MatchString("1") // => true |
| 49 | m.MatchString("1a") // => true |
| 50 | m.MatchString("a") // => false |
| 51 | } |