Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

the ecosystem may now suggest projects based on name similarity #47

Closed
wants to merge 3 commits into from

3 participants

@timo
Collaborator

currently only compares the names case-insensitively and removes
all -, _ and : before comparing.

@timo timo the ecosystem may now suggest projects based on name similarity
currently only compares the names case-insensitively and removes
all -, _ and : before comparing.
0e28b81
@leto
Collaborator

I like this, but can you please add some tests?

@tadzik
Owner

It's merged now, github didn't notice. Thanks!

@tadzik tadzik closed this
@tadzik tadzik referenced this pull request
Closed

Did you mean...? #16

@timo timo deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 24, 2013
  1. @timo

    the ecosystem may now suggest projects based on name similarity

    timo authored
    currently only compares the names case-insensitively and removes
    all -, _ and : before comparing.
  2. @timo
Commits on May 25, 2013
  1. @timo
This page is out of date. Refresh to see the latest.
View
8 lib/Panda.pm
@@ -118,8 +118,12 @@ class Panda {
$.ecosystem.add-project($p);
$proj = $p.name;
}
- my $bone = $.ecosystem.get-project($proj)
- or die "Project $proj not found in the ecosystem";
+ my $bone = $.ecosystem.get-project($proj);
+ if not $bone {
+ my $suggestion = $.ecosystem.suggest-project($proj);
+ die "Project $proj not found in the ecosystem. Maybe you meant $suggestion?" if $suggestion;
+ die "Project $proj not found in the ecosystem";
+ }
unless $nodeps {
my @deps = self.get-deps($bone).uniq;
@deps.=grep: {
View
9 lib/Panda/Ecosystem.pm
@@ -73,6 +73,15 @@ class Panda::Ecosystem {
%!projects{$p}
}
+ method suggest-project($p as Str) {
+ my &canonical = *.subst(/ <[\- _ :]>+ /, "", :g).lc;
+ my $cpname = canonical($p);
+ for %!projects.keys {
+ return $_ if canonical($_) eq $cpname;
+ }
+ return Nil;
+ }
+
method project-get-state(Panda::Project $p) {
%!states{$p.name} // Panda::Project::absent
}
View
8 t/ecosystem.t
@@ -1,7 +1,7 @@
use Test;
use Panda::Ecosystem;
use Panda::Project;
-plan 9;
+plan 14;
my $absent = Panda::Project::absent;
my $installed = Panda::Project::installed;
@@ -33,6 +33,12 @@ is $b.dependencies[0], 'some', 'dependencies 1';
is $b.dependencies[1], 'thing', 'dependencies 2';
is $b.dependencies[2], 'else', 'dependencies 3';
+is $a.suggest-project("Frob-Frob"), "Frob::Frob", 'suggestions 1';
+is $a.suggest-project("Frob_Frob"), "Frob::Frob", 'suggestions 2';
+is $a.suggest-project("frobfrob"), "Frob::Frob", 'suggestions 3';
+is $a.suggest-project("Adventure::Engine"), "Adventure-Engine", 'suggestions 4';
+is $a.suggest-project("Adventure_engine"), "Adventure-Engine", 'suggestions 5';
+
unlink "{cwd}/REMOVEME";
# vim: ft=perl6
View
4 t/fakeprojects
@@ -4,5 +4,7 @@
"depends" : [ "some", "thing", "else" ]
},
{ "name" : "bar", "version" : "2", "source-type" : "hg" },
- { "name" : "baz", "version" : "3" }
+ { "name" : "baz", "version" : "3" },
+ { "name" : "Frob::Frob", "version" : "2", "source-type" : "hg" },
+ { "name" : "Adventure-Engine", "version" : "5" }
]
Something went wrong with that request. Please try again.