@@ -7,24 +7,24 @@ import (
8func TestRegexCache(t *testing.T) {
8func TestRegexCache(t *testing.T) {
9 cache := newRegexCache()
9 cache := newRegexCache()
11 // Test basic caching
11 // Test basic caching
12 pattern := "test.*pattern"
12 pattern := "test.*pattern"
13 regex1, err := cache.get(pattern)
13 regex1, err := cache.get(pattern)
14 if err != nil {
14 if err != nil {
15 t.Fatalf("Failed to compile regex: %v", err)
15 t.Fatalf("Failed to compile regex: %v", err)
18 regex2, err := cache.get(pattern)
18 regex2, err := cache.get(pattern)
19 if err != nil {
19 if err != nil {
20 t.Fatalf("Failed to get cached regex: %v", err)
20 t.Fatalf("Failed to get cached regex: %v", err)
23 // Should be the same instance (cached)
23 // Should be the same instance (cached)
24 if regex1 != regex2 {
24 if regex1 != regex2 {
25 t.Error("Expected cached regex to be the same instance")
25 t.Error("Expected cached regex to be the same instance")
28 // Test that it actually works
28 // Test that it actually works
29 if !regex1.MatchString("test123pattern") {
29 if !regex1.MatchString("test123pattern") {
30 t.Error("Regex should match test string")
30 t.Error("Regex should match test string")
@@ -34,13 +34,13 @@ func TestRegexCache(t *testing.T) {
34func TestGlobToRegexCaching(t *testing.T) {
34func TestGlobToRegexCaching(t *testing.T) {
35 // Test that globToRegex uses pre-compiled regex
35 // Test that globToRegex uses pre-compiled regex
36 pattern1 := globToRegex("*.{js,ts}")
36 pattern1 := globToRegex("*.{js,ts}")
38 // Should not panic and should work correctly
38 // Should not panic and should work correctly
39 regex1, err := regexp.Compile(pattern1)
39 regex1, err := regexp.Compile(pattern1)
40 if err != nil {
40 if err != nil {
41 t.Fatalf("Failed to compile glob regex: %v", err)
41 t.Fatalf("Failed to compile glob regex: %v", err)
44 if !regex1.MatchString("test.js") {
44 if !regex1.MatchString("test.js") {
45 t.Error("Glob regex should match .js files")
45 t.Error("Glob regex should match .js files")
@@ -56,7 +56,7 @@ func TestGlobToRegexCaching(t *testing.T) {
56func BenchmarkRegexCacheVsCompile(b *testing.B) {
56func BenchmarkRegexCacheVsCompile(b *testing.B) {
57 cache := newRegexCache()
57 cache := newRegexCache()
58 pattern := "test.*pattern.*[0-9]+"
58 pattern := "test.*pattern.*[0-9]+"
60 b.Run("WithCache", func(b *testing.B) {
60 b.Run("WithCache", func(b *testing.B) {
61 for b.Loop() {
61 for b.Loop() {
62 _, err := cache.get(pattern)
62 _, err := cache.get(pattern)
@@ -65,7 +65,7 @@ func BenchmarkRegexCacheVsCompile(b *testing.B) {
69 b.Run("WithoutCache", func(b *testing.B) {
69 b.Run("WithoutCache", func(b *testing.B) {
70 for b.Loop() {
70 for b.Loop() {
71 _, err := regexp.Compile(pattern)
71 _, err := regexp.Compile(pattern)
@@ -74,4 +74,4 @@ func BenchmarkRegexCacheVsCompile(b *testing.B) {