Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only run the new decode/encode conf tests on moarvm for now
- Loading branch information
Showing
2 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This can be moved when *conf ops are added to jvm and others | ||
use nqpmo; | ||
plan(7); | ||
|
||
my sub create_buf($type) { | ||
my $buf := nqp::newtype(nqp::null(), 'VMArray'); | ||
nqp::composetype($buf, nqp::hash('array', nqp::hash('type', $type))); | ||
nqp::setmethcache($buf, nqp::hash('new', method () {nqp::create($buf)})); | ||
$buf; | ||
} | ||
|
||
|
||
my $buf8 := create_buf(uint8); | ||
my $replaced_ascii := nqp::encoderepconf('åfooåbar', 'ascii', 'XXX', $buf8.new, 0); | ||
is(nqp::decode($replaced_ascii, "utf8"), 'XXXfooXXXbar', 'nqp::encoderep works with ascii'); | ||
|
||
my $replaced_latin1 := nqp::encoderep('☃foo☃barå', 'iso-8859-1', 'XXX', $buf8.new); | ||
is(nqp::decode($replaced_latin1, 'iso-8859-1'), 'XXXfooXXXbarå', 'nqp::encoderep works with latin1'); | ||
|
||
my $replaced_windows1252 := nqp::encoderep('☃foo☃barå', 'windows-1252', 'XXX', $buf8.new); | ||
|
||
my $replaced_w := nqp::encoderepconf("\c[129]åfooåbar→", 'windows-1252', 'XXX', $buf8.new, 1); | ||
is(nqp::decodeconf($replaced_w, "windows-1252", 1), "\c[129]åfooåbarXXX", | ||
'nqp::encoderepconf(.., 1) only replaces things not fiting in one byte'); | ||
my $replaced_w2 := nqp::encoderepconf("\c[129]åfooåbar", 'windows-1252', 'XXX', $buf8.new, 0); | ||
is(nqp::decode($replaced_w2, "windows-1252"), "XXXåfooåbar", | ||
'nqp::encoderepconf(…, 0) replaces anything not officially mapped.'); | ||
# Encode chr 129 using unstrict mode (invalid codepoint otherwise) | ||
my $special_windows1252 := nqp::encodeconf(nqp::chr(129), 'windows-1252', $buf8.new, 1); | ||
# Test that it can be decoded unstrict | ||
is(nqp::decodeconf($special_windows1252, 'windows-1252', 1), "\c[129]", | ||
'nqp::encodeconf works with windows-1252 and non-strict. decodeconf works non-strict'); | ||
# Test we can decode invalid codepoint and it is replaced instead on strict mode | ||
is(nqp::decoderepconf($special_windows1252, 'windows-1252', 'X', 0), "X", | ||
"nqp::decoderepconf works on strict (does do replacement)"); | ||
# Test that if we use non-strict mode, it leaves things that fit into Unicode | ||
# unchanged. | ||
is(nqp::decoderepconf($special_windows1252, 'windows-1252', 'X', 1), "\c[129]", | ||
"nqp::decoderepconf(…,1) doesn't replace if byte fits into unicode"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters