Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: bb88aecc18
...
compare: gerd/JSON_nqp
Checking mergeability… Don't worry, you can still create the pull request.
  • 11 commits
  • 3 files changed
  • 1 commit comment
  • 1 contributor
Commits on Feb 24, 2011
Gerd Pokorra add new JSON API to file "nci_thunk_gen.pir" 3f7c693
Commits on Feb 27, 2011
Gerd Pokorra follow master branch 449376f
Commits on Feb 28, 2011
Gerd Pokorra Merge branch 'master' into gerd/JSON_nqp e410b68
Commits on Mar 03, 2011
Gerd Pokorra change JSON tests to use new API cf6d1a8
Gerd Pokorra look to an other error message 45e5941
Gerd Pokorra Merge branch 'master' into gerd/JSON_nqp 7ac0362
Commits on Mar 07, 2011
Gerd Pokorra Merge branch 'master' into gerd/JSON_nqp 394f955
Gerd Pokorra switch back to test JSON from PGE 938ab0e
Gerd Pokorra add test for JSON from NQP de4f790
Gerd Pokorra update mainfest 72c0a77
Commits on Mar 10, 2011
Gerd Pokorra change documentation in test to use the correct filename d92f11c
View
1  MANIFEST
@@ -1478,6 +1478,7 @@ t/codingstd/tabs.t [test]
t/codingstd/trailing_space.t [test]
t/compilers/data_json/from_parrot.t [test]
t/compilers/data_json/to_parrot.t [test]
+t/compilers/data_json/to_parrot_2.t [test]
t/compilers/imcc/imcpasm/cfg.t [test]
t/compilers/imcc/imcpasm/opt0.t [test]
t/compilers/imcc/imcpasm/opt1.t [test]
View
728 t/compilers/data_json/to_parrot_2.t
@@ -0,0 +1,728 @@
+#!perl
+# Copyright (C) 2001-2008, Parrot Foundation.
+
+use strict;
+use warnings;
+use lib qw( t . lib ../lib ../../lib );
+
+use Test::More;
+use Parrot::Test tests => 60;
+
+=head1 NAME
+
+t/compilers/data_json/to_parrot_2.t - test JSON to parrot conversions
+
+=head1 SYNOPSIS
+
+ % prove t/compilers/data_json/to_parrot_2.t
+
+=head1 DESCRIPTION
+
+Tests JSON->Parrot conversions.
+
+=cut
+
+json_dump_is( <<'JSON', <<'OUT', 'empty string' );
+""
+JSON
+"JSON" => ""
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string' );
+"json"
+JSON
+"JSON" => "json"
+OUT
+
+json_isnt( 'a', 'strings need quotes' );
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash "' );
+"\"json\""
+JSON
+"JSON" => "\"json\""
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash \\' );
+"\\json\\"
+JSON
+"JSON" => "\\json\\"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with /' );
+"\/json\/"
+JSON
+"JSON" => "/json/"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash b' );
+"\bjson\b"
+JSON
+"JSON" => "\bjson\b"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash f' );
+"\fjson\f"
+JSON
+"JSON" => "\fjson\f"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash n' );
+"\njson\n"
+JSON
+"JSON" => "\njson\n"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash r' );
+"\rjson\r"
+JSON
+"JSON" => "\rjson\r"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'string with backslash t' );
+"\tjson\t"
+JSON
+"JSON" => "\tjson\t"
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int' );
+1
+JSON
+"JSON" => 1
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int minus' );
+-1
+JSON
+"JSON" => -1
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int frac' );
+3.14
+JSON
+"JSON" => 3.14
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int frac minus' );
+-3.14
+JSON
+"JSON" => -3.14
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int exp' );
+1e+11
+JSON
+"JSON" => 100000000000
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int exp' );
+2e-12
+JSON
+"JSON" => 2e-12
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int exp minus' );
+-1e+11
+JSON
+"JSON" => -100000000000
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int exp minus' );
+-2e-12
+JSON
+"JSON" => -2e-12
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int frac exp' );
+3.14e+10
+JSON
+"JSON" => 31400000000
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'number int frac exp minus' );
+-3.14e+10
+JSON
+"JSON" => -31400000000
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'null' );
+null
+JSON
+"JSON" => null
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'true' );
+true
+JSON
+"JSON" => 1
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'false' );
+false
+JSON
+"JSON" => 0
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'empty array' );
+[]
+JSON
+"JSON" => ResizablePMCArray (size:0) [
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'simple array' );
+[1,2,3]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'simple array (check white spaces)' );
+[ 1 , 2 , 3 ]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of empty arrays' );
+[[],[],[]]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ ResizablePMCArray (size:0) [
+ ],
+ ResizablePMCArray (size:0) [
+ ],
+ ResizablePMCArray (size:0) [
+ ]
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of empty arrays (check white spaces)' );
+[ [] , [] , [] ]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ ResizablePMCArray (size:0) [
+ ],
+ ResizablePMCArray (size:0) [
+ ],
+ ResizablePMCArray (size:0) [
+ ]
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of arrays of integers' );
+[[1,2,3],[1,2,3],[1,2,3]]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ],
+ ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ],
+ ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ]
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of empty strings' );
+["","",""]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ "",
+ "",
+ ""
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of strings' );
+["string a","string b","string c"]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ "string a",
+ "string b",
+ "string c"
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of empty objects' );
+[{},{},{}]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ Hash {
+ },
+ Hash {
+ },
+ Hash {
+ }
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of empty objects (check white spaces)' );
+[ {} , {} , {} ]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ Hash {
+ },
+ Hash {
+ },
+ Hash {
+ }
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of objects with one element' );
+[{"one":1},{"two":2},{"three":3}]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ Hash {
+ "one" => 1
+ },
+ Hash {
+ "two" => 2
+ },
+ Hash {
+ "three" => 3
+ }
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of objects with one element (white space check)' );
+[ { "one" : 1 } , { "two" : 2 } , {"three" : 3} ]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ Hash {
+ "one" => 1
+ },
+ Hash {
+ "two" => 2
+ },
+ Hash {
+ "three" => 3
+ }
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'array of objects with multiple elements' );
+[{"one":1,"two":2,"three":3},{"one":1,"two":2,"three":3},{"one":1,"two":2,"three":3}]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ },
+ Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ },
+ Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ }
+]
+OUT
+
+json_dump_is(
+ <<'JSON', <<'OUT', 'array of boolean objects' );
+[false,true,null]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+ 0,
+ 1,
+ null
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'empty object' );
+{}
+JSON
+"JSON" => Hash {
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with one element' );
+{"one":1}
+JSON
+"JSON" => Hash {
+ "one" => 1
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with numbers' );
+{"one":1,"two":2,"three":3}
+JSON
+"JSON" => Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with strings' );
+{"one":"string a","two":"string b","three":"string c"}
+JSON
+"JSON" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with strings (white space check)' );
+{ "one" : "string a" , "two" : "string b" , "three" : "string c" }
+JSON
+"JSON" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with one empty object' );
+{"one":{}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with one object with one element' );
+{"one":{"one":1}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => 1
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with one object of various element with integers' );
+{"one":{"one":1,"two":2,"three":3}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with one object of various element with strings' );
+{"one":{"one":"string a","two":"string b","three":"string c"}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+ }
+}
+OUT
+
+json_dump_is(
+ <<'JSON', <<'OUT', 'object with one object of various element with strings (check white spaces)' );
+{ "one" : { "one" : "string a" , "two" : "string b" , "three" : "string c" } }
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with more than one empty object' );
+{"one":{},"two":{},"three":{}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ },
+ "three" => Hash {
+ },
+ "two" => Hash {
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with more than one object with one integer element' );
+{"one":{"one":1},"two":{"two":2},"three":{"three":3}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => 1
+ },
+ "three" => Hash {
+ "three" => 3
+ },
+ "two" => Hash {
+ "two" => 2
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with more than one object with various integer elements' );
+{"one":{"one":1,"two":2,"three":3},"two":{"one":1,"two":2,"three":3},"three":{"one":1,"two":2,"three":3}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ },
+ "three" => Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ },
+ "two" => Hash {
+ "one" => 1,
+ "three" => 3,
+ "two" => 2
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with more than one object with one string element' );
+{"one":{"one":"string a"},"two":{"two":"string b"},"three":{"three":"string c"}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => "string a"
+ },
+ "three" => Hash {
+ "three" => "string c"
+ },
+ "two" => Hash {
+ "two" => "string b"
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with more than one object with various integer elements' );
+{"one":{"one":"string a","two":"string b","three":"string c"},"two":{"one":"string a","two":"string b","three":"string c"},"three":{"one":"string a","two":"string b","three":"string c"}}
+JSON
+"JSON" => Hash {
+ "one" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+ },
+ "three" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+ },
+ "two" => Hash {
+ "one" => "string a",
+ "three" => "string c",
+ "two" => "string b"
+ }
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with empty array' );
+{"one":[]}
+JSON
+"JSON" => Hash {
+ "one" => ResizablePMCArray (size:0) [
+ ]
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with array' );
+{"one":[1,2,3]}
+JSON
+"JSON" => Hash {
+ "one" => ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ]
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with various arrays' );
+{"one":[1,2,3],"two":[1,2,3],"three":[1,2,3]}
+JSON
+"JSON" => Hash {
+ "one" => ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ],
+ "three" => ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ],
+ "two" => ResizablePMCArray (size:3) [
+ 1,
+ 2,
+ 3
+ ]
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'object with boolean values' );
+{"one":true,"two":false,"three":null}
+JSON
+"JSON" => Hash {
+ "one" => 1,
+ "three" => null,
+ "two" => 0
+}
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'example taken from the RFC' );
+{"Image":{"Width":800,"Height":600,"Title":"View from 15th Floor","Thumbnail":{"Url":"http://www.example.com/image/481989943","Height":125,"Width":"100"},"IDs":[116, 943, 234, 38793]}}
+JSON
+"JSON" => Hash {
+ "Image" => Hash {
+ "Height" => 600,
+ "IDs" => ResizablePMCArray (size:4) [
+ 116,
+ 943,
+ 234,
+ 38793
+ ],
+ "Thumbnail" => Hash {
+ "Height" => 125,
+ "Url" => "http://www.example.com/image/481989943",
+ "Width" => "100"
+ },
+ "Title" => "View from 15th Floor",
+ "Width" => 800
+ }
+}
+OUT
+
+# Note that the original example has a trailig zero in a floating point value,
+# but we shouldn't check that the processed output match that.
+json_dump_is(
+ <<'JSON', <<'OUT', 'another example taken from the RFC' );
+[{"precision":"zip","Latitude":37.7668,"Longitude":-122.3959,"Address":"","City":"SAN FRANCISCO","State":"CA","Zip":"94107","Country":"US"},{"precision":"zip","Latitude":37.371991,"Longitude":-122.026020,"Address":"","City":"SUNNYVALE", "State":"CA", "Zip":"94085", "Country":"US"}]
+JSON
+"JSON" => ResizablePMCArray (size:2) [
+ Hash {
+ "Address" => "",
+ "City" => "SAN FRANCISCO",
+ "Country" => "US",
+ "Latitude" => 37.7668,
+ "Longitude" => -122.3959,
+ "State" => "CA",
+ "Zip" => "94107",
+ "precision" => "zip"
+ },
+ Hash {
+ "Address" => "",
+ "City" => "SUNNYVALE",
+ "Country" => "US",
+ "Latitude" => 37.371991,
+ "Longitude" => -122.02602,
+ "State" => "CA",
+ "Zip" => "94085",
+ "precision" => "zip"
+ }
+]
+OUT
+
+json_dump_is( <<'JSON', <<'OUT', 'random object/array example' );
+[[],[{},{}],{"str":true},{"a":"1","b":{},"c":"2"},[true],false,{"e":[],"d":3}]
+JSON
+"JSON" => ResizablePMCArray (size:7) [
+ ResizablePMCArray (size:0) [
+ ],
+ ResizablePMCArray (size:2) [
+ Hash {
+ },
+ Hash {
+ }
+ ],
+ Hash {
+ "str" => 1
+ },
+ Hash {
+ "a" => "1",
+ "b" => Hash {
+ },
+ "c" => "2"
+ },
+ ResizablePMCArray (size:1) [
+ 1
+ ],
+ 0,
+ Hash {
+ "d" => 3,
+ "e" => ResizablePMCArray (size:0) [
+ ]
+ }
+]
+OUT
+
+# TT #1226 Need many more tests, exercising all aspects of http://www.json.org/
+
+sub json_dump_is {
+ my ( $code, $dumped, $reason, %args ) = @_;
+
+ chomp $code;
+ $code =~ s{("|\\)}{\\$1}g;
+ $code =~ s{\n}{\\n}g;
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ return pir_output_is( <<"END_PIR", $dumped, $reason, %args );
+
+.sub test :main
+ load_language 'JSON'
+ load_bytecode 'dumper.pbc'
+
+ .local pmc result
+ result = from_json("$code")
+ _dumper(result, "JSON")
+.end
+END_PIR
+
+}
+
+sub json_isnt {
+ my ( $code, $reason, %args ) = @_;
+
+ $code =~ s{("|\\)}{\\$1}g;
+ $code =~ s{\n}{\\n}g;
+
+ return pir_error_output_like( <<"END_PIR", qr/Unable to parse source/, $reason, %args );
+
+.sub test :main
+ load_language 'JSON'
+
+ .local pmc result
+
+ result = from_json("$code")
+.end
+END_PIR
+
+}
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
View
8 tools/dev/nci_thunk_gen.pir
@@ -927,13 +927,9 @@ ERROR
JSON
# decode table
- .local pmc compiler
- load_language 'data_json'
- compiler = compreg 'data_json'
-
.local pmc table
- $P0 = compiler.'compile'(json_table)
- table = $P0()
+ load_language 'JSON'
+ table = from_json(json_table)
# fixup table
.local pmc table_iter

Showing you all comments on commits in this comparison.

@cotto

We should avoid testing against specific error messages. What about just testing that the compile fails?

Something went wrong with that request. Please try again.