-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
41 lines (35 loc) · 796 Bytes
/
Copy pathexample_test.go
File metadata and controls
41 lines (35 loc) · 796 Bytes
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
package regexcache_test
import (
"fmt"
"github.com/azghr/forge/regexcache"
)
func ExampleCache_MustCompile() {
cache := regexcache.New()
r := cache.MustCompile("^a.*z$")
fmt.Println(r.MatchString("abz"))
// Output: true
}
func ExampleCache_Compile() {
cache := regexcache.New()
r, err := cache.Compile("^[a-z]+$")
if err != nil {
fmt.Println("invalid regex")
return
}
fmt.Println(r.MatchString("hello"))
// Output: true
}
func ExampleCache_Compile_invalid() {
cache := regexcache.New()
_, err := cache.Compile("(foo")
if err != nil {
fmt.Println("invalid regex")
}
// Output: invalid regex
}
func ExampleNew_withMaxSize() {
cache := regexcache.New(regexcache.WithMaxSize(100))
r := cache.MustCompile("^[0-9]+$")
fmt.Println(r.MatchString("42"))
// Output: true
}