Hi all,

I haded some more tests to t/compilers/json/to_parrot.t file to test
some objects/array combinations. All tests pass at this point, except
for tests:

#17 - something about null value in a array
#25 - just added that random sequence, it does not parse not quite sure why.

Attached to this message you have the patch for file:
t/compilers/json/to_parrot.t

Best regards,
./smash

On 9/7/06, via RT Will Coleda <[EMAIL PROTECTED]> wrote:
# New Ticket Created by  Will Coleda
# Please include the string:  [perl #40292]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=40292 >


There is now a "JSON" compiler: perldoc compilers/json/JSON.pir

We need more tests (t/compilers/json/to_parrot.t) that test the
_dumper() output of a PMC generated by converting from a JSON string.

E.g.:

""

Would convert to an empty string, which would then be dumped as:

"JSON" => ""

See http://www.json.org/ for a description of the JSON grammar: all
elements of that grammar should be tested.

For failing tests, TODO them, and I'll be happy to fix the compiler.
Unless you beat me to it, which is fine.

As of the opening of this ticket, expect arrays and objects to fail
(need TGE support), true/false/null to work, and strings & numbers to
partially work.

Regards.

--
Will "Coke" Coleda
[EMAIL PROTECTED]



Index: t/compilers/json/to_parrot.t
===================================================================
--- t/compilers/json/to_parrot.t	(revision 14476)
+++ t/compilers/json/to_parrot.t	(working copy)
@@ -6,7 +6,7 @@
 use lib qw( t . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 11;
+use Parrot::Test tests => 35;
 
 =head1 NAME
 
@@ -81,6 +81,123 @@
 ]
 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 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 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 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',todo=>'TODO parse error');
+[false,true,null]
+JSON
+"JSON" => ResizablePMCArray (size:3) [
+    0,
+    1,
+    null
+]
+OUT
+
+
 json_dump_is(<<'JSON', <<'OUT', 'empty object');
 {}
 JSON
@@ -88,7 +205,15 @@
 }
 OUT
 
-json_dump_is(<<'JSON', <<'OUT', 'simple object');
+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 {
@@ -98,6 +223,232 @@
 }
 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 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 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', 'random object/array example',todo=>'TODO parse error');
+{[],{[],{}},"str":true,{"a":"1",{},"b":"2"},[true],false,{[],"d":3}}
+JSON
+"JSON" => Hash {
+    ResizablePMCArray (size:0) [
+    ],
+    Hash {
+        ResizablePMCArray (size:0) [
+        ],
+        Hash {
+        }
+    },
+    "str" => null,
+    Hash {
+        "a" => 1,
+        "b" => 2,
+        Hash {
+        }
+    },
+    ResizablePMCArray (size:1) [
+        1
+    ],
+    0,
+    Hash {
+        ResizablePMCArray (size:0) [
+        ],
+        "d" => 3
+    }
+}
+OUT
+
 # XXX Need many more tests, exercising all aspects of http://www.json.org/
 
 sub json_dump_is {

Reply via email to