Skip to content

Commit

Permalink
better stringification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 12, 2012
1 parent 1ba7ad7 commit 6f11a0d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Changes
@@ -1,10 +1,9 @@
This file documents the revision history for Perl extension Mojolicious.

2.96 2012-05-12
2.96 2012-05-13
- Added merge method to Mojo::Path.
- Improved documentation.
- Improved tests.
- Fixed small stringification bugs in Mojo::Path.

2.95 2012-05-10
- Improved documentation.
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Path.pm
Expand Up @@ -86,9 +86,8 @@ sub parse {
}

sub to_abs_string {
my $self = shift;
my $string = $self->to_string;
return $self->leading_slash ? $string : length($string) ? "/$string" : '';
my $self = shift;
return $self->leading_slash ? "$self" : "/$self";
}

# "How is education supposed to make me feel smarter?
Expand Down
9 changes: 7 additions & 2 deletions lib/Mojo/URL.pm
Expand Up @@ -220,8 +220,13 @@ sub to_string {
my $authority = $self->authority;
$url .= $url ? $authority : $authority ? "//$authority" : '';

# Path
$url .= $url ? $self->path->to_abs_string : $self->path->to_string;
# Relative path
my $path = $self->path;
if (!$url) { $url .= "$path" }

# Absolute path
elsif ($path->leading_slash) { $url .= "$path" }
else { $url .= @{$path->parts} ? "/$path" : '' }

# Query
my $query = join '', $self->query;
Expand Down
5 changes: 4 additions & 1 deletion t/mojo/path.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 210;
use Test::More tests => 212;

# "This is the greatest case of false advertising I’ve seen since I sued the
# movie 'The Never Ending Story.'"
Expand All @@ -20,6 +20,9 @@ is $path->parts->[0], 'path', 'right part';
is $path->parts->[1], undef, 'no part';
ok !$path->leading_slash, 'no leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new;
is $path->to_string, '', 'right result';
is $path->to_abs_string, '/', 'right result';

# Advanced
$path = Mojo::Path->new('/AZaz09-._~!$&\'()*+,;=:@');
Expand Down

0 comments on commit 6f11a0d

Please sign in to comment.