From 92cb9c797ab121f19afbe164e74241f6979b61cd Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 28 Nov 2019 18:10:11 +0100 Subject: [PATCH 1/2] extend search fields for libs, added tests --- commands/lib/search.go | 5 ++++- test/test_lib.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/commands/lib/search.go b/commands/lib/search.go index 5b14a3f25bb..6214591f6ce 100644 --- a/commands/lib/search.go +++ b/commands/lib/search.go @@ -37,7 +37,10 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library res := []*rpc.SearchedLibrary{} for _, lib := range lm.Index.Libraries { - if strings.Contains(strings.ToLower(lib.Name), strings.ToLower(req.GetQuery())) { + qry := strings.ToLower(req.GetQuery()) + if strings.Contains(strings.ToLower(lib.Name), qry) || + strings.Contains(strings.ToLower(lib.Latest.Paragraph), qry) || + strings.Contains(strings.ToLower(lib.Latest.Sentence), qry) { releases := map[string]*rpc.LibraryRelease{} for str, rel := range lib.Releases { releases[str] = GetLibraryParameters(rel) diff --git a/test/test_lib.py b/test/test_lib.py index 22f7fbff525..8e73afd34a0 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -106,3 +106,17 @@ def test_search(run_command): assert result.ok libs_json = json.loads(result.stdout) assert 1 == len(libs_json.get("libraries")) + + +def test_search_paragraph(run_command): + """ + Search for a string that's only present in the `paragraph` field + within the index file. + """ + assert run_command("lib update-index") + result = run_command( + 'lib search "An efficient and elegant JSON library" --format json' + ) + assert result.ok + libs_json = json.loads(result.stdout) + assert 1 == len(libs_json.get("libraries")) From 25087c27cc734f1b5cdba1eaf9158201938586f5 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Fri, 29 Nov 2019 09:35:01 +0100 Subject: [PATCH 2/2] adjust tests --- test/test_lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_lib.py b/test/test_lib.py index 8e73afd34a0..6323e849e66 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -105,7 +105,7 @@ def test_search(run_command): result = run_command("lib search ArduinoJson --format json") assert result.ok libs_json = json.loads(result.stdout) - assert 1 == len(libs_json.get("libraries")) + assert len(libs_json.get("libraries")) >= 1 def test_search_paragraph(run_command):