Skip to content

Commit

Permalink
0 but ture bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tomill committed Dec 13, 2010
1 parent 6ae3740 commit c372f97
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README
Expand Up @@ -4,8 +4,8 @@ NAME
SYNOPSIS
use Acme::Ikamusume;
use utf8;
Acme::Ikamusume->geso('イカ娘です。perlで侵略しませんか?');
# => イカ娘でゲソ。perlで侵略しなイカ
Acme::Ikamusume->geso('イカ娘です。あなたもperlで侵略しませんか?');
# => イカ娘でゲソ。お主もperlで侵略しなイカ

DESCRIPTION
Acme::Ikamusume module converts text to Ikamusume like talk. Ikamusume,
Expand Down
11 changes: 6 additions & 5 deletions lib/Acme/Ikamusume.pm
Expand Up @@ -18,9 +18,9 @@ sub new {

sub geso {
my ($self, $input) = @_;
return "" unless $input;
return "" unless defined $input;
$self = $self->new unless ref $self;

my $parser = Acme::Ikamusume::MAParser->new({
userdic => File::ShareDir::dist_file('Acme-Ikamusume', 'ika.dic'),
});
Expand All @@ -39,7 +39,8 @@ sub geso {
$node = $node->next
) {
next if $node->stat =~ /[23]/; # skip MECAB_(BOS|EOS)_NODE
push @words, $node->surface || "";
push @words, $node->surface;

$self->call_trigger('node' => ($node, \@words));
$self->call_trigger('node.has_extra' => ($node, \@words)) if $node->features->{extra};
$self->call_trigger('node.readable' => ($node, \@words)) if $node->features->{yomi};
Expand All @@ -64,8 +65,8 @@ Acme::Ikamusume - The invader comes from the bottom of the sea!
use Acme::Ikamusume;
use utf8;
Acme::Ikamusume->geso('イカ娘です。perlで侵略しませんか?');
# => イカ娘でゲソ。perlで侵略しなイカ
Acme::Ikamusume->geso('イカ娘です。あなたもperlで侵略しませんか?');
# => イカ娘でゲソ。お主もperlで侵略しなイカ
=head1 DESCRIPTION
Expand Down
5 changes: 3 additions & 2 deletions lib/Acme/Ikamusume/MAParser.pm
Expand Up @@ -8,7 +8,7 @@ use base 'Text::MeCab';
my $encoding = Encode::find_encoding( Text::MeCab::ENCODING );

sub parse {
shift->SUPER::parse($encoding->encode(@_) || "");
shift->SUPER::parse($encoding->encode(@_));
}

package Text::MeCab::Node;
Expand All @@ -19,7 +19,8 @@ package Text::MeCab::Node;
for my $method (qw( surface feature )) {
my $original = \&$method;
*{$method} = sub {
$encoding->decode($original->(@_) || "");
my $val = $original->(@_);
defined $val ? $encoding->decode($val) : "";
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions t/01_geso.t
Expand Up @@ -15,7 +15,7 @@ run {
my $block = shift;

my $output = Acme::Ikamusume->geso($block->input);
my $title = $block->name ."\n input: ". $block->input;
my $title = $block->name ." input: ". $block->input;

if ($block->match) {
like($output, $block->match, $title);
Expand All @@ -26,8 +26,8 @@ run {

__DATA__
=== SYNOPSIS
--- input: イカ娘です。perlで侵略しませんか
--- expected: イカ娘でゲソ。perlで侵略しなイカ
--- input: イカ娘です。あなたもperlで侵略しませんか
--- expected: イカ娘でゲソ。お主もperlで侵略しなイカ
=== IKA: replace
Expand Down
31 changes: 31 additions & 0 deletions t/02_parser.t
@@ -0,0 +1,31 @@
use strict;
use warnings;
use Test::Base;
plan tests => 1 * blocks;

use Acme::Ikamusume;

run {
my $block = shift;

my $output = Acme::Ikamusume->geso($block->input);
is($output, $block->expected, $block->name);
};

__DATA__
=== 0 but true
--- reported: http://twitter.com/ttakah/status/14160980556648450
--- input: 0
--- expected: 0
=== empty
--- input eval
""
--- expected eval
""
=== undef
--- input eval
undef
--- expected eval
""

0 comments on commit c372f97

Please sign in to comment.