Skip to content
Browse files

[GH #845] Add more unicode tests to data_json.

Add more documentation to the chr op.
  • Loading branch information...
1 parent 8874b90 commit 2079a97b6b0ed44124acda0102940ed3df5e5847 @rurban rurban committed Sep 27, 2012
Showing with 34 additions and 8 deletions.
  1. +4 −0 src/ops/string.ops
  2. +11 −6 t/compilers/data_json/from_parrot.t
  3. +19 −2 t/compilers/data_json/to_parrot.t
View
4 src/ops/string.ops
@@ -59,6 +59,10 @@ inline op ord(out INT, in STR, in INT) {
The character specified by codepoint integer $2 is returned in string $1.
+For characters > 0xff an utf8 encoded string is returned,
+for characters between 0x7f and 0xff a latin1 encoded string is returned,
+for characters below 0x7f an ascii encoded string.
+
=cut
inline op chr(out STR, in INT) {
View
17 t/compilers/data_json/from_parrot.t
@@ -1,5 +1,5 @@
#!./parrot
-# Copyright (C) 2001-2010, Parrot Foundation.
+# Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
@@ -13,11 +13,13 @@ t/compilers/data_json/from_parrot.t - test parrot to JSON conversion.
Tests JSON->Parrot conversions.
+Note: This uses the old JSON.pbc not the new data_json compiler.
+
=cut
.sub main :main
.include 'test_more.pir'
- plan(39)
+ plan(40)
load_bytecode 'JSON.pbc'
test_create_json_of_an_empty_string()
@@ -356,7 +358,7 @@ OUTPUT
.end
-# no. 24..27
+# no. 24..28
.sub test_create_json_of_string_pmcs
.local pmc s
@@ -373,10 +375,13 @@ OUTPUT
is($S0, '"12345\"67890"', 'Create JSON of String PMCs')
$S0 = _json( s, 1 )
is($S0, "\"12345\\\"67890\"\n", 'Create JSON of String PMCs')
+ s = utf16:"\x{0}\u203e Pl\x{e4}ne"
+ $S0 = _json( s, 0 )
+ is($S0, '"\x{0}\u203e Pl\x{e4}ne"', 'Create JSON of String PMCs')
.end
-# no. 28..31
+# no. 29..32
.sub test_create_json_of_integer_pmcs
.local pmc i
@@ -396,7 +401,7 @@ OUTPUT
.end
-# no. 32..35
+# no. 33..36
.sub test_create_json_of_boolean_pmcs
.local pmc b
@@ -416,7 +421,7 @@ OUTPUT
.end
-# no. 36..39
+# no. 37..40
.sub test_create_json_of_null_and_undef
.local pmc n
null n
View
21 t/compilers/data_json/to_parrot.t
@@ -1,12 +1,12 @@
#!perl
-# Copyright (C) 2001-2008, Parrot Foundation.
+# Copyright (C) 2001-2012, Parrot Foundation.
use strict;
use warnings;
use lib qw( t . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 60;
+use Parrot::Test tests => 61;
=head1 NAME
@@ -20,6 +20,8 @@ t/compilers/data_json/to_parrot.t - test JSON to parrot conversions
Tests JSON->Parrot conversions.
+Note: This uses the new data_json compiler.
+
=cut
json_dump_is( <<'JSON', <<'OUT', 'empty string' );
@@ -677,6 +679,21 @@ JSON
]
OUT
+json_dump_is( <<'JSON', <<'OUT', 'unicode chars' );
+["\u0000","\u00e4","\u007f","\u0080","\u0100","\u203e","Pl\u00e4ne"]
+JSON
+"JSON" => ResizablePMCArray (size:7) [
+ "\x{0}",
+ "\x{e4}",
+ "\x{7f}",
+ "\x{80}",
+ "\u0100",
+ "\u203e",
+ "Pl\x{e4}ne"
+]
+OUT
+
+
# GH #570 Need many more tests, exercising all aspects of http://www.json.org/
sub json_dump_is {

0 comments on commit 2079a97

Please sign in to comment.
Something went wrong with that request. Please try again.