Aozora2Epub

 view release on metacpan or  search on metacpan

t/gaiji-replace.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use Test::More;
use Test::Base;
use Aozora2Epub;
use Aozora2Epub::Gensym;
use lib qw/./;
use t::Util;

plan tests => 1 * blocks;

sub eval_unicode_notation {
    my $s = shift;
    $s =~ s|\\x\{([0-9a-fA-F]+)\}|chr(hex($1))|esg;
    return $s;
}

filters {
    html => 'chomp',
    expected => ['chomp', 'eval_unicode_notation'],
};

run {
    my $block = shift;
    Aozora2Epub::Gensym->reset_counter;

    my $doc = Aozora2Epub->new($block->html, no_fetch_assets=>1);
    my $got = join('', map { $_->as_html } @{$doc->files});
    is_deeply($got, $block->expected, $block->name);
};

__DATA__

=== simple unicode
--- html
※<span class="notes">[#「てへん+去」、U+62BE、369-2]</span>
--- expected
\x{62be}

=== non gaiji note
--- html
あああ<span class="notes">[# あああはママ]</span>
--- expected
あああ<span class="notes">[# あああはママ]</span>

=== within ruby
--- html
嘴<ruby><rb>鸚※</rb><rp>(</rp><rt>おうむ</rt><rp>)</rp></ruby><span class="notes">[#「母+鳥」、U+4CC7、217-9]</span>のごとく
--- expected
嘴<ruby><rb>鸚\x{4cc7}</rb><rp>(</rp><rt>おうむ</rt><rp>)</rp></ruby>のごとく

=== corrupted ruby
--- html
嘴<ruby><rb>鸚</rb><rp>(</rp><rt>おうむ</rt><rp>)</rp></ruby><span class="notes">[#「母+鳥」、U+4CC7、217-9]</span>のごとく
--- expected
嘴<ruby><rb>鸚</rb><rp>(</rp><rt>おうむ</rt><rp>)</rp></ruby><span class="notes">[#「母+鳥」、U+4CC7、217-9]</span>のごとく

=== within ruby 2
--- html
人里に出て<ruby><rb>※腹</rb><rp>(</rp><rt>きょうふく</rt><rp>)</rp></ruby><span class="notes">[#「木+号」、U+67B5、532-2]</span>を充たしたい
--- expected
人里に出て<ruby><rb>\x{67b5}腹</rb><rp>(</rp><rt>きょうふく</rt><rp>)</rp></ruby>を充たしたい



( run in 0.876 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )