Skip to content

Commit 8aea6d7

Browse files
committed
Test encoding and decoding as utf8-c8
1 parent 4bffb46 commit 8aea6d7

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

t/nqp/082-decode.t

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use nqpmo;
22

3-
plan(13);
3+
plan(22);
44

55

66
my sub create_buf($type) {
@@ -75,3 +75,35 @@ my $pi_signed := create_buf(int8).new;
7575
nqp::push_i($pi_signed, -49);
7676
nqp::push_i($pi_signed, -128);
7777
is(nqp::decode($pi_signed, "utf8"), 'π', 'nqp::decode with a buffer of signed ints');
78+
79+
80+
if nqp::getcomp('nqp').backend.name eq 'jvm' {
81+
skip("utf8-c8 not yet implemented on the JVM", 1 + 4*2);
82+
} else {
83+
my $composed := $buf8.new;
84+
nqp::push_i($composed, 0xc3);
85+
nqp::push_i($composed, 0x85);
86+
87+
my $decomposed := $buf8.new;
88+
nqp::push_i($decomposed, 0x41);
89+
nqp::push_i($decomposed, 0xcc);
90+
nqp::push_i($decomposed, 0x8a);
91+
92+
my $partial := $buf8.new;
93+
nqp::push_i($partial, 0xcc);
94+
95+
96+
my $wrong := $buf8.new;
97+
nqp::push_i($wrong, 0xFE);
98+
is(nqp::decode($composed, 'utf8-c8'), 'Å', 'NFC strings is read just like utf8');
99+
100+
my sub test_encode($buf, $result, $desc) {
101+
is(buf_dump(nqp::encode(nqp::decode($buf, 'utf8-c8'), 'utf8-c8', $buf8.new)), $result, $desc);
102+
is(buf_dump(nqp::encoderep(nqp::decode($buf, 'utf8-c8'), 'utf8-c8', 'XXX', $buf8.new)), $result, $desc ~ ' - nqp::encoderep');
103+
}
104+
105+
test_encode($partial, '204', 'partial utf8');
106+
test_encode($composed, '195,133', 'NFC string');
107+
test_encode($decomposed, '65,204,138', 'not normalized UTF8');
108+
test_encode($wrong, '254', 'not proper UTF8');
109+
}

0 commit comments

Comments
 (0)