Skip to content

Commit 24f9097

Browse files
committed
Only run the new decode/encode conf tests on moarvm for now
1 parent b6d98ea commit 24f9097

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

t/moar/11-decode.t

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This can be moved when *conf ops are added to jvm and others
2+
use nqpmo;
3+
plan(7);
4+
5+
my sub create_buf($type) {
6+
my $buf := nqp::newtype(nqp::null(), 'VMArray');
7+
nqp::composetype($buf, nqp::hash('array', nqp::hash('type', $type)));
8+
nqp::setmethcache($buf, nqp::hash('new', method () {nqp::create($buf)}));
9+
$buf;
10+
}
11+
12+
13+
my $buf8 := create_buf(uint8);
14+
my $replaced_ascii := nqp::encoderepconf('åfooåbar', 'ascii', 'XXX', $buf8.new, 0);
15+
is(nqp::decode($replaced_ascii, "utf8"), 'XXXfooXXXbar', 'nqp::encoderep works with ascii');
16+
17+
my $replaced_latin1 := nqp::encoderep('☃foo☃barå', 'iso-8859-1', 'XXX', $buf8.new);
18+
is(nqp::decode($replaced_latin1, 'iso-8859-1'), 'XXXfooXXXbarå', 'nqp::encoderep works with latin1');
19+
20+
my $replaced_windows1252 := nqp::encoderep('☃foo☃barå', 'windows-1252', 'XXX', $buf8.new);
21+
22+
my $replaced_w := nqp::encoderepconf("\c[129]åfooåbar→", 'windows-1252', 'XXX', $buf8.new, 1);
23+
is(nqp::decodeconf($replaced_w, "windows-1252", 1), "\c[129]åfooåbarXXX",
24+
'nqp::encoderepconf(.., 1) only replaces things not fiting in one byte');
25+
my $replaced_w2 := nqp::encoderepconf("\c[129]åfooåbar", 'windows-1252', 'XXX', $buf8.new, 0);
26+
is(nqp::decode($replaced_w2, "windows-1252"), "XXXåfooåbar",
27+
'nqp::encoderepconf(…, 0) replaces anything not officially mapped.');
28+
# Encode chr 129 using unstrict mode (invalid codepoint otherwise)
29+
my $special_windows1252 := nqp::encodeconf(nqp::chr(129), 'windows-1252', $buf8.new, 1);
30+
# Test that it can be decoded unstrict
31+
is(nqp::decodeconf($special_windows1252, 'windows-1252', 1), "\c[129]",
32+
'nqp::encodeconf works with windows-1252 and non-strict. decodeconf works non-strict');
33+
# Test we can decode invalid codepoint and it is replaced instead on strict mode
34+
is(nqp::decoderepconf($special_windows1252, 'windows-1252', 'X', 0), "X",
35+
"nqp::decoderepconf works on strict (does do replacement)");
36+
# Test that if we use non-strict mode, it leaves things that fit into Unicode
37+
# unchanged.
38+
is(nqp::decoderepconf($special_windows1252, 'windows-1252', 'X', 1), "\c[129]",
39+
"nqp::decoderepconf(…,1) doesn't replace if byte fits into unicode");

t/nqp/082-decode.t

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

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

55

66
my sub create_buf($type) {
@@ -56,38 +56,16 @@ my $hello2 := $buf8.new;
5656
nqp::encode('Hello World', 'utf8', $hello2);
5757
is(buf_dump($hello2), "72,101,108,108,111,32,87,111,114,108,100", "the buf passed to nqp::encode is actually changed");
5858

59-
# encode/decode config tests
60-
my $replaced_ascii := nqp::encoderepconf('åfooåbar', 'ascii', 'XXX', $buf8.new, 0);
59+
my $replaced_ascii := nqp::encoderep('åfooåbar', 'ascii', 'XXX', $buf8.new);
6160
is(nqp::decode($replaced_ascii, "utf8"), 'XXXfooXXXbar', 'nqp::encoderep works with ascii');
6261

6362
my $replaced_latin1 := nqp::encoderep('☃foo☃barå', 'iso-8859-1', 'XXX', $buf8.new);
6463
is(nqp::decode($replaced_latin1, 'iso-8859-1'), 'XXXfooXXXbarå', 'nqp::encoderep works with latin1');
6564

6665
my $replaced_windows1252 := nqp::encoderep('☃foo☃barå', 'windows-1252', 'XXX', $buf8.new);
67-
68-
my $replaced_w := nqp::encoderepconf("\c[129]åfooåbar→", 'windows-1252', 'XXX', $buf8.new, 1);
69-
is(nqp::decodeconf($replaced_w, "windows-1252", 1), "\c[129]åfooåbarXXX",
70-
'nqp::encoderepconf(.., 1) only replaces things not fiting in one byte');
71-
my $replaced_w2 := nqp::encoderepconf("\c[129]åfooåbar", 'windows-1252', 'XXX', $buf8.new, 0);
72-
is(nqp::decode($replaced_w2, "windows-1252"), "XXXåfooåbar",
73-
'nqp::encoderepconf(…, 0) replaces anything not officially mapped.');
74-
# Encode chr 129 using unstrict mode (invalid codepoint otherwise)
75-
my $special_windows1252 := nqp::encodeconf(nqp::chr(129), 'windows-1252', $buf8.new, 1);
76-
# Test that it can be decoded unstrict
77-
is(nqp::decodeconf($special_windows1252, 'windows-1252', 1), "\c[129]",
78-
'nqp::encodeconf works with windows-1252 and non-strict. decodeconf works non-strict');
79-
# Test we can decode invalid codepoint and it is replaced instead on strict mode
80-
is(nqp::decoderepconf($special_windows1252, 'windows-1252', 'X', 0), "X",
81-
"nqp::decoderepconf works on strict (does do replacement)");
82-
# Test that if we use non-strict mode, it leaves things that fit into Unicode
83-
# unchanged.
84-
is(nqp::decoderepconf($special_windows1252, 'windows-1252', 'X', 1), "\c[129]",
85-
"nqp::decoderepconf(…,1) doesn't replace if byte fits into unicode");
86-
8766
is(nqp::decode($replaced_latin1, 'windows-1252'), 'XXXfooXXXbarå', 'nqp::encoderep works with windows-1252');
8867

8968

90-
9169
my $pi_unsigned := $buf8.new;
9270
nqp::push_i($pi_unsigned, 207);
9371
nqp::push_i($pi_unsigned, 128);

0 commit comments

Comments
 (0)