/
encode.t
36 lines (26 loc) 路 1.31 KB
/
encode.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use v6;
use Test;
plan 15;
# L<S32::Containers/Buf>
ok 'ab'.encode('ASCII') ~~ blob8, '$str.encode returns a blob8';
ok ('ab'.encode('ASCII') eqv blob8.new(97, 98)), 'encoding to ASCII';
is 'ab'.encode('ASCII').elems, 2, 'right length of Buf';
ok ('枚'.encode('UTF-8') eqv utf8.new(195, 182)), 'encoding to UTF-8';
is 'ab'.encode('UTF-8').elems, 2, 'right length of Buf';
is 'abc'.encode()[0], 97, 'can index one element in a Buf';
is_deeply 'abc'.encode()[1, 2], (98, 99), 'can slice-index a Buf';
# verified with Perl 5:
# perl -CS -Mutf8 -MUnicode::Normalize -e 'print NFD("盲")' | hexdump -C
#?rakudo skip 'We do not handle NDF yet'
ok ('盲'.encode('UTF-8', 'D') eqv Buf.new(:16<61>, :16<cc>, :16<88>)),
'encoding to UTF-8, with NFD';
#?rakudo todo 'encode returns signed 8bit integers instead of unsigned'
ok ('盲'.encode('UTF-8') eqv Buf.new(:16<c3>, :16<a4>)),
'encoding 盲 utf8 gives correct numbers';
ok Buf.new(195, 182).decode ~~ Str, '.decode returns a Str';
is Buf.new(195, 182).decode, '枚', 'decoding a Buf with UTF-8';
is Buf.new(246).decode('ISO-8859-1'), '枚', 'decoding a Buf with Latin-1';
ok Buf ~~ Stringy, 'Buf does Stringy';
ok Buf ~~ Positional, 'Buf does Positional';
is 'abc'.encode('ascii').list.join(','), '97,98,99', 'Buf.list gives list of codepoints';
# vim: ft=perl6