Skip to content

Commit

Permalink
Merge pull request #1157 from marc-vanderwal/issue/#1153
Browse files Browse the repository at this point in the history
normalization.t: Avoid non-ASCII characters in test names and notes
  • Loading branch information
marc-vanderwal authored Nov 30, 2022
2 parents a553e34 + 4b57414 commit c701ba2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions t/normalization.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ use utf8;

BEGIN { use_ok( 'Zonemaster::Engine::Normalization' ); }

sub char_to_hex_esc {
my ($char) = @_;
my $ord = ord($char);
if ($ord >= 32 && $ord <= 127) {
return $char;
} elsif ($ord <= 255) {
return sprintf('\x%02X', $ord);
} else {
return sprintf('\x{%04X}', $ord);
}
}

sub to_hex_esc {
my ($str) = @_;
return join('', map({ char_to_hex_esc($_) } (split //, $str)));
}

subtest 'Valid domains' => sub {
my %input_domains = (
# Roots
Expand Down Expand Up @@ -67,7 +84,8 @@ subtest 'Valid domains' => sub {
);

while (($domain, $expected_output) = each (%input_domains)) {
subtest "Domain: '$domain'" => sub {
my $safe_domain = to_hex_esc($domain);
subtest "Domain: '$safe_domain'" => sub {
my $errors, $final_domain;
lives_ok(sub {
($errors, $final_domain) = normalize_name($domain);
Expand Down Expand Up @@ -109,15 +127,16 @@ subtest 'Bad domains' => sub {
);

while (($domain, $error) = each (%input_domains)) {
subtest "Domain: '$domain' ($error)" => sub {
my $safe_domain = to_hex_esc($domain);
subtest "Domain: '$safe_domain' ($error)" => sub {
my $output, $messages, $domain;
lives_ok(sub {
($errors, $final_domain) = normalize_name($domain);
}, 'incorrect domain should live');

is($final_domain, undef, 'No domain returned') or diag($final_domain);
is($errors->[0]->tag, $error, 'Correct error is returned') or diag($errors[0]);
note($errors->[0])
note(to_hex_esc($errors->[0]))
}
}
};
Expand Down

0 comments on commit c701ba2

Please sign in to comment.