Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expand the nqp::encode/nqp::decode test.
  • Loading branch information
pmurias committed Oct 30, 2015
1 parent e00d482 commit 5b5faaa
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions t/nqp/82-decode.t
@@ -1,4 +1,4 @@
plan(3);
plan(5);

class int8 is repr('P6int') {}
class buf8 is repr('VMArray') {}
Expand All @@ -13,11 +13,27 @@ nqp::composetype(int16, nqp::hash('integer', nqp::hash('bits', 16)));
nqp::composetype(buf16, nqp::hash('array', nqp::hash('type', int16)));

my $buf := nqp::encode('', 'utf8', buf8.new);
ok(1, 'encoding empty string as UTF-8');
ok(nqp::elems($buf) == 0, 'encoding empty string as UTF-8');
my $str := nqp::decode($buf, 'utf8');
ok(1, 'decoding empty UTF-8 string into string');
ok($str eq '', 'decoding empty UTF-8 string into string');


# Test for a regression in the Parrot backend.
$buf := nqp::encode('a', 'utf16', buf16.new);
$str := nqp::decode($buf, 'utf16');
ok(1, 'round-tripping via UTF-16');
ok($str eq 'a', 'round-tripping via UTF-16');

my $hello := nqp::encode('Hello World', 'utf8', buf8.new);

sub buf_dump($buf) {
my @parts;
my $i := 0;
while $i < nqp::elems($buf) {
@parts.push(~nqp::atpos_i($hello, $i));
$i := $i + 1;
}
nqp::join(",", @parts);
}

ok(buf_dump($hello) eq "72,101,108,108,111,32,87,111,114,108,100", "Hello World is encoded to utf8 correctly");
ok(nqp::decode($hello, "utf8") eq "Hello World", "round-tripping Hello World");

0 comments on commit 5b5faaa

Please sign in to comment.