|
1 | 1 | use nqpmo;
|
2 | 2 |
|
3 |
| -plan(13); |
| 3 | +plan(22); |
4 | 4 |
|
5 | 5 |
|
6 | 6 | my sub create_buf($type) {
|
@@ -75,3 +75,35 @@ my $pi_signed := create_buf(int8).new;
|
75 | 75 | nqp::push_i($pi_signed, -49);
|
76 | 76 | nqp::push_i($pi_signed, -128);
|
77 | 77 | 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