Skip to content

Commit dd15d19

Browse files
committed
Add tests for nqp::encoderep and the windows-1252 encoding
1 parent fc728ac commit dd15d19

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

t/nqp/082-decode.t

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

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

55

66
my sub create_buf($type) {
@@ -42,10 +42,30 @@ sub buf_dump($buf) {
4242
is(buf_dump($hello), "72,101,108,108,111,32,87,111,114,108,100", "Hello World is encoded to utf8 correctly");
4343
is(nqp::decode($hello, "utf8"), "Hello World", "round-tripping Hello World");
4444

45+
my str $windows_1252_str := '€‚ƒ„…†‡ˆ‰Š‹ŒŽ';
46+
my $windows_1252_encoded := nqp::encode($windows_1252_str, 'windows-1252', $buf8.new);
47+
is(
48+
buf_dump($windows_1252_encoded),
49+
'128,130,131,132,133,134,135,136,137,138,139,140,142',
50+
'cp1252 encodes most C1 substitutes'
51+
);
52+
53+
is(nqp::decode($windows_1252_encoded, 'windows-1252'), $windows_1252_str, "round-tripping windows-1252 str");
54+
4555
my $hello2 := $buf8.new;
4656
nqp::encode('Hello World', 'utf8', $hello2);
4757
is(buf_dump($hello2), "72,101,108,108,111,32,87,111,114,108,100", "the buf passed to nqp::encode is actually changed");
4858

59+
my $replaced_ascii := nqp::encoderep('åfooåbar', 'ascii', 'XXX', $buf8.new);
60+
is(nqp::decode($replaced_ascii, "utf8"), 'XXXfooXXXbar', 'nqp::encoderep works with ascii');
61+
62+
my $replaced_latin1 := nqp::encoderep('☃foo☃barå', 'iso-8859-1', 'XXX', $buf8.new);
63+
is(nqp::decode($replaced_latin1, 'iso-8859-1'), 'XXXfooXXXbarå', 'nqp::encoderep works with latin1');
64+
65+
my $replaced_windows1252 := nqp::encoderep('☃foo☃barå', 'windows-1252', 'XXX', $buf8.new);
66+
is(nqp::decode($replaced_latin1, 'windows-1252'), 'XXXfooXXXbarå', 'nqp::encoderep works with windows-1252');
67+
68+
4969
my $pi_unsigned := $buf8.new;
5070
nqp::push_i($pi_unsigned, 207);
5171
nqp::push_i($pi_unsigned, 128);

0 commit comments

Comments
 (0)