From 392c286db37eec28d1effcabacc6cfc450b82c66 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 31 Aug 2025 01:49:00 +0100 Subject: [PATCH] test(search): add tests for `AdvancedIssueSearchString` method Signed-off-by: Babak K. Shandiz --- pkg/search/query_test.go | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/pkg/search/query_test.go b/pkg/search/query_test.go index ddec211cb..064a11f28 100644 --- a/pkg/search/query_test.go +++ b/pkg/search/query_test.go @@ -78,6 +78,69 @@ func TestQueryString(t *testing.T) { } } +func TestAdvancedIssueSearchString(t *testing.T) { + tests := []struct { + name string + query Query + out string + }{ + { + name: "quotes keywords", + query: Query{ + Keywords: []string{"quote keywords"}, + }, + out: `"quote keywords"`, + }, + { + name: "quotes keywords that are qualifiers", + query: Query{ + Keywords: []string{"quote:keywords", "quote:multiword keywords"}, + }, + out: `quote:keywords quote:"multiword keywords"`, + }, + { + name: "quotes qualifiers", + query: Query{ + Qualifiers: Qualifiers{ + Label: []string{"quote qualifier"}, + }, + }, + out: `label:"quote qualifier"`, + }, + { + name: "special qualifiers when used once", + query: Query{ + Keywords: []string{"keyword"}, + Qualifiers: Qualifiers{ + Repo: []string{"foo/bar"}, + Is: []string{"private"}, + User: []string{"johndoe"}, + In: []string{"title"}, + }, + }, + out: `keyword in:title is:private repo:foo/bar user:johndoe`, + }, + { + name: "special qualifiers are OR-ed when used multiple times", + query: Query{ + Keywords: []string{"keyword"}, + Qualifiers: Qualifiers{ + Repo: []string{"foo/bar", "foo/baz"}, + Is: []string{"private", "public", "foo"}, // "foo" is to ensure only "public" and "private" are grouped + User: []string{"johndoe", "janedoe"}, + In: []string{"title", "body", "comments", "foo"}, // "foo" is to ensure only "title", "body", and "comments" are grouped + }, + }, + out: `keyword (in:title OR in:body OR in:comments) in:foo (is:private OR is:public) is:foo (repo:foo/bar OR repo:foo/baz) (user:johndoe OR user:janedoe)`, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.out, tt.query.AdvancedIssueSearchString()) + }) + } +} + func TestQualifiersMap(t *testing.T) { tests := []struct { name string