Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using custom registries with encode & decode #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions S32-encoding/registry.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use Test;
use lib $?FILE.IO.parent(2).add: 'packages/Test-Helpers';
use Test::Util;

#!rakudo.moar emit plan 40;
#?rakudo.moar emit plan 37;
#!rakudo.moar emit plan 42;
#?rakudo.moar emit plan 39;

for <utf8 utf-8 UTF-8 ascii iso-8859-1 latin-1 utf16 utf-16 UTF-16 UTF16
utf16le utf-16le utf16-le utf-16-le utf16be UTF16BE UTF-16be utf16-be
Expand Down Expand Up @@ -77,4 +77,21 @@ throws-like { Encoding::Registry.find('utf-29') },
"Encodings with no alternative names method can be registered";
}

{
my class TestEncoding4 does Encoding {
method name() { 'userspace-encoding' }
method encoder(*%options) { Encoding::Encoder::Builtin.new('utf8', blob8, |%options) }
method decoder(*%options) { Encoding::Decoder::Builtin.new('utf8', |%options) }
}
Encoding::Registry.register(TestEncoding4);
is-deeply "Hello, world!".encode('userspace-encoding'),
Blob[uint8].new(72,101,108,108,111,44,32,119,111,114,108,100,33),
'Regesterd encodings can be used to encode a Str';

is-deeply Blob[uint8].new(72,101,108,108,111,44,32,119,111,114,108,100,33)
.decode('userspace-encoding'),
"Hello, world!",
'Regesterd encodings can be used to decode a Blob';
}

# vim: expandtab shiftwidth=4