use warnings;
use strict;
use Test::More;
use FindBin '$Bin';
my $builder = Test::More->builder;
binmode $builder->output, ":encoding(utf8)";
binmode $builder->failure_output, ":encoding(utf8)";
binmode $builder->todo_output, ":encoding(utf8)";
binmode STDOUT, ":encoding(utf8)";
binmode STDERR, ":encoding(utf8)";
use Table::Readable 'replace';
use File::Compare;
use File::Copy 'copy';
my $orig = "$Bin/test-replace.txt";
my $in = "$Bin/test-replace-in.txt";
my $out = "$Bin/test-replace-compare.txt";
copy($orig, $in);
replace($in, {a => 'b', c => 'd'}, {e => 'f', g => 'h'});
ok(compare($in, $out), "Files $in and $out are the same after replacement");
unlink($in) or warn "Failed to remove test file $in: $!";
my $warned;
$SIG{__WARN__} = sub { ($warned) = @_ };
replace($orig, {a => 'b', p => 'q'}, {b => 'c'});
ok($warned, "Warning $warned occurred for non-matching entry");
like($warned, qr/not found/, "Warning looks right");
done_testing ();
