Skip to content

Commit

Permalink
Alr.Commands.Search: use a set rather than a vector for matching props
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Chouteau committed Feb 22, 2024
1 parent f30cba6 commit 2f80399
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/alire/alire-releases.adb
Original file line number Diff line number Diff line change
Expand Up @@ -924,9 +924,9 @@ package body Alire.Releases is
-----------------------

function Property_Contains (R : Release; Str : String)
return AAA.Strings.Vector
return AAA.Strings.Set
is
Results : AAA.Strings.Vector;
Results : AAA.Strings.Set;
use AAA.Strings;

Search : constant String := To_Lower_Case (Str);
Expand All @@ -941,12 +941,12 @@ package body Alire.Releases is
Value : constant String := Trim (Tail (Image, ':'));
begin
if Contains (To_Lower_Case (Value), Search) then
Results.Append (Prop);
Results.Include (Prop);
end if;
end;
else
if Contains (To_Lower_Case (Image), Search) then
Results.Append (Image);
Results.Include (Image);
end if;
end if;
end;
Expand Down
5 changes: 2 additions & 3 deletions src/alire/alire-releases.ads
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ package Alire.Releases is
-- True if some property contains the given string

function Property_Contains (R : Release; Str : String)
return AAA.Strings.Vector;
-- Return a vector with the names of propreties that contain the given
-- string.
return AAA.Strings.Set;
-- Return a set with the names of propeties that contain the given string

function Satisfies (R : Release;
Dep : Alire.Dependencies.Dependency'Class)
Expand Down
28 changes: 14 additions & 14 deletions src/alr/alr-commands-search.adb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ package body Alr.Commands.Search is
-------------------

procedure Print_Release (R : Alire.Releases.Release;
Match_Locations : AAA.Strings.Vector)
Match_Locations : AAA.Strings.Set)
is
package Solver renames Alire.Solver;

Expand All @@ -63,7 +63,7 @@ package body Alr.Commands.Search is
Tab.Append (TTY.Version (Semantic_Versioning.Image (R.Version)));
Tab.Append (TTY.Description (R.Description));
Tab.Append (R.Notes);
Tab.Append (Match_Locations.Flatten (", "));
Tab.Append (Match_Locations.To_Vector.Flatten (", "));
end Print_Release;

-----------------
Expand All @@ -72,16 +72,16 @@ package body Alr.Commands.Search is

function Match_Crate (Crate : Alire.Crates.Crate;
Pattern : String)
return AAA.Strings.Vector
return AAA.Strings.Set
is
Match_Locations : AAA.Strings.Vector;
Match_Locations : AAA.Strings.Set;
begin
if AAA.Strings.Contains (+Crate.Name, Pattern) then
Match_Locations.Append ("Name");
Match_Locations.Include ("Name");
end if;

if AAA.Strings.Contains (Crate.Description, Pattern) then
Match_Locations.Append ("Description");
Match_Locations.Include ("Description");
end if;
return Match_Locations;
end Match_Crate;
Expand All @@ -90,18 +90,18 @@ package body Alr.Commands.Search is
-- Filter_Release --
--------------------

procedure Filter_Release (R : Alire.Releases.Release;
procedure Filter_Release (R : Alire.Releases.Release;
Pattern : String)
is
begin
Trace.Debug ("Listing release: " & R.Milestone.TTY_Image);

if Pattern = "" then
-- Empty pattern means include everything
Print_Release (R, Match_Locations => AAA.Strings.Empty_Vector);
Print_Release (R, Match_Locations => AAA.Strings.Empty_Set);
else
declare
Match_Locations : constant AAA.Strings.Vector
Match_Locations : constant AAA.Strings.Set
:= R.Property_Contains (Pattern);
begin
if not Match_Locations.Is_Empty
Expand All @@ -119,8 +119,8 @@ package body Alr.Commands.Search is
--------------------

procedure Print_External (Name : Alire.Crate_Name;
Ext : Alire.Externals.External'Class;
Match_Locations : AAA.Strings.Vector)
Ext : Alire.Externals.External'Class;
Match_Locations : AAA.Strings.Set)
is
begin
Found := Found + 1;
Expand All @@ -132,7 +132,7 @@ package body Alr.Commands.Search is
Tab.Append ("external");
Tab.Append (Alire.Index.Crate (Name).TTY_Description);
Tab.Append (Ext.Image);
Tab.Append (Match_Locations.Flatten (", "));
Tab.Append (Match_Locations.To_Vector.Flatten (", "));
end Print_External;

begin
Expand Down Expand Up @@ -209,7 +209,7 @@ package body Alr.Commands.Search is
-- List_All_Or_Latest --
------------------------

procedure List_All_Or_Latest (Crate : Alire.Crates.Crate;
procedure List_All_Or_Latest (Crate : Alire.Crates.Crate;
Pattern : String)
is
Progress : Trace.Ongoing :=
Expand Down Expand Up @@ -238,7 +238,7 @@ package body Alr.Commands.Search is
Trace.Activity (Crate.Name.Index_Prefix)
with Unreferenced;

Match_Locations : constant AAA.Strings.Vector :=
Match_Locations : constant AAA.Strings.Set :=
Match_Crate (Crate, Pattern);
begin
if Cmd.External
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name = "libhello"
version = "1.0.0"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]
tags = ["libhello-tag1"]

# for an `alr search` test we need multiple tags that match the same pattern
tags = ["libhello-tag1", "libhello-tag2"]

[configuration.variables]
Var1={type="Boolean", default=true}
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/search/basic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def format_table(*args):
assert_eq('libhello "Hello, world!" demonstration project support library\n', p.out)


# Then on all properties
p = run_alr('search', 'libhello-tag1')
# Then on all properties, matching properties name should appear only once
p = run_alr('search', 'libhello-tag')
assert_eq(format_table(
('libhello', '', '1.0.0',
'"Hello, world!" demonstration project support library', '', 'Tag'),
Expand Down

0 comments on commit 2f80399

Please sign in to comment.