Ticket #1333: compilers_json_from_parrot_t.patch

File compilers_json_from_parrot_t.patch, 11.8 KB (added by bubaflub, 12 years ago)

patch to convert t/compilers/json/from_parrot.patch to PIR

  • t/compilers/json/from_parrot.t

    diff --git t/compilers/json/from_parrot.t t/compilers/json/from_parrot.t
    index 170176c..f328141 100644
     
    1 #!perl 
     1#!parrot 
    22# Copyright (C) 2001-2006, Parrot Foundation. 
    33# $Id$ 
    44 
    5 use strict; 
    6 use warnings; 
    7 use lib qw( t . lib ../lib ../../lib ); 
    8  
    9 use Test::More; 
    10 use Parrot::Test tests => 18; 
    11  
    125=head1 NAME 
    136 
    147t/compilers/json/from_parrot.t - test parrot to JSON conversion. 
     
    2316 
    2417=cut 
    2518 
    26 # no. 1 
    27 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of an empty string' ); 
     19.sub main :main 
     20    .include 'test_more.pir' 
     21    plan(39) 
     22 
     23    test_create_json_of_an_empty_string() 
     24    test_create_json_of_a_non_empty_string() 
     25    test_create_json_of_a_string_with_simple_escapes() 
     26    test_create_json_of_some_integers() 
     27    test_create_json_of_some_numbers() 
     28    test_create_json_of_various_scalars_with_pretty_option() 
     29    test_create_json_of_an_array() 
     30    test_create_pretty_json_of_an_array() 
     31    test_create_json_of_array_keep_element_ordering() 
     32    test_create_json_of_a_mixed_array() 
     33    test_create_json_of_hash() 
     34    test_create_non_pretty_json_of_hash() 
     35    test_create_json_of_nested_structure_including_resizablepmcarray_and_empties() 
     36    test_create_non_pretty_json_of_nested_structure() 
     37    test_create_json_of_string_pmcs() 
     38    test_create_json_of_integer_pmcs() 
     39    test_create_json_of_boolean_pmcs() 
     40    test_create_json_of_null_and_undef() 
     41.end 
    2842 
    29 .sub test :main 
     43# no. 1 
     44.sub test_create_json_of_an_empty_string 
    3045    .local string s 
    3146    s = '' 
    3247 
    3348    load_bytecode 'JSON.pbc' 
    3449    $S0 = _json( s, 0 ) 
    35     say $S0 
     50    is($S0, '""', 'Create JSON of an empty string') 
    3651.end 
    37 CODE 
    38 "" 
    39 OUT 
    4052 
    4153# no. 2 
    42 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of a non-empty string' ); 
     54.sub test_create_json_of_a_non_empty_string 
    4355 
    44 .sub test :main 
    4556    .local string s 
    4657    s = 'abcdeABCDE01234$%^&*' 
    4758 
    4859    load_bytecode 'JSON.pbc' 
    4960    $S0 = _json( s, 0 ) 
    50     say $S0 
     61    is($S0, '"abcdeABCDE01234$%^&*"', 'Create JSON of a non-empty string') 
    5162.end 
    52 CODE 
    53 "abcdeABCDE01234$%^&*" 
    54 OUT 
    5563 
    5664# no. 3 
    57 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of a string with simple escapes' ); 
    58  
    59 .sub test :main 
     65.sub test_create_json_of_a_string_with_simple_escapes 
    6066    .local string s 
    6167    s = "abcde\\ABCDE\"01234\n$%^&*" 
    6268    # XXX more escapes need to be tested; see http://www.json.org/ 
    6369    load_bytecode 'JSON.pbc' 
    6470    $S0 = _json( s, 0 ) 
    65     say $S0 
     71    is($S0, '"abcde\\ABCDE\"01234\n$%^&*"', 'Create JSON of a string with simple escapes')  
    6672.end 
    67 CODE 
    68 "abcde\\ABCDE\"01234\n$%^&*" 
    69 OUT 
    7073 
    7174# no. 4 
    72 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of some integers' ); 
     75.sub test_create_json_of_some_integers 
    7376 
    74 .sub test :main 
    7577    .local int i 
    7678    i = 0 
    7779    load_bytecode 'JSON.pbc' 
    7880    $S0 = _json( i, 0 ) 
    79     say $S0 
     81    is($S0, 0, 'Create JSON of some integers') 
    8082    i = 35 
    8183    $S0 = _json( i, 0 ) 
    82     say $S0 
     84    is($S0, 35, 'Create JSON of some integers') 
    8385    i = -42 
    8486    $S0 = _json( i, 0 ) 
    85     say $S0 
     87    is($S0, -42, 'Create JSON of some integers') 
    8688    i = 2147483647 
    8789    $S0 = _json( i, 0 ) 
    88     say $S0 
     90    is($S0, 2147483647, 'Create JSON of some integers') 
    8991    i = -2147483648 
    9092    $S0 = _json( i, 0 ) 
    91     say $S0 
     93    is($S0, -2147483648, 'Create JSON of some integers') 
    9294.end 
    93 CODE 
    94 0 
    95 35 
    96 -42 
    97 2147483647 
    98 -2147483648 
    99 OUT 
    10095 
    10196# no. 5 
    102 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of some numbers' ); 
    103  
    104 .sub test :main 
     97.sub test_create_json_of_some_numbers 
    10598    .local num n 
    10699    n = 0.0 
    107100    load_bytecode 'JSON.pbc' 
    108101    $S0 = _json( n ) 
    109     say $S0 
     102    is($S0, 0, 'Create JSON of some numbers') 
    110103    n = 2.50 
    111104    $S0 = _json( n ) 
    112     say $S0 
     105    is($S0, 2.5, 'Create JSON of some numbers') 
    113106    n = -42.0 
    114107    $S0 = _json( n ) 
    115     say $S0 
     108    is($S0, -42, 'Create JSON of some numbers') 
    116109    n = 4.5e1 
    117110    $S0 = _json( n ) 
    118     say $S0 
     111    is($S0, 45, 'Create JSON of some numbers') 
    119112.end 
    120 CODE 
    121 0 
    122 2.5 
    123 -42 
    124 45 
    125 OUT 
    126113 
    127114# no. 6 
    128 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of various scalars with pretty option' ); 
    129  
    130 .sub test :main 
     115.sub test_create_json_of_various_scalars_with_pretty_option 
    131116    .local string s 
    132117    s = "abcde\\ABCDE\"01234\n$%^&*" 
    133118    load_bytecode 'JSON.pbc' 
    134119    $S0 = _json( s, 1 ) 
    135     print $S0 
     120    is($S0, "\"abcde\\\\ABCDE\\\"01234\\n\$\%\^\&\*\"\n", 'Create JSON of various scalars with pretty option') 
    136121 
    137122    .local int i 
    138123    i = -42 
    139124    $S0 = _json( i, 1 ) 
    140     print $S0 
     125    is($S0, "-42\n", 'Create JSON of various scalars with pretty option') 
    141126 
    142127    .local num n 
    143128    n = 2.50 
    144129    $S0 = _json( n, 1 ) 
    145     print $S0 
     130    is($S0, "2.5\n", 'Create JSON of various scalars with pretty option') 
    146131.end 
    147 CODE 
    148 "abcde\\ABCDE\"01234\n$%^&*" 
    149 -42 
    150 2.5 
    151 OUT 
    152132 
    153133# no. 7 
    154 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of an array' ); 
    155  
    156 .sub test :main 
     134.sub test_create_json_of_an_array 
    157135    .local pmc array 
    158136 
    159137    new array, 'Array' 
     
    171149 
    172150    load_bytecode 'JSON.pbc' 
    173151    $S0 = _json( array, 0 ) 
    174     say $S0 
     152    is($S0, '[0,1,2,3,4,5,6,7,8,9]', 'Create JSON of an array') 
    175153.end 
    176 CODE 
    177 [0,1,2,3,4,5,6,7,8,9] 
    178 OUT 
    179154 
    180155# no. 8 
    181 pir_output_is( <<'CODE', <<'OUT', 'Create pretty JSON of an array' ); 
    182  
    183 .sub test :main 
     156.sub test_create_pretty_json_of_an_array 
    184157    .local pmc array 
    185158 
    186159    new array, 'Array' 
     
    198171 
    199172    load_bytecode 'JSON.pbc' 
    200173    $S0 = _json( array, 1 ) 
    201     print $S0 
    202 .end 
    203 CODE 
     174    is($S0, <<'OUTPUTPUT', 'Create pretty JSON of an array') 
    204175[ 
    205176  0, 
    206177  1, 
     
    213184  8, 
    214185  9 
    215186] 
    216 OUT 
     187OUTPUTPUT 
     188.end 
    217189 
    218190# no. 9 
    219 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of array, keep element ordering' ); 
    220  
    221 .sub test :main 
     191.sub test_create_json_of_array_keep_element_ordering 
    222192    .local pmc array 
    223193 
    224194    new array, 'Array' 
     
    232202 
    233203    load_bytecode 'JSON.pbc' 
    234204    $S0 = _json( array, 1 ) 
    235     print $S0 
    236 .end 
    237 CODE 
     205    is($S0, <<'OUTPUTPUT', 'Create JSON of an array, keep element ordering') 
    238206[ 
    239207  35, 
    240208  1, 
     
    243211  -2147483648, 
    244212  2147483647 
    245213] 
    246 OUT 
     214OUTPUTPUT 
     215.end 
    247216 
    248217# no. 10 
    249 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of a mixed array' ); 
    250  
    251 .sub test :main 
     218.sub test_create_json_of_a_mixed_array 
    252219    .local pmc array 
    253220 
    254221    new array, 'Array' 
     
    262229 
    263230    load_bytecode 'JSON.pbc' 
    264231    $S0 = _json( array, 1 ) 
    265     print $S0 
    266 .end 
    267 CODE 
     232    is($S0, <<'OUTPUT', 'Create JSON of a mixed array') 
    268233[ 
    269234  0, 
    270235  15, 
     
    273238  "json", 
    274239  0 
    275240] 
    276 OUT 
     241OUTPUT 
     242.end 
    277243 
    278244# no. 11 
    279 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of hash' ); 
    280  
    281 .sub test :main 
     245.sub test_create_json_of_hash 
    282246    .local pmc hash 
    283247 
    284248    new hash, 'Hash' 
     
    289253 
    290254    load_bytecode 'JSON.pbc' 
    291255    $S0 = _json( hash, 1 ) 
    292     print $S0 
    293 .end 
    294 CODE 
     256    is($S0, <<'OUTPUT', 'Create JSON of hash') 
    295257{ 
    296258  "alpha" : 29, 
    297259  "beta" : "B", 
    298260  "delta" : "DELTA", 
    299261  "gamma" : 3.1 
    300262} 
    301 OUT 
     263OUTPUT 
     264.end 
    302265 
    303266# no. 12 
    304 pir_output_is( <<'CODE', <<'OUT', 'Create non-pretty JSON of hash' ); 
    305  
    306 .sub test :main 
     267.sub test_create_non_pretty_json_of_hash 
    307268    .local pmc hash 
    308269 
    309270    new hash, 'Hash' 
     
    314275 
    315276    load_bytecode 'JSON.pbc' 
    316277    $S0 = _json( hash, 0 ) 
    317     say $S0 
     278    is($S0, '{"alpha":29,"beta":"B","delta":"DELTA","gamma":3.1}', 'Create non-pretty JSON of hash') 
    318279.end 
    319 CODE 
    320 {"alpha":29,"beta":"B","delta":"DELTA","gamma":3.1} 
    321 OUT 
    322280 
    323281# no. 13 
    324 pir_output_is( 
    325     <<'CODE', <<'OUT', 'Create JSON of nested structure including ResizablePMCArray and empties' ); 
    326  
    327 .sub test :main 
     282.sub test_create_json_of_nested_structure_including_resizablepmcarray_and_empties 
    328283    .local pmc street1, street2, city1, city2, country, world 
    329284 
    330285    street1 = new 'Hash' 
     
    351306 
    352307    load_bytecode 'JSON.pbc' 
    353308    $S0 = _json( world, 1 ) 
    354     print $S0 
    355 .end 
    356 CODE 
     309    is($S0, <<'OUTPUT', 'Create JSON of nested structure including ResizablePMCArray and empties') 
    357310{ 
    358311  "population" : 1234567890, 
    359312  "some_country" : [ 
     
    370323    ] 
    371324  ] 
    372325} 
    373 OUT 
     326OUTPUT 
     327.end 
    374328 
    375329# no. 14 
    376 pir_output_is( <<'CODE', <<'OUT', 'Create non-pretty JSON of nested structure' ); 
    377  
    378 .sub test :main 
     330.sub test_create_non_pretty_json_of_nested_structure 
    379331    .local pmc street1, street2, city1, city2, country, world 
    380332 
    381333    street1 = new 'Hash' 
     
    402354 
    403355    load_bytecode 'JSON.pbc' 
    404356    $S0 = _json( world, 0 ) 
    405     say $S0 
     357    is($S0, '{"population":1234567890,"some_country":[[{"Perl":"Highway","Python":"Grove","Ruby":"Lane"},{}],[]]}', 'Create non-pretty JSON of nested structure') 
    406358.end 
    407 CODE 
    408 {"population":1234567890,"some_country":[[{"Perl":"Highway","Python":"Grove","Ruby":"Lane"},{}],[]]} 
    409 OUT 
    410359 
    411360# no. 15 
    412 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of String PMCs' ); 
    413  
    414 .sub test :main 
     361.sub test_create_json_of_string_pmcs 
    415362    .local pmc s 
    416363 
    417364    s = new 'String' 
    418365    s = '' 
    419366    load_bytecode 'JSON.pbc' 
    420367    $S0 = _json( s, 0 ) 
    421     say $S0 
     368    is($S0, '""', 'Create JSON of String PMCs') 
    422369    $S0 = _json( s, 1 ) 
    423     print $S0 
     370    is($S0, "\"\"\n", 'Create JSON of String PMCs') 
    424371 
    425372    s = new 'String' 
    426373    s = "12345\"67890" 
    427374    $S0 = _json( s, 0 ) 
    428     say $S0 
     375    is($S0, '"12345\"67890"', 'Create JSON of String PMCs') 
    429376    $S0 = _json( s, 1 ) 
    430     print $S0 
     377    is($S0, "\"12345\\\"67890\"\n", 'Create JSON of String PMCs') 
    431378.end 
    432 CODE 
    433 "" 
    434 "" 
    435 "12345\"67890" 
    436 "12345\"67890" 
    437 OUT 
    438379 
    439380# no. 16 
    440 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of Integer PMCs' ); 
    441  
    442 .sub test :main 
     381.sub test_create_json_of_integer_pmcs 
    443382    .local pmc i 
    444383 
    445384    i = new 'Integer' 
    446385    i = 0 
    447386    load_bytecode 'JSON.pbc' 
    448387    $S0 = _json( i, 0 ) 
    449     say $S0 
     388    is($S0, 0, 'Create JSON of String PMCs') 
    450389    $S0 = _json( i, 1 ) 
    451     print $S0 
     390    is($S0, "0\n", 'Create JSON of String PMCs') 
    452391 
    453392    i = new 'Integer' 
    454393    i = -42 
    455394    $S0 = _json( i, 0 ) 
    456     say $S0 
     395    is($S0, -42, 'Create JSON of String PMCs') 
    457396    $S0 = _json( i, 1 ) 
    458     print $S0 
     397    is($S0, "-42\n", 'Create JSON of String PMCs') 
    459398.end 
    460 CODE 
    461 0 
    462 0 
    463 -42 
    464 -42 
    465 OUT 
    466399 
    467400# no. 17 
    468 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of Boolean PMCs' ); 
    469  
    470 .sub test :main 
     401.sub test_create_json_of_boolean_pmcs 
    471402    .local pmc b 
    472403 
    473404    b = new 'Boolean' 
    474405    b = 0 
    475406    load_bytecode 'JSON.pbc' 
    476407    $S0 = _json( b, 0 ) 
    477     say $S0 
     408    is($S0, 'false', 'Create JSON of Boolean PMCs') 
    478409    $S0 = _json( b, 1 ) 
    479     print $S0 
     410    is($S0, "false\n", 'Create JSON of Boolean PMCs') 
    480411 
    481412    b = new 'Boolean' 
    482413    b = 1 
    483414    $S0 = _json( b, 0 ) 
    484     say $S0 
     415    is($S0, 'true', 'Create JSON of Boolean PMCs') 
    485416    $S0 = _json( b, 1 ) 
    486     print $S0 
     417    is($S0, "true\n", 'Create JSON of Boolean PMCs') 
    487418.end 
    488 CODE 
    489 false 
    490 false 
    491 true 
    492 true 
    493 OUT 
    494419 
    495420# no. 18 
    496 pir_output_is( <<'CODE', <<'OUT', 'Create JSON of null and .Undef' ); 
    497  
    498 .sub test :main 
     421.sub test_create_json_of_null_and_undef 
    499422    .local pmc n 
    500423    null n 
    501424 
    502425    load_bytecode 'JSON.pbc' 
    503426    $S0 = _json( n, 0 ) 
    504     say $S0 
     427    is($S0, 'null', 'Create JSON of null and .Undef') 
    505428    $S0 = _json( n, 1 ) 
    506     print $S0 
     429    is($S0, "null\n", 'Create JSON of null and .Undef') 
    507430 
    508431    n = new 'Undef' 
    509432    $S0 = _json( n, 0 ) 
    510     say $S0 
     433    is($S0, 'null', 'Create JSON of null and .Undef') 
    511434    $S0 = _json( n, 1 ) 
    512     print $S0 
     435    is($S0, "null\n", 'Create JSON of null and .Undef') 
    513436.end 
    514 CODE 
    515 null 
    516 null 
    517 null 
    518 null 
    519 OUT 
    520437 
    521438# Local Variables: 
    522439#   mode: cperl 
    523440#   cperl-indent-level: 4 
    524441#   fill-column: 100 
    525442# End: 
    526 # vim: expandtab shiftwidth=4: 
     443# vim: expandtab shiftwidth=4 filetype=pir: