@@ -303,3 +303,41 @@ func TestSaveWithMultipleSnippetFiles(t *testing.T) {
303
303
`
304
304
assert .Equal (t , want , string (data ))
305
305
}
306
+
307
+ func TestFilterByTags (t * testing.T ) {
308
+ snippets := & Snippets {
309
+ Snippets : []SnippetInfo {
310
+ {
311
+ Description : "Test snippet" ,
312
+ Command : "echo 'Hello, World!'" ,
313
+ Tag : []string {"test" },
314
+ Output : "Hello, World!" ,
315
+ },
316
+ {
317
+ Description : "Test snippet 2" ,
318
+ Command : "echo 'Hello, World 2!'" ,
319
+ Tag : []string {"test" , "test2" },
320
+ Output : "Hello, World 2!" ,
321
+ },
322
+ {
323
+ Description : "Test snippet 3" ,
324
+ Command : "echo 'Hello, World 3!'" ,
325
+ Tag : []string {"test" , "test3" },
326
+ Output : "Hello, World 3!" ,
327
+ },
328
+ },
329
+ }
330
+
331
+ // Filter by a single tag
332
+ filteredSnippets := snippets .FilterByTags ([]string {"test" })
333
+ assert .Len (t , filteredSnippets , 3 )
334
+ assert .Equal (t , "Test snippet" , filteredSnippets [0 ].Description )
335
+ assert .Equal (t , "Test snippet 2" , filteredSnippets [1 ].Description )
336
+
337
+ // Filter by multiple tags
338
+ filteredSnippets = snippets .FilterByTags ([]string {"test" , "test2" })
339
+ assert .Len (t , filteredSnippets , 3 )
340
+ assert .Equal (t , "Test snippet" , filteredSnippets [0 ].Description )
341
+ assert .Equal (t , "Test snippet 2" , filteredSnippets [1 ].Description )
342
+ assert .Equal (t , "Test snippet 3" , filteredSnippets [2 ].Description )
343
+ }
0 commit comments