Skip to content

Commit 4b979dd

Browse files
committed
Add tests for Encoding::Registry.
1 parent 3dc96c7 commit 4b979dd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

S32-encoding/registry.t

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use Test;
2+
3+
plan 8;
4+
5+
throws-like { Encoding::Registry.find('utf-29') },
6+
X::Encoding::Unknown, name => 'utf-29',
7+
'Unknown encoding throws correct type of exception';
8+
9+
{
10+
my class TestEncoding does Encoding {
11+
method name() { 'utf-29' }
12+
method alternative-names() { ('utf29', 'prime-enc') }
13+
method encoder() { die "NYI" }
14+
method decoder() { die "NYI" }
15+
}
16+
17+
lives-ok { Encoding::Registry.register(TestEncoding) },
18+
'Can register an encoding';
19+
20+
isa-ok Encoding::Registry.find('utf-29'), TestEncoding,
21+
'Can find an encoding by its name';
22+
isa-ok Encoding::Registry.find('UtF-29'), TestEncoding,
23+
'Encoding finding by name is case-insensitive';
24+
isa-ok Encoding::Registry.find('utf29'), TestEncoding,
25+
'Can find an encoding by its alternative names';
26+
isa-ok Encoding::Registry.find('Prime-Enc'), TestEncoding,
27+
'Encoding finding by alternative names is case-insensitive';
28+
29+
my class TestEncoding2 does Encoding {
30+
method name() { 'utf-29' }
31+
method alternative-names() { () }
32+
method encoder() { die "NYI" }
33+
method decoder() { die "NYI" }
34+
}
35+
throws-like { Encoding::Registry.register(TestEncoding2) },
36+
X::Encoding::AlreadyRegistered, name => 'utf-29',
37+
'Cannot register an encoding with an overlapping name';
38+
39+
my class TestEncoding3 does Encoding {
40+
method name() { 'utf-17' }
41+
method alternative-names() { 'prime-enc' }
42+
method encoder() { die "NYI" }
43+
method decoder() { die "NYI" }
44+
}
45+
throws-like { Encoding::Registry.register(TestEncoding3) },
46+
X::Encoding::AlreadyRegistered, name => 'prime-enc',
47+
'Cannot register an encoding with an overlapping alternative name';
48+
}
49+

0 commit comments

Comments
 (0)