[svn:parrot] r42810 - trunk/t/compilers/json

mikehh at svn.parrot.org mikehh at svn.parrot.org
Thu Nov 26 18:07:06 UTC 2009


Author: mikehh
Date: Thu Nov 26 18:07:04 2009
New Revision: 42810
URL: https://trac.parrot.org/parrot/changeset/42810

Log:
convert test to pir - based on patch by bubaflub++ (TT #1333)

Modified:
   trunk/t/compilers/json/from_parrot.t

Modified: trunk/t/compilers/json/from_parrot.t
==============================================================================
--- trunk/t/compilers/json/from_parrot.t	Thu Nov 26 14:44:46 2009	(r42809)
+++ trunk/t/compilers/json/from_parrot.t	Thu Nov 26 18:07:04 2009	(r42810)
@@ -1,14 +1,7 @@
-#!perl
-# Copyright (C) 2001-2006, Parrot Foundation.
+#!parrot
+# Copyright (C) 2001-2009, Parrot Foundation.
 # $Id$
 
-use strict;
-use warnings;
-use lib qw( t . lib ../lib ../../lib );
-
-use Test::More;
-use Parrot::Test tests => 18;
-
 =head1 NAME
 
 t/compilers/json/from_parrot.t - test parrot to JSON conversion.
@@ -23,137 +16,127 @@
 
 =cut
 
-# no. 1
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of an empty string' );
+.sub main :main
+    .include 'test_more.pir'
+    plan(39)
+
+    test_create_json_of_an_empty_string()
+    test_create_json_of_a_non_empty_string()
+    test_create_json_of_a_string_with_simple_escapes()
+    test_create_json_of_some_integers()
+    test_create_json_of_some_numbers()
+    test_create_json_of_various_scalars_with_pretty_option()
+    test_create_json_of_an_array()
+    test_create_pretty_json_of_an_array()
+    test_create_json_of_array_keep_element_ordering()
+    test_create_json_of_a_mixed_array()
+    test_create_json_of_hash()
+    test_create_non_pretty_json_of_hash()
+    test_create_json_of_nested_structure_including_resizablepmcarray_and_empties()
+    test_create_non_pretty_json_of_nested_structure()
+    test_create_json_of_string_pmcs()
+    test_create_json_of_integer_pmcs()
+    test_create_json_of_boolean_pmcs()
+    test_create_json_of_null_and_undef()
+.end
 
-.sub test :main
+
+# no. 1
+.sub test_create_json_of_an_empty_string
     .local string s
     s = ''
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( s, 0 )
-    say $S0
+    is($S0, '""', 'Create JSON of an empty string')
 .end
-CODE
-""
-OUT
 
-# no. 2
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of a non-empty string' );
 
-.sub test :main
+# no. 2
+.sub test_create_json_of_a_non_empty_string
     .local string s
     s = 'abcdeABCDE01234$%^&*'
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( s, 0 )
-    say $S0
+    is($S0, '"abcdeABCDE01234$%^&*"', 'Create JSON of a non-empty string')
 .end
-CODE
-"abcdeABCDE01234$%^&*"
-OUT
 
-# no. 3
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of a string with simple escapes' );
 
-.sub test :main
+# no. 3
+.sub test_create_json_of_a_string_with_simple_escapes
     .local string s
     s = "abcde\\ABCDE\"01234\n$%^&*"
     # XXX more escapes need to be tested; see http://www.json.org/
     load_bytecode 'JSON.pbc'
     $S0 = _json( s, 0 )
-    say $S0
+    is($S0, '"abcde\\ABCDE\"01234\n$%^&*"', 'Create JSON of a string with simple escapes')
 .end
-CODE
-"abcde\\ABCDE\"01234\n$%^&*"
-OUT
 
-# no. 4
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of some integers' );
 
-.sub test :main
+# no. 4..8
+.sub test_create_json_of_some_integers
     .local int i
     i = 0
     load_bytecode 'JSON.pbc'
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, 0, 'Create JSON of some integers (0)')
     i = 35
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, 35, 'Create JSON of some integers (35)')
     i = -42
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, -42, 'Create JSON of some integers (-42)')
     i = 2147483647
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, 2147483647, 'Create JSON of some integers (2147483647)')
     i = -2147483648
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, -2147483648, 'Create JSON of some integers (-2147483647)')
 .end
-CODE
-0
-35
--42
-2147483647
--2147483648
-OUT
 
-# no. 5
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of some numbers' );
 
-.sub test :main
+# no. 9..12
+.sub test_create_json_of_some_numbers
     .local num n
     n = 0.0
     load_bytecode 'JSON.pbc'
     $S0 = _json( n )
-    say $S0
+    is($S0, 0, 'Create JSON of some numbers (0)')
     n = 2.50
     $S0 = _json( n )
-    say $S0
+    is($S0, 2.5, 'Create JSON of some numbers (2.5)')
     n = -42.0
     $S0 = _json( n )
-    say $S0
+    is($S0, -42, 'Create JSON of some numbers (-42)')
     n = 4.5e1
     $S0 = _json( n )
-    say $S0
+    is($S0, 45, 'Create JSON of some numbers (45)')
 .end
-CODE
-0
-2.5
--42
-45
-OUT
 
-# no. 6
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of various scalars with pretty option' );
 
-.sub test :main
+# no. 13..15
+.sub test_create_json_of_various_scalars_with_pretty_option
     .local string s
     s = "abcde\\ABCDE\"01234\n$%^&*"
     load_bytecode 'JSON.pbc'
     $S0 = _json( s, 1 )
-    print $S0
+    is($S0, "\"abcde\\\\ABCDE\\\"01234\\n\$\%\^\&\*\"\n", 'Create JSON of various scalars with pretty option (string)')
 
     .local int i
     i = -42
     $S0 = _json( i, 1 )
-    print $S0
+    is($S0, "-42\n", 'Create JSON of various scalars with pretty option (integer)')
 
     .local num n
     n = 2.50
     $S0 = _json( n, 1 )
-    print $S0
+    is($S0, "2.5\n", 'Create JSON of various scalars with pretty option (number)')
 .end
-CODE
-"abcde\\ABCDE\"01234\n$%^&*"
--42
-2.5
-OUT
 
-# no. 7
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of an array' );
 
-.sub test :main
+# no. 16
+.sub test_create_json_of_an_array
     .local pmc array
 
     new array, 'Array'
@@ -171,16 +154,12 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( array, 0 )
-    say $S0
+    is($S0, '[0,1,2,3,4,5,6,7,8,9]', 'Create JSON of an array')
 .end
-CODE
-[0,1,2,3,4,5,6,7,8,9]
-OUT
 
-# no. 8
-pir_output_is( <<'CODE', <<'OUT', 'Create pretty JSON of an array' );
 
-.sub test :main
+# no. 17
+.sub test_create_pretty_json_of_an_array
     .local pmc array
 
     new array, 'Array'
@@ -198,9 +177,7 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( array, 1 )
-    print $S0
-.end
-CODE
+    is($S0, <<'OUTPUT', 'Create pretty JSON of an array')
 [
   0,
   1,
@@ -213,12 +190,12 @@
   8,
   9
 ]
-OUT
+OUTPUT
+.end
 
-# no. 9
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of array, keep element ordering' );
 
-.sub test :main
+# no. 18
+.sub test_create_json_of_array_keep_element_ordering
     .local pmc array
 
     new array, 'Array'
@@ -232,9 +209,7 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( array, 1 )
-    print $S0
-.end
-CODE
+    is($S0, <<'OUTPUT', 'Create JSON of an array, keep element ordering')
 [
   35,
   1,
@@ -243,12 +218,12 @@
   -2147483648,
   2147483647
 ]
-OUT
+OUTPUT
+.end
 
-# no. 10
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of a mixed array' );
 
-.sub test :main
+# no. 19
+.sub test_create_json_of_a_mixed_array
     .local pmc array
 
     new array, 'Array'
@@ -262,9 +237,7 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( array, 1 )
-    print $S0
-.end
-CODE
+    is($S0, <<'OUTPUT', 'Create JSON of a mixed array')
 [
   0,
   15,
@@ -273,12 +246,12 @@
   "json",
   0
 ]
-OUT
+OUTPUT
+.end
 
-# no. 11
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of hash' );
 
-.sub test :main
+# no. 20
+.sub test_create_json_of_hash
     .local pmc hash
 
     new hash, 'Hash'
@@ -289,21 +262,19 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( hash, 1 )
-    print $S0
-.end
-CODE
+    is($S0, <<'OUTPUT', 'Create JSON of hash')
 {
   "alpha" : 29,
   "beta" : "B",
   "delta" : "DELTA",
   "gamma" : 3.1
 }
-OUT
+OUTPUT
+.end
 
-# no. 12
-pir_output_is( <<'CODE', <<'OUT', 'Create non-pretty JSON of hash' );
 
-.sub test :main
+# no. 21
+.sub test_create_non_pretty_json_of_hash
     .local pmc hash
 
     new hash, 'Hash'
@@ -314,17 +285,12 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( hash, 0 )
-    say $S0
+    is($S0, '{"alpha":29,"beta":"B","delta":"DELTA","gamma":3.1}', 'Create non-pretty JSON of hash')
 .end
-CODE
-{"alpha":29,"beta":"B","delta":"DELTA","gamma":3.1}
-OUT
 
-# no. 13
-pir_output_is(
-    <<'CODE', <<'OUT', 'Create JSON of nested structure including ResizablePMCArray and empties' );
 
-.sub test :main
+# no. 22
+.sub test_create_json_of_nested_structure_including_resizablepmcarray_and_empties
     .local pmc street1, street2, city1, city2, country, world
 
     street1 = new 'Hash'
@@ -351,9 +317,7 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( world, 1 )
-    print $S0
-.end
-CODE
+    is($S0, <<'OUTPUT', 'Create JSON of nested structure including ResizablePMCArray and empties')
 {
   "population" : 1234567890,
   "some_country" : [
@@ -370,12 +334,12 @@
     ]
   ]
 }
-OUT
+OUTPUT
+.end
 
-# no. 14
-pir_output_is( <<'CODE', <<'OUT', 'Create non-pretty JSON of nested structure' );
 
-.sub test :main
+# no. 23
+.sub test_create_non_pretty_json_of_nested_structure
     .local pmc street1, street2, city1, city2, country, world
 
     street1 = new 'Hash'
@@ -402,125 +366,94 @@
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( world, 0 )
-    say $S0
+    is($S0, '{"population":1234567890,"some_country":[[{"Perl":"Highway","Python":"Grove","Ruby":"Lane"},{}],[]]}', 'Create non-pretty JSON of nested structure')
 .end
-CODE
-{"population":1234567890,"some_country":[[{"Perl":"Highway","Python":"Grove","Ruby":"Lane"},{}],[]]}
-OUT
 
-# no. 15
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of String PMCs' );
 
-.sub test :main
+# no. 24..27
+.sub test_create_json_of_string_pmcs
     .local pmc s
 
     s = new 'String'
     s = ''
     load_bytecode 'JSON.pbc'
     $S0 = _json( s, 0 )
-    say $S0
+    is($S0, '""', 'Create JSON of String PMCs')
     $S0 = _json( s, 1 )
-    print $S0
+    is($S0, "\"\"\n", 'Create JSON of String PMCs')
 
     s = new 'String'
     s = "12345\"67890"
     $S0 = _json( s, 0 )
-    say $S0
+    is($S0, '"12345\"67890"', 'Create JSON of String PMCs')
     $S0 = _json( s, 1 )
-    print $S0
+    is($S0, "\"12345\\\"67890\"\n", 'Create JSON of String PMCs')
 .end
-CODE
-""
-""
-"12345\"67890"
-"12345\"67890"
-OUT
 
-# no. 16
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of Integer PMCs' );
 
-.sub test :main
+# no. 28..31
+.sub test_create_json_of_integer_pmcs
     .local pmc i
 
     i = new 'Integer'
     i = 0
     load_bytecode 'JSON.pbc'
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, 0, 'Create JSON of String PMCs')
     $S0 = _json( i, 1 )
-    print $S0
+    is($S0, "0\n", 'Create JSON of String PMCs')
 
     i = new 'Integer'
     i = -42
     $S0 = _json( i, 0 )
-    say $S0
+    is($S0, -42, 'Create JSON of String PMCs')
     $S0 = _json( i, 1 )
-    print $S0
+    is($S0, "-42\n", 'Create JSON of String PMCs')
 .end
-CODE
-0
-0
--42
--42
-OUT
 
-# no. 17
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of Boolean PMCs' );
 
-.sub test :main
+# no. 32..35
+.sub test_create_json_of_boolean_pmcs
     .local pmc b
 
     b = new 'Boolean'
     b = 0
     load_bytecode 'JSON.pbc'
     $S0 = _json( b, 0 )
-    say $S0
+    is($S0, 'false', 'Create JSON of Boolean PMCs')
     $S0 = _json( b, 1 )
-    print $S0
+    is($S0, "false\n", 'Create JSON of Boolean PMCs')
 
     b = new 'Boolean'
     b = 1
     $S0 = _json( b, 0 )
-    say $S0
+    is($S0, 'true', 'Create JSON of Boolean PMCs')
     $S0 = _json( b, 1 )
-    print $S0
+    is($S0, "true\n", 'Create JSON of Boolean PMCs')
 .end
-CODE
-false
-false
-true
-true
-OUT
 
-# no. 18
-pir_output_is( <<'CODE', <<'OUT', 'Create JSON of null and .Undef' );
 
-.sub test :main
+# no. 36..39
+.sub test_create_json_of_null_and_undef
     .local pmc n
     null n
 
     load_bytecode 'JSON.pbc'
     $S0 = _json( n, 0 )
-    say $S0
+    is($S0, 'null', 'Create JSON of null and .Undef')
     $S0 = _json( n, 1 )
-    print $S0
+    is($S0, "null\n", 'Create JSON of null and .Undef')
 
     n = new 'Undef'
     $S0 = _json( n, 0 )
-    say $S0
+    is($S0, 'null', 'Create JSON of null and .Undef')
     $S0 = _json( n, 1 )
-    print $S0
+    is($S0, "null\n", 'Create JSON of null and .Undef')
 .end
-CODE
-null
-null
-null
-null
-OUT
 
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4
 #   fill-column: 100
 # End:
-# vim: expandtab shiftwidth=4:
+# vim: expandtab shiftwidth=4 filetype=pir:


More information about the parrot-commits mailing list