- Timestamp:
- Dec 28, 2009, 12:03:29 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- dc8f6e0
- Parents:
- 880311d
- git-author:
- Nelson Elhage <nelhage@mit.edu> (12/27/09 23:48:30)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (12/28/09 00:03:29)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
t/completion.t
r1167bf1 re6cec01 289 289 \&complete_filter_expr); 290 290 291 # Test complete_files 292 use BarnOwl::Completion::Util qw(complete_file); 293 use File::Temp; 294 use File::Path qw(mkpath); 295 296 my $tmpdir = File::Temp::tempdir(CLEANUP => 1); 297 298 # Make sure $tmpdir does not have a trailing / 299 $tmpdir =~ s{/$}{}; 300 $ENV{HOME} = $tmpdir; 301 302 sub touch { 303 my $path = shift; 304 system("touch", "$path"); 305 } 306 307 mkpath("$tmpdir/.owl/", 308 "$tmpdir/.owl/modules/", 309 "$tmpdir/Public/", 310 "$tmpdir/Private/", 311 "$tmpdir/.ours", 312 "$tmpdir/www"); 313 touch("$tmpdir/.zephyr.subs"); 314 touch("$tmpdir/wheee"); 315 touch("$tmpdir/.owl/startup"); 316 317 sub completion_value { 318 my $c = shift; 319 return $c unless ref($c) eq 'ARRAY'; 320 return $c->[1]; 321 } 322 323 sub test_file { 324 my $spec = shift; 325 my $pfx = shift; 326 my $dirs = shift; 327 my $files = shift; 328 329 my $expect = [ sort {$a->[1] cmp $b->[1]} 330 ((map {["$_/", defined($pfx)?"$pfx/$_/":"$_/", 0]} @$dirs), 331 (map {["$_", defined($pfx)?"$pfx/$_" :$_ , 1]} @$files)) 332 ]; 333 334 local $Test::Builder::Level = $Test::Builder::Level + 1; 335 336 my @got = complete_file($spec); 337 338 @got = grep {completion_value($_) =~ m{^\Q$spec\E}} @got; 339 @got = sort {completion_value($a) cmp completion_value($b)} @got; 340 341 use Data::Dumper; 342 is_deeply(\@got, $expect); 343 } 344 345 is_deeply([complete_file("~")], [["~/", "~/", 0]]); 346 347 chdir($tmpdir); 348 test_file("$tmpdir/", $tmpdir, 349 [qw(Public Private www)], 350 [qw(wheee)]); 351 352 test_file("./", ".", 353 [qw(Public Private www)], 354 [qw(wheee)]); 355 356 test_file("", undef, [qw(Public Private www)], [qw(wheee)]); 357 358 test_file("./.owl/", "./.owl", 359 [qw(modules)], 360 [qw(startup)]); 361 362 test_file("~/", "~", 363 [qw(Public Private www)], 364 [qw(wheee)]); 365 366 test_file("P", undef, [qw(Public Private)], []); 367 368 test_file("$tmpdir/.", $tmpdir, 369 [qw(. .. .owl .ours)], 370 [qw(.zephyr.subs)]); 291 371 1; 292 372
Note: See TracChangeset
for help on using the changeset viewer.