MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / TestPerformSearchRegex

Function TestPerformSearchRegex

search_test.go:56–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestPerformSearchRegex(t *testing.T) {
57 // Create test buffer
58 testData := [][]string{
59 {"Name", "Email", "Age"},
60 {"John", "john@test.com", "25"},
61 {"Jane", "jane@example.org", "30"},
62 {"Bob", "bob123@test.com", "35"},
63 }
64
65 b, err := createNewBufferWithData(testData, false)
66 if err != nil {
67 t.Fatalf("Failed to create buffer: %v", err)
68 }
69
70 // Test regex pattern for email domains
71 results := performSearch(b, `@test\.com$`, true, false)
72 if len(results) != 2 { // john@test.com and bob123@test.com
73 t.Errorf("Expected 2 results for email regex, got %d", len(results))
74 }
75
76 // Test regex pattern for numbers at end
77 results = performSearch(b, `\d+$`, true, false)
78 if len(results) != 3 { // All age values (25, 30, 35)
79 t.Errorf("Expected 3 results for number regex, got %d", len(results))
80 }
81
82 // Test regex pattern - case sensitive
83 results = performSearch(b, `^J`, true, true)
84 if len(results) != 2 { // John and Jane
85 t.Errorf("Expected 2 results for '^J' regex, got %d", len(results))
86 }
87
88 // Test regex pattern - case insensitive
89 results = performSearch(b, `^j`, true, false)
90 if len(results) != 4 { // John, Jane, john@test.com, jane@example.org
91 t.Errorf("Expected 4 results for '^j' regex, got %d", len(results))
92 }
93
94 // Test invalid regex
95 results = performSearch(b, `[invalid(`, true, false)
96 if len(results) != 0 {
97 t.Errorf("Expected 0 results for invalid regex, got %d", len(results))
98 }
99
100 // Test regex OR pattern
101 results = performSearch(b, `John|Bob`, true, false)
102 if len(results) != 4 {
103 t.Errorf("Expected 4 results for 'John|Bob' regex, got %d", len(results))
104 }
105}
106
107func TestToLower(t *testing.T) {
108 tests := []struct {

Callers

nothing calls this directly

Calls 2

createNewBufferWithDataFunction · 0.85
performSearchFunction · 0.85

Tested by

no test coverage detected