Development

Changeset 7923

You must first sign up to be able to contribute.

Changeset 7923

Show
Ignore:
Timestamp:
03/16/08 22:03:59 (1 year ago)
Author:
fabien
Message:

added indentation modifier support to folded blocks + fixed string <-> integer conversion in sfYamlInline

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/util/sfYamlInline.class.php

    r7922 r7923  
    7070        return 'false'; 
    7171      case ctype_digit($value): 
    72         return (int) $value; 
     72        return is_string($value) ? "'$value'" : (int) $value; 
    7373      case is_numeric($value): 
    74         return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : $value
     74        return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : (is_string($value) ? "'$value'" : $value)
    7575      case false !== strpos($value, "\n"): 
    7676        return sprintf('"%s"', str_replace(array('"', "\n"), array('\\"', '\n'), $value)); 
  • branches/1.1/lib/util/sfYamlParser.class.php

    r7919 r7923  
    161161      if ($this->isCurrentLineEmpty()) 
    162162      { 
    163         if (!$this->isCurrentLineComment()) 
     163        if ($this->isCurrentLineBlank()) 
    164164        { 
    165165          $data[] = substr($this->currentLine, $newIndent); 
     
    227227  protected function parseValue($value) 
    228228  { 
    229     switch ($value) 
    230     { 
    231       case '|': 
    232         return $this->parseFoldedScalar("\n", ''); 
    233       case '>': 
    234         return $this->parseFoldedScalar(' ', ''); 
    235       case '|+': 
    236         return $this->parseFoldedScalar("\n", '+'); 
    237       case '>+': 
    238         return $this->parseFoldedScalar(' ', '+'); 
    239       case '|-': 
    240         return $this->parseFoldedScalar("\n", '-'); 
    241       case '>-': 
    242         return $this->parseFoldedScalar(' ', '-'); 
    243       default: 
    244         return sfYamlInline::load($value); 
     229    if (preg_match('/^(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?$/', $value, $matches)) 
     230    { 
     231      $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; 
     232 
     233      return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers))); 
     234    } 
     235    else 
     236    { 
     237      return sfYamlInline::load($value); 
    245238    } 
    246239  } 
     
    249242   * Parses a folded scalar. 
    250243   * 
    251    * @param  string The separator that was used to begin this folded scalar 
    252    * @param  string The indicator that was used to begin this folded scalar 
    253    * 
    254    * @return string The text value 
    255    */ 
    256   protected function parseFoldedScalar($separator, $indicator = '') 
    257   { 
    258     $this->moveToNextLine(); 
    259  
    260     if (!preg_match('#^(?P<indent> +)(?P<text>.*)$#', $this->currentLine, $matches)) 
    261     { 
    262       throw new InvalidArgumentException(sprintf('Wrong indentation at line %d (%s)', $this->getRealCurrentLineNb(), $this->currentLine)); 
     244   * @param  string  The separator that was used to begin this folded scalar (| or >) 
     245   * @param  string  The indicator that was used to begin this folded scalar (+ or -) 
     246   * @param  integer The indentation that was used to begin this folded scalar 
     247   * 
     248   * @return string  The text value 
     249   */ 
     250  protected function parseFoldedScalar($separator, $indicator = '', $indentation = 0) 
     251  { 
     252    $separator = '|' == $separator ? "\n" : ' '; 
     253    $text = ''; 
     254 
     255    $notEOF = $this->moveToNextLine(); 
     256 
     257    while ($notEOF && $this->isCurrentLineBlank()) 
     258    { 
     259      $text .= "\n"; 
     260 
     261      $notEOF = $this->moveToNextLine(); 
     262    } 
     263 
     264    if (!$notEOF) 
     265    { 
     266      return ''; 
     267    } 
     268 
     269    if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#', $this->currentLine, $matches)) 
     270    { 
     271      $this->moveToPreviousLine(); 
     272 
     273      return ''; 
    263274    } 
    264275 
    265276    $textIndent = $matches['indent']; 
    266  
    267     $text = $matches['text'].$separator; 
     277    $previousIndent = 0; 
     278 
     279    $text .= $matches['text'].$separator; 
    268280    while ($this->currentLineNb + 1 < count($this->lines)) 
    269281    { 
    270282      $this->moveToNextLine(); 
    271283 
    272       if (preg_match('#^'.$textIndent.'(?P<text>.+)$#', $this->currentLine, $matches)) 
    273       { 
    274         $text .= $matches['text'].$separator; 
     284      if (preg_match('#^(?<indent> {'.strlen($textIndent).',})(?P<text>.+)$#', $this->currentLine, $matches)) 
     285      { 
     286        if (' ' == $separator && $previousIndent != $matches['indent']) 
     287        { 
     288          $text = substr($text, 0, -1)."\n"; 
     289        } 
     290        $previousIndent = $matches['indent']; 
     291 
     292        $text .= str_repeat(' ', $diff = strlen($matches['indent']) - strlen($textIndent)).$matches['text'].($diff ? "\n" : $separator); 
    275293      } 
    276294      else if (preg_match('#^(?P<text> *)$#', $this->currentLine, $matches)) 
     
    317335    $notEOF = $this->moveToNextLine(); 
    318336 
    319     while ($this->isCurrentLineEmpty() && $notEOF
     337    while ($notEOF && $this->isCurrentLineEmpty()
    320338    { 
    321339      $notEOF = $this->moveToNextLine(); 
     
    339357 
    340358  /** 
    341    * Returns true if the current line is empty or if it is a comment line. 
     359   * Returns true if the current line is blank or if it is a comment line. 
    342360   * 
    343361   * @return Boolean Returns true if the current line is empty or if it is a comment line, false otherwise 
     
    345363  protected function isCurrentLineEmpty() 
    346364  { 
    347     return '' == trim($this->currentLine, ' ') || $this->isCurrentLineComment(); 
     365    return $this->isCurrentLineBlank() || $this->isCurrentLineComment(); 
     366  } 
     367 
     368  /** 
     369   * Returns true if the current line is blank. 
     370   * 
     371   * @return Boolean Returns true if the current line is blank, false otherwise 
     372   */ 
     373  protected function isCurrentLineBlank() 
     374  { 
     375    return '' == trim($this->currentLine, ' '); 
    348376  } 
    349377 
  • branches/1.1/test/unit/util/fixtures/yaml/YtsSpecificationExamples.yml

    r7892 r7923  
    129129---  
    130130test: Sequence of sequences  
    131 todo: true 
    132131spec: 2.5 
    133132yaml: |  
     
    135134  - [ Mark McGwire , 65 , 0.278 ]  
    136135  - [ Sammy Sosa   , 63 , 0.288 ]  
    137 perl: |  
    138   [  
    139     [ 'name', 'hr', 'avg' ],  
    140     [ 'Mark McGwire', 65, 0.278 ],  
    141     [ 'Sammy Sosa', 63, 0.288 ],  
    142   ]  
    143 python: |  
    144   [[  
    145     [ 'name', 'hr', 'avg' ],  
    146     [ 'Mark McGwire', 65, 0.278 ],  
    147     [ 'Sammy Sosa', 63, 0.288 ]  
    148   ]]  
    149 ruby: |  
    150   [  
    151     [ 'name', 'hr', 'avg' ],  
    152     [ 'Mark McGwire', 65, 0.278 ],  
    153     [ 'Sammy Sosa', 63, 0.288 ]  
    154   ]  
    155 syck: | 
    156   struct test_node seq1[] = { 
    157       { T_STR, 0, "name" }, 
    158       { T_STR, 0, "hr" }, 
    159       { T_STR, 0, "avg" }, 
    160       end_node 
    161   }; 
    162   struct test_node seq2[] = { 
    163       { T_STR, 0, "Mark McGwire" }, 
    164       { T_STR, 0, "65" }, 
    165       { T_STR, 0, "0.278" }, 
    166       end_node 
    167   }; 
    168   struct test_node seq3[] = { 
    169       { T_STR, 0, "Sammy Sosa" }, 
    170       { T_STR, 0, "63" }, 
    171       { T_STR, 0, "0.288" }, 
    172       end_node 
    173   }; 
    174   struct test_node seq[] = { 
    175       { T_SEQ, 0, 0, seq1 }, 
    176       { T_SEQ, 0, 0, seq2 }, 
    177       { T_SEQ, 0, 0, seq3 }, 
    178       end_node 
    179   }; 
    180   struct test_node stream[] = { 
    181       { T_SEQ, 0, 0, seq }, 
    182       end_node 
    183   }; 
    184   
     136php: |  
     137  array(  
     138    array( 'name', 'hr', 'avg' ),  
     139    array( 'Mark McGwire', 65, 0.278 ),  
     140    array( 'Sammy Sosa', 63, 0.288 )  
     141  ) 
    185142---  
    186143test: Mapping of mappings  
     
    193150      avg: 0.288 
    194151    } 
    195 perl-xxx: |  
    196   {   
    197     'Mark McGwire' => { 'hr' => 65, 'avg' => 0.278 },  
    198     'Sammy Sosa' => { 'hr' => 63, 'avg' => 0.288 },  
    199   }  
    200 not_yet_in_python: |  
    201   [{   
    202     'Mark McGwire':   
    203       { 'hr': 65, 'avg': 0.278 },  
    204     'Sammy Sosa':  
    205       { 'hr': 63, 'avg': 0.288 }  
    206   }]  
    207 ruby: |  
    208   {   
     152ruby: |  
     153  array(   
    209154    'Mark McGwire' =>  
    210       { 'hr' => 65, 'avg' => 0.278 },  
     155      array( 'hr' => 65, 'avg' => 0.278 ),  
    211156    'Sammy Sosa' =>  
    212       { 'hr' => 63, 'avg' => 0.288 }  
    213   }  
    214 syck: | 
    215   struct test_node map1[] = { 
    216       { T_STR, 0, "hr" }, 
    217           { T_STR, 0, "65" }, 
    218       { T_STR, 0, "avg" }, 
    219           { T_STR, 0, "0.278" }, 
    220       end_node 
    221   }; 
    222   struct test_node map2[] = { 
    223       { T_STR, 0, "hr" }, 
    224           { T_STR, 0, "63" }, 
    225       { T_STR, 0, "avg" }, 
    226           { T_STR, 0, "0.288" }, 
    227       end_node 
    228   }; 
    229   struct test_node map[] = { 
    230       { T_STR, 0, "Mark McGwire" }, 
    231           { T_MAP, 0, 0, map1 }, 
    232       { T_STR, 0, "Sammy Sosa" }, 
    233           { T_MAP, 0, 0, map2 }, 
    234       end_node 
    235   }; 
    236   struct test_node stream[] = { 
    237       { T_MAP, 0, 0, map }, 
    238       end_node 
    239   }; 
    240   
    241 ---  
    242 test: Two documents in a stream each with a 
    243       leading comment 
     157      array( 'hr' => 63, 'avg' => 0.288 )  
     158  ) 
     159---  
     160test: Two documents in a stream each with a leading comment 
    244161todo: true 
    245162spec: 2.7  
     
    255172  - Chicago Cubs 
    256173  - St Louis Cardinals 
    257 perl: |  
    258   { name => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278 },  
    259   { name => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288 }  
    260 python: |  
    261   [  
    262     { 'name': 'Mark McGwire', 'hr': 65, 'avg': 0.278 },  
    263     { 'name': 'Sammy Sosa', 'hr': 63, 'avg': 0.288 }  
    264   ]  
    265174ruby: |  
    266175  y = YAML::Stream.new  
    267176  y.add( [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] )  
    268177  y.add( [ 'Chicago Cubs', 'St Louis Cardinals' ] )  
    269 syck: | 
    270   struct test_node seq1[] = { 
    271       { T_STR, 0, "Mark McGwire" }, 
    272       { T_STR, 0, "Sammy Sosa" }, 
    273       { T_STR, 0, "Ken Griffey" }, 
    274       end_node 
    275   }; 
    276   struct test_node seq2[] = { 
    277       { T_STR, 0, "Chicago Cubs" }, 
    278       { T_STR, 0, "St Louis Cardinals" }, 
    279       end_node 
    280   }; 
    281   struct test_node stream[] = { 
    282       { T_SEQ, 0, 0, seq1 }, 
    283       { T_SEQ, 0, 0, seq2 }, 
    284       end_node 
    285   }; 
    286178documents: 2  
    287179  
     
    303195perl: |  
    304196  [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ]  
    305 python: |  
    306   [[ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ]]  
    307 ruby: |  
    308   y = YAML::Stream.new  
    309   y.add( {"player"=>"Sammy Sosa", "time"=>72200, "action"=>"strike (miss)"} ) 
    310   y.add( {"player"=>"Sammy Sosa", "time"=>72227, "action"=>"grand slam"} ) 
    311 syck: | 
    312   struct test_node map1[] = { 
    313       { T_STR, 0, "time" }, 
    314           { T_STR, 0, "20:03:20" }, 
    315       { T_STR, 0, "player" }, 
    316           { T_STR, 0, "Sammy Sosa" }, 
    317       { T_STR, 0, "action" }, 
    318           { T_STR, 0, "strike (miss)" }, 
    319       end_node 
    320   }; 
    321   struct test_node map2[] = { 
    322       { T_STR, 0, "time" }, 
    323           { T_STR, 0, "20:03:47" }, 
    324       { T_STR, 0, "player" }, 
    325           { T_STR, 0, "Sammy Sosa" }, 
    326       { T_STR, 0, "action" }, 
    327           { T_STR, 0, "grand slam" }, 
    328       end_node 
    329   }; 
    330   struct test_node stream[] = { 
    331       { T_MAP, 0, 0, map1 }, 
    332       { T_MAP, 0, 0, map2 }, 
    333       end_node 
    334   }; 
    335197documents: 2  
    336198  
    337199---  
    338200test: Single document with two comments  
    339 todo: true 
    340201spec: 2.9 
    341202yaml: |  
     
    347208    - Sammy Sosa  
    348209    - Ken Griffey  
    349 perl-xxx: |  
    350   {   
    351     'hr' => [ 'Mark McGwire', 'Sammy Sosa' ],  
    352     'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ]   
    353   }  
    354 python: |  
    355   [{   
    356     'hr': [ 'Mark McGwire', 'Sammy Sosa' ],  
    357     'rbi': [ 'Sammy Sosa', 'Ken Griffey' ]   
    358   }]  
    359 ruby: |  
    360   {   
    361     'hr' => [ 'Mark McGwire', 'Sammy Sosa' ],  
    362     'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ]   
    363   }  
    364 syck: | 
    365   struct test_node seq1[] = { 
    366       { T_STR, 0, "Mark McGwire" }, 
    367       { T_STR, 0, "Sammy Sosa" }, 
    368       end_node 
    369   }; 
    370   struct test_node seq2[] = { 
    371       { T_STR, 0, "Sammy Sosa" }, 
    372       { T_STR, 0, "Ken Griffey" }, 
    373       end_node 
    374   }; 
    375   struct test_node map[] = { 
    376       { T_STR, 0, "hr" }, 
    377           { T_SEQ, 0, 0, seq1 }, 
    378       { T_STR, 0, "rbi" }, 
    379           { T_SEQ, 0, 0, seq2 }, 
    380       end_node 
    381   }; 
    382   struct test_node stream[] = { 
    383       { T_MAP, 0, 0, map }, 
    384       end_node 
    385   }; 
    386   
     210php: |  
     211  array(   
     212    'hr' => array( 'Mark McGwire', 'Sammy Sosa' ),  
     213    'rbi' => array( 'Sammy Sosa', 'Ken Griffey' )   
     214  ) 
    387215---  
    388216test: Node for Sammy Sosa appears twice in this document  
     
    654482     65 Home Runs 
    655483     0.278 Batting Average 
    656 perl: |  
    657   {   
    658     name           => 'Mark McGwire',   
    659     accomplishment => "Mark set a major league home run record in 1998.\n",  
    660     stats          => "65 Home Runs\n0.278 Batting Average\n"  
    661   }  
    662 ruby: |  
    663   {   
    664     'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n",  
    665     'stats' => "65 Home Runs\n0.278 Batting Average\n"  
    666   }  
    667 python: |  
    668     [  
    669         {  
    670         'name': 'Mark McGwire',  
    671         'accomplishment':   
    672             'Mark set a major league home run record in 1998.\n',  
    673         'stats': "65 Home Runs\n0.278 Batting Average\n"  
    674         }  
    675     ]  
    676 syck: | 
    677   struct test_node map[] = { 
    678       { T_STR, 0, "name" }, 
    679           { T_STR, 0, "Mark McGwire" }, 
    680       { T_STR, 0, "accomplishment" }, 
    681           { T_STR, 0, "Mark set a major league home run record in 1998.\n" }, 
    682       { T_STR, 0, "stats" }, 
    683           { T_STR, 0, "65 Home Runs\n0.278 Batting Average\n" }, 
    684       end_node 
    685   }; 
    686   struct test_node stream[] = { 
    687       { T_MAP, 0, 0, map }, 
    688       end_node 
    689   }; 
    690   
     484php: |  
     485  array(   
     486    'name'           => 'Mark McGwire',   
     487    'accomplishment' => "Mark set a major league home run record in 1998.\n",  
     488    'stats'          => "65 Home Runs\n0.278 Batting Average\n"  
     489  )  
    691490---  
    692491test: Quoted scalars  
     492todo: true 
    693493spec: 2.17 
    694494yaml: |  
     
    700500  quoted: ' # not a ''comment''.'  
    701501  tie-fighter: '|\-*-/|'  
    702 perl-not-working: |  
    703     {  
    704         unicode => "Sosa did fine.\x{263A}",  
    705         control => "\x081998\t1999\t2000\n",   
    706         hexesc  => "\r\n is \r\n",  
    707         single  => '"Howdy!" he cried.',  
    708         quoted   => " # not a 'comment'.",  
    709         "tie-fighter" => '|\\-*-/|',  
    710     }  
    711502ruby: |  
    712503  {  
     
    718509    "hexesc"=>"\r\n is \r\n"  
    719510  }  
    720 python: |  
    721     [ {  
    722         'unicode': u"Sosa did fine.\u263A",  
    723         'control': "\b1998\t1999\t2000\n",   
    724         'hexesc':  "\x0D\x0A is \r\n",  
    725         'single': '"Howdy!" he cried.',  
    726         'quoted': ' # not a \'comment\'.',  
    727         'tie-fighter': '|\-*-/|',  
    728     } ]  
    729  
    730  
    731511---  
    732512test: Multiline flow scalars  
     513todo: true 
    733514spec: 2.18  
    734515yaml: | 
     
    739520  quoted: "So does this 
    740521    quoted scalar.\n" 
    741 perl-not-working: |  
    742   {   
    743     plain  => 'This unquoted scalar spans many lines.',  
    744     quoted => "So does this quoted scalar.\n"  
    745   }  
    746522ruby: |  
    747523  {   
     
    749525    'quoted' => "So does this quoted scalar.\n"  
    750526  }  
    751 python: |  
    752     [ {  
    753         'plain': 'This unquoted scalar spans many lines.',  
    754         'quoted': 'So does this quoted scalar.\n'  
    755       }  
    756     ]  
    757 syck: | 
    758   struct test_node map[] = { 
    759       { T_STR, 0, "plain" }, 
    760           { T_STR, 0, "This unquoted scalar spans many lines." }, 
    761       { T_STR, 0, "quoted" }, 
    762           { T_STR, 0, "So does this quoted scalar.\n" }, 
    763       end_node 
    764   }; 
    765   struct test_node stream[] = { 
    766       { T_MAP, 0, 0, map }, 
    767       end_node 
    768   }; 
    769   
    770527---  
    771528test: Integers  
     
    774531  canonical: 12345  
    775532  decimal: +12,345  
    776   sexagecimal: 3:25:45 
    777533  octal: 014  
    778534  hexadecimal: 0xC  
    779 perl: |  
    780   {   
    781     canonical   => 12345,   
    782     decimal     => 12345,   
    783     octal       => oct("014"),  
    784     hexadecimal => hex("0xC"),  
    785   }  
    786 ruby: |  
    787   {   
     535php: |  
     536  array(   
    788537    'canonical' => 12345,   
    789538    'decimal' => 12345,   
    790     'sexagecimal' => 12345, 
    791     'octal' => '014'.oct,   
    792     'hexadecimal' => '0xC'.hex   
    793   }  
    794 python: |  
    795     [ {  
    796         'canonical': 12345,  
    797         'decimal': 12345,  
    798         'octal': 014,  
    799         'hexadecimal': 0xC  
    800     } ]  
    801 syck: | 
    802   struct test_node map[] = { 
    803       { T_STR, 0, "canonical" }, 
    804           { T_STR, 0, "12345" }, 
    805       { T_STR, 0, "decimal" }, 
    806           { T_STR, 0, "+12,345" }, 
    807       { T_STR, 0, "sexagecimal" }, 
    808           { T_STR, 0, "3:25:45" }, 
    809       { T_STR, 0, "octal" }, 
    810           { T_STR, 0, "014" }, 
    811       { T_STR, 0, "hexadecimal" }, 
    812           { T_STR, 0, "0xC" }, 
    813       end_node 
    814   }; 
    815   struct test_node stream[] = { 
    816       { T_MAP, 0, 0, map }, 
    817       end_node 
    818   }; 
    819   
     539    'octal' => 014,   
     540    'hexadecimal' => 0xC 
     541  ) 
    820542---  
    821543# FIX: spec shows parens around -inf and NaN 
     
    825547  canonical: 1.23015e+3  
    826548  exponential: 12.3015e+02  
    827   sexagecimal: 20:30.15 
    828549  fixed: 1,230.15  
    829550  negative infinity: -.inf 
    830551  not a number: .NaN  
    831 perl: |  
    832   {  
     552php: |  
     553  array(  
    833554    'canonical' => 1230.15,   
    834555    'exponential' => 1230.15,   
    835556    'fixed' => 1230.15,  
    836     'negative infinity' => "-.inf",  
    837     'not a number' => ".NaN",  
    838   }  
    839 ruby: |  
    840   {   
    841     'canonical' => 1230.15,   
    842     'exponential' => 1230.15,   
    843     'sexagecimal' => 1230.15,   
    844     'fixed' => 1230.15,  
    845     'negative infinity' => -1.0/0.0,  
    846     'not a number' => 0.0/0.0  
    847   }  
    848   if obj_y['not a number'].nan?   # NaN comparison doesn't work right against 0.0/0.0  
    849     obj_r['not a number'] = obj_y['not a number']  
    850   end  
    851 python: |  
    852     [ {  
    853         'canonical': 1.23015e+3,  
    854         'exponential': 1.23015e+3,  
    855         'fixed': 1230.15,  
    856         'negative infinity': '-.inf',  
    857         'not a number': '.NaN',  
    858     } ]  
    859 syck: | 
    860   struct test_node map[] = { 
    861       { T_STR, 0, "canonical" }, 
    862           { T_STR, 0, "1.23015e+3" }, 
    863       { T_STR, 0, "exponential" }, 
    864           { T_STR, 0, "12.3015e+02" }, 
    865       { T_STR, 0, "sexagecimal" }, 
    866           { T_STR, 0, "20:30.15" }, 
    867       { T_STR, 0, "fixed" }, 
    868           { T_STR, 0, "1,230.15" }, 
    869       { T_STR, 0, "negative infinity" }, 
    870           { T_STR, 0, "-.inf" }, 
    871       { T_STR, 0, "not a number" }, 
    872           { T_STR, 0, ".NaN" }, 
    873       end_node 
    874   }; 
    875   struct test_node stream[] = { 
    876       { T_MAP, 0, 0, map }, 
    877       end_node 
    878   }; 
    879   
     557    'negative infinity' => log(0),  
     558    'not a number' => -log(0),  
     559  ) 
    880560---  
    881561test: Miscellaneous  
     
    886566  false: n  
    887567  string: '12345'  
    888 perl: |  
    889   {  
    890     null   => undef,  
    891     true   => 1,  
    892     false  => 0,  
    893     string => "12345"  
    894   }  
    895 ruby: |   
    896   {   
    897     nil => nil,   
    898     true => true,   
    899     false => false,   
     568php: |   
     569  array(   
     570    '' => null,   
     571    1 => true,   
     572    0 => false,   
    900573    'string' => '12345'   
    901   }  
    902 python: |  
    903     [ {  
    904         'null': None,  
    905         'true': 1,  
    906         'false': 0,  
    907         'string': '12345',  
    908     } ]  
    909 syck: | 
    910   struct test_node map[] = { 
    911       { T_STR, 0, "null" }, 
    912           { T_STR, 0, "~" }, 
    913       { T_STR, 0, "true" }, 
    914           { T_STR, 0, "y" }, 
    915       { T_STR, 0, "false" }, 
    916           { T_STR, 0, "n" }, 
    917       { T_STR, 0, "string" }, 
    918           { T_STR, 0, "12345" }, 
    919       end_node 
    920   }; 
    921   struct test_node stream[] = { 
    922       { T_MAP, 0, 0, map }, 
    923       end_node 
    924   }; 
    925   
     574  )  
    926575--- 
    927576test: Timestamps 
     577todo: true 
    928578spec: 2.22 
    929579yaml: | 
     
    932582  spaced:  2001-12-14 21:59:43.10 -05:00 
    933583  date:   2002-12-14 # Time is noon UTC 
    934 perl: | 
    935   { 
    936     canonical => "2001-12-15T02:59:43.1Z", 
    937     iso8601   => "2001-12-14t21:59:43.10-05:00", 
    938     spaced    => "2001-12-14 21:59:43.10 -05:00", 
    939     date      => "2002-12-14", 
    940   } 
    941 ruby: | 
    942   { 
     584php: | 
     585  array( 
    943586    'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ), 
    944587    'iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 
    945588    'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 
    946589    'date' => Date.new( 2002, 12, 14 ) 
    947   } 
    948 syck: | 
    949   struct test_node map[] = { 
    950       { T_STR, 0, "canonical" }, 
    951           { T_STR, 0, "2001-12-15T02:59:43.1Z" }, 
    952       { T_STR, 0, "iso8601" }, 
    953           { T_STR, 0, "2001-12-14t21:59:43.10-05:00" }, 
    954       { T_STR, 0, "spaced" }, 
    955           { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" }, 
    956       { T_STR, 0, "date" }, 
    957           { T_STR, 0, "2002-12-14" }, 
    958       end_node 
    959   }; 
    960   struct test_node stream[] = { 
    961       { T_MAP, 0, 0, map }, 
    962       end_node 
    963   }; 
    964  
     590  ) 
    965591--- 
    966592test: legacy Timestamps test 
     593todo: true 
    967594spec: legacy D4 
    968595yaml: | 
     
    971598    spaced:  2001-12-14 21:59:43.00 -05:00 
    972599    date:   2002-12-14 
    973 python: | 
    974     [ { 
    975         'canonical': yaml.timestamp('2001-12-15T02:59:43.00Z'), 
    976         'iso8601':   yaml.timestamp('2001-03-01T02:59:43.00Z'), 
    977         'spaced':    yaml.timestamp('2001-12-15T02:59:43.00Z'), 
    978         'date':      yaml.timestamp('2002-12-14T00:00:00.00Z') 
    979     } ] 
    980 ruby: | 
    981    { 
     600php: | 
     601   array( 
    982602     'canonical' => Time::utc( 2001, 12, 15, 2, 59, 43, 0 ), 
    983603     'iso8601' => YAML::mktime( 2001, 2, 28, 21, 59, 43, 0, "-05:00" ), 
    984604     'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0, "-05:00" ), 
    985605     'date' => Date.new( 2002, 12, 14 ) 
    986    } 
    987 syck: | 
    988   struct test_node map[] = { 
    989       { T_STR, 0, "canonical" }, 
    990           { T_STR, 0, "2001-12-15T02:59:43.00Z" }, 
    991       { T_STR, 0, "iso8601" }, 
    992           { T_STR, 0, "2001-02-28t21:59:43.00-05:00" }, 
    993       { T_STR, 0, "spaced" }, 
    994           { T_STR, 0, "2001-12-14 21:59:43.00 -05:00" }, 
    995       { T_STR, 0, "date" }, 
    996           { T_STR, 0, "2002-12-14" }, 
    997       end_node 
    998   }; 
    999   struct test_node stream[] = { 
    1000       { T_MAP, 0, 0, map }, 
    1001       end_node 
    1002   }; 
    1003  
     606   ) 
    1004607--- 
    1005608test: Various explicit families 
     609todo: true 
    1006610spec: 2.23 
    1007611yaml: | 
     
    1028632    'application specific tag' => "SOMETHING: The semantics of the tag\nabove may be different for\ndifferent documents.\n" 
    1029633  } 
    1030 syck: | 
    1031   struct test_node map[] = { 
    1032       { T_STR, 0, "not-date" }, 
    1033           { T_STR, "tag:yaml.org,2002:str", "2002-04-28" }, 
    1034       { T_STR, 0, "picture" }, 
    1035           { T_STR, "tag:yaml.org,2002:binary", "R0lGODlhDAAMAIQAAP//9/X\n17unp5WZmZgAAAOfn515eXv\nPz7Y6OjuDg4J+fn5OTk6enp\n56enmleECcgggoBADs=\n" }, 
    1036       { T_STR, 0, "application specific tag" }, 
    1037           { T_STR, "x-private:something", "The semantics of the tag\nabove may be different for\ndifferent documents.\n" }, 
    1038       end_node 
    1039   }; 
    1040   struct test_node stream[] = { 
    1041       { T_MAP, 0, 0, map }, 
    1042       end_node 
    1043   }; 
    1044  
    1045634--- 
    1046635test: Application specific family 
     636todo: true 
    1047637spec: 2.24 
    1048638yaml: | 
     
    1116706    "Shape Container" 
    1117707  ] 
    1118 syck: | 
    1119   struct test_node point1[] = { 
    1120       { T_STR, 0, "x" }, 
    1121           { T_STR, 0, "73" }, 
    1122       { T_STR, 0, "y" }, 
    1123           { T_STR, 0, "129" }, 
    1124       end_node 
    1125   }; 
    1126   struct test_node point2[] = { 
    1127       { T_STR, 0, "x" }, 
    1128           { T_STR, 0, "89" }, 
    1129       { T_STR, 0, "y" }, 
    1130           { T_STR, 0, "102" }, 
    1131       end_node 
    1132   }; 
    1133   struct test_node map1[] = { 
    1134       { T_STR, 0, "center" }, 
    1135           { T_MAP, 0, 0, point1 }, 
    1136       { T_STR, 0, "radius" }, 
    1137           { T_STR, 0, "7" }, 
    1138       end_node 
    1139   }; 
    1140   struct test_node map2[] = { 
    1141       { T_STR, 0, "start" }, 
    1142           { T_MAP, 0, 0, point1 }, 
    1143       { T_STR, 0, "finish" }, 
    1144           { T_MAP, 0, 0, point2 }, 
    1145       end_node 
    1146   }; 
    1147   struct test_node map3[] = { 
    1148       { T_STR, 0, "start" }, 
    1149           { T_MAP, 0, 0, point1 }, 
    1150       { T_STR, 0, "color" }, 
    1151           { T_STR, 0, "0xFFEEBB" }, 
    1152       { T_STR, 0, "value" }, 
    1153           { T_STR, 0, "Pretty vector drawing." }, 
    1154       end_node 
    1155   }; 
    1156   struct test_node seq[] = { 
    1157       { T_MAP, "tag:clarkevans.com,2002:graph/circle", 0, map1 }, 
    1158       { T_MAP, "tag:clarkevans.com,2002:graph/line", 0, map2 }, 
    1159       { T_MAP, "tag:clarkevans.com,2002:graph/label", 0, map3 }, 
    1160       end_node 
    1161   }; 
    1162   struct test_node stream[] = { 
    1163       { T_SEQ, "tag:clarkevans.com,2002:graph/shape", 0, seq }, 
    1164       end_node 
    1165   }; 
    1166  
    1167708# --- 
    1168709# test: Unordered set 
     
    1178719--- 
    1179720test: Ordered mappings 
     721todo: true 
    1180722spec: 2.26 
    1181723yaml: | 
     
    1193735    'Ken Griffy', 58 
    1194736  ] 
    1195 syck: | 
    1196   struct test_node map1[] = { 
    1197       { T_STR, 0, "Mark McGwire" }, 
    1198           { T_STR, 0, "65" }, 
    1199       end_node 
    1200   }; 
    1201   struct test_node map2[] = { 
    1202       { T_STR, 0, "Sammy Sosa" }, 
    1203           { T_STR, 0, "63" }, 
    1204       end_node 
    1205   }; 
    1206   struct test_node map3[] = { 
    1207       { T_STR, 0, "Ken Griffy" }, 
    1208           { T_STR, 0, "58" }, 
    1209       end_node 
    1210   }; 
    1211   struct test_node seq[] = { 
    1212       { T_MAP, 0, 0, map1 }, 
    1213       { T_MAP, 0, 0, map2 }, 
    1214       { T_MAP, 0, 0, map3 }, 
    1215       end_node 
    1216   }; 
    1217   struct test_node stream[] = { 
    1218       { T_SEQ, "tag:yaml.org,2002:omap", 0, seq }, 
    1219       end_node 
    1220   }; 
    1221  
    1222737--- 
    1223738test: Invoice 
     739todo: true 
    1224740spec: 2.27 
    1225741yaml: | 
     
    1268784     'tax' => 251.42, 'total' => 4443.52, 
    1269785     'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" } 
    1270 syck: | 
    1271   struct test_node prod1[] = { 
    1272       { T_STR, 0, "sku" }, 
    1273           { T_STR, 0, "BL394D" }, 
    1274       { T_STR, 0, "quantity" }, 
    1275           { T_STR, 0, "4" }, 
    1276       { T_STR, 0, "description" }, 
    1277           { T_STR, 0, "Basketball" }, 
    1278       { T_STR, 0, "price" }, 
    1279           { T_STR, 0, "450.00" }, 
    1280       end_node 
    1281   }; 
    1282   struct test_node prod2[] = { 
    1283       { T_STR, 0, "sku" }, 
    1284           { T_STR, 0, "BL4438H" }, 
    1285       { T_STR, 0, "quantity" }, 
    1286           { T_STR, 0, "1" }, 
    1287       { T_STR, 0, "description" }, 
    1288           { T_STR, 0, "Super Hoop" }, 
    1289       { T_STR, 0, "price" }, 
    1290           { T_STR, 0, "2392.00" }, 
    1291       end_node 
    1292   }; 
    1293   struct test_node products[] = { 
    1294       { T_MAP, 0, 0, prod1 }, 
    1295       { T_MAP, 0, 0, prod2 }, 
    1296       end_node 
    1297   }; 
    1298   struct test_node address[] = { 
    1299       { T_STR, 0, "lines" }, 
    1300           { T_STR, 0, "458 Walkman Dr.\nSuite #292\n" }, 
    1301       { T_STR, 0, "city" }, 
    1302           { T_STR, 0, "Royal Oak" }, 
    1303       { T_STR, 0, "state" }, 
    1304           { T_STR, 0, "MI" }, 
    1305       { T_STR, 0, "postal" }, 
    1306           { T_STR, 0, "48046" }, 
    1307       end_node 
    1308   }; 
    1309   struct test_node id001[] = { 
    1310       { T_STR, 0, "given" }, 
    1311           { T_STR, 0, "Chris" }, 
    1312       { T_STR, 0, "family" }, 
    1313           { T_STR, 0, "Dumars" }, 
    1314       { T_STR, 0, "address" }, 
    1315           { T_MAP, 0, 0, address }, 
    1316       end_node 
    1317   }; 
    1318   struct test_node map[] = { 
    1319       { T_STR, 0, "invoice" }, 
    1320           { T_STR, 0, "34843" }, 
    1321       { T_STR, 0, "date" }, 
    1322           { T_STR, 0, "2001-01-23" }, 
    1323       { T_STR, 0, "bill-to" }, 
    1324           { T_MAP, 0, 0, id001 }, 
    1325       { T_STR, 0, "ship-to" }, 
    1326           { T_MAP, 0, 0, id001 }, 
    1327       { T_STR, 0, "product" }, 
    1328           { T_SEQ, 0, 0, products }, 
    1329       { T_STR, 0, "tax" }, 
    1330           { T_STR, 0, "251.42" },  
    1331       { T_STR, 0, "total" }, 
    1332           { T_STR, 0, "4443.52" }, 
    1333       { T_STR, 0, "comments" }, 
    1334           { T_STR, 0, "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" }, 
    1335       end_node 
    1336   }; 
    1337   struct test_node stream[] = { 
    1338       { T_MAP, "tag:clarkevans.com,2002:invoice", 0, map }, 
    1339       end_node 
    1340   }; 
    1341  
    1342786--- 
    1343787test: Log file 
     788todo: true 
    1344789spec: 2.28 
    1345790yaml: | 
     
    1381826           { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" },  
    1382827           { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } )  
    1383 syck: | 
    1384   struct test_node map1[] = { 
    1385       { T_STR, 0, "Time" },  
    1386           { T_STR, 0, "2001-11-23 15:01:42 -05:00" }, 
    1387       { T_STR, 0, "User" },  
    1388           { T_STR, 0, "ed" }, 
    1389       { T_STR, 0, "Warning" },  
    1390           { T_STR, 0, "This is an error message for the log file\n" }, 
    1391       end_node 
    1392   }; 
    1393   struct test_node map2[] = { 
    1394       { T_STR, 0, "Time" },  
    1395           { T_STR, 0, "2001-11-23 15:02:31 -05:00" }, 
    1396       { T_STR, 0, "User" },  
    1397           { T_STR, 0, "ed" }, 
    1398       { T_STR, 0, "Warning" },  
    1399           { T_STR, 0, "A slightly different error message.\n" }, 
    1400       end_node 
    1401   }; 
    1402   struct test_node file1[] = { 
    1403       { T_STR, 0, "file" },  
    1404           { T_STR, 0, "TopClass.py" }, 
    1405       { T_STR, 0, "line" },  
    1406           { T_STR, 0, "23" }, 
    1407       { T_STR, 0, "code" },  
    1408           { T_STR, 0, "x = MoreObject(\"345\\n\")\n" }, 
    1409       end_node 
    1410   }; 
    1411   struct test_node file2[] = { 
    1412       { T_STR, 0, "file" },  
    1413           { T_STR, 0, "MoreClass.py" }, 
    1414       { T_STR, 0, "line" },  
    1415           { T_STR, 0, "58" }, 
    1416       { T_STR, 0, "code" },  
    1417           { T_STR, 0, "foo = bar" }, 
    1418       end_node 
    1419   }; 
    1420   struct test_node stack[] = { 
    1421       { T_MAP, 0, 0, file1 }, 
    1422       { T_MAP, 0, 0, file2 }, 
    1423       end_node 
    1424   }; 
    1425   struct test_node map3[] = { 
    1426       { T_STR, 0, "Date" },  
    1427           { T_STR, 0, "2001-11-23 15:03:17 -05:00" }, 
    1428       { T_STR, 0, "User" },  
    1429           { T_STR, 0, "ed" }, 
    1430       { T_STR, 0, "Fatal" },  
    1431           { T_STR, 0, "Unknown variable \"bar\"\n" }, 
    1432       { T_STR, 0, "Stack" },  
    1433           { T_SEQ, 0, 0, stack }, 
    1434       end_node 
    1435   }; 
    1436   struct test_node stream[] = { 
    1437       { T_MAP, 0, 0, map1 }, 
    1438       { T_MAP, 0, 0, map2 }, 
    1439       { T_MAP, 0, 0, map3 }, 
    1440       end_node 
    1441   }; 
    1442828documents: 3  
    1443829  
     
    1455841   # These are three throwaway comment 
    1456842   # lines (the first line is empty). 
    1457 ruby: |  
    1458    {  
     843php: |  
     844   array(  
    1459845     'this' => "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"  
    1460    }  
    1461 syck: | 
    1462   struct test_node map[] = { 
    1463       { T_STR, 0, "this" }, 
    1464           { T_STR, 0, "contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n" }, 
    1465       end_node 
    1466   }; 
    1467   struct test_node stream[] = { 
    1468       { T_MAP, 0, 0, map }, 
    1469       end_node 
    1470   }; 
    1471   
     846   ) 
    1472847---  
    1473848test: Document with a single value  
     849todo: true 
    1474850yaml: |  
    1475851   --- >  
     
    1480856ruby: |  
    1481857   "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n"  
    1482 syck: | 
    1483   struct test_node stream[] = { 
    1484       { T_STR, 0, "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n" }, 
    1485       end_node 
    1486   }; 
    1487   
    1488858---  
    1489859test: Document stream  
     860todo: true 
    1490861yaml: |  
    1491862   ---  
     
    1513884      'url' => '/toc.html'  
    1514885   } )  
    1515 syck: | 
    1516   struct test_node map1[] = { 
    1517       { T_STR, 0, "at" },  
    1518           { T_STR, 0, "2001-08-12 09:25:00.00 Z" }, 
    1519       { T_STR, 0, "type" },  
    1520           { T_STR, 0, "GET" }, 
    1521       { T_STR, 0, "HTTP" },  
    1522           { T_STR, 0, "1.0" }, 
    1523       { T_STR, 0, "url" },  
    1524           { T_STR, 0, "/index.html" }, 
    1525       end_node 
    1526   }; 
    1527   struct test_node map2[] = { 
    1528       { T_STR, 0, "at" },  
    1529           { T_STR, 0, "2001-08-12 09:25:10.00 Z" }, 
    1530       { T_STR, 0, "type" },  
    1531           { T_STR, 0, "GET" }, 
    1532       { T_STR, 0, "HTTP" },  
    1533           { T_STR, 0, "1.0" }, 
    1534       { T_STR, 0, "url" },  
    1535           { T_STR, 0, "/toc.html" }, 
    1536       end_node 
    1537   }; 
    1538   struct test_node stream[] = { 
    1539       { T_MAP, 0, 0, map1 }, 
    1540       { T_MAP, 0, 0, map2 }, 
    1541       end_node 
    1542   }; 
    1543886documents: 2  
    1544887  
     
    1550893   date    : 2001-01-23  
    1551894   total   : 4443.52  
    1552 ruby: |  
    1553    {  
    1554       'invoice' => 34843,  
    1555       'date' => Date.new( 2001, 1, 23 ),  
     895php: |  
     896   array(  
     897      'invoice' => 34843, 
     898      'date' => mktime(0, 0, 0, 1, 23, 2001),  
    1556899      'total' => 4443.52  
    1557    }  
    1558 syck: | 
    1559   struct test_node map[] = { 
    1560       { T_STR, 0, "invoice" },  
    1561           { T_STR, 0, "34843" }, 
    1562       { T_STR, 0, "date" },  
    1563           { T_STR, 0, "2001-01-23" }, 
    1564       { T_STR, 0, "total" },  
    1565           { T_STR, 0, "4443.52" }, 
    1566       end_node 
    1567   }; 
    1568   struct test_node stream[] = { 
    1569       { T_MAP, 0, 0, map }, 
    1570       end_node 
    1571   }; 
    1572   
     900   ) 
    1573901---  
    1574902test: Single-line documents  
     903todo: true 
    1575904yaml: |  
    1576905  # The following is a sequence of three documents.  
     
    1585914  y.add( [] )  
    1586915  y.add( '' )  
    1587 syck: | 
    1588   struct test_node map[] = { 
    1589       end_node 
    1590   }; 
    1591   struct test_node seq[] = { 
    1592       end_node 
    1593   }; 
    1594   struct test_node stream[] = { 
    1595       { T_MAP, 0, 0, map }, 
    1596       { T_SEQ, 0, 0, seq }, 
    1597       { T_STR, 0, "" }, 
    1598       end_node 
    1599   }; 
    1600916documents: 3  
    1601917  
    1602918---  
    1603919test: Document with pause  
     920todo: true 
    1604921yaml: |  
    1605922  # A communication channel based on a YAML stream.  
     
    1623940    { "payload" => "Whatever", "sent at" => YAML::mktime( 2002, 6, 6, 12, 5, 53, 0.47 ) }  
    1624941  )  
    1625 syck: | 
    1626   struct test_node map1[] = { 
    1627       { T_STR, 0, "sent at" }, 
    1628           { T_STR, 0, "2002-06-06 11:46:25.10 Z" }, 
    1629       { T_STR, 0, "payload" }, 
    1630           { T_STR, 0, "Whatever" }, 
    1631       end_node 
    1632   }; 
    1633   struct test_node map2[] = { 
    1634       { T_STR, 0, "sent at" }, 
    1635           { T_STR, 0, "2002-06-06 12:05:53.47 Z" }, 
    1636       { T_STR, 0, "payload" }, 
    1637           { T_STR, 0, "Whatever" }, 
    1638       end_node 
    1639   }; 
    1640   struct test_node stream[] = { 
    1641       { T_MAP, 0, 0, map1 }, 
    1642       { T_MAP, 0, 0, map2 }, 
    1643       end_node 
    1644   }; 
    1645942documents: 2  
    1646943  
     
    1651948   also int: ! "12"  
    1652949   string: !str 12  
    1653 ruby: |  
    1654    { 'integer' => 12, 'also int' => 12, 'string' => '12' }  
    1655 syck: | 
    1656   struct test_node map[] = { 
    1657       { T_STR, 0, "integer" }, 
    1658           { T_STR, "tag:yaml.org,2002:int", "12" }, 
    1659       { T_STR, 0, "also int" }, 
    1660           { T_STR, "tag:yaml.org,2002:int", "12" }, 
    1661       { T_STR, 0, "string" }, 
    1662           { T_STR, "tag:yaml.org,2002:str", "12" }, 
    1663       end_node 
    1664   }; 
    1665   struct test_node stream[] = { 
    1666       { T_MAP, 0, 0, map }, 
    1667       end_node 
    1668   }; 
    1669   
     950php: |  
     951   array( 'integer' => 12, 'also int' => 12, 'string' => '12' ) 
    1670952---  
    1671953test: Private types  
     954todo: true 
    1672955yaml: |  
    1673956  # Both examples below make use of the 'x-private:ball'  
     
    1690973      { 'material' => 'steel' } ) }  
    1691974  )  
    1692 syck: | 
    1693   struct test_node pool[] = { 
    1694       { T_STR, 0, "number" }, 
    1695           { T_STR, 0, "8" }, 
    1696       { T_STR, 0, "color" }, 
    1697           { T_STR, 0, "black" }, 
    1698       end_node 
    1699   }; 
    1700   struct test_node map1[] = { 
    1701       { T_STR, 0, "pool" }, 
    1702           { T_MAP, "x-private:ball", 0, pool }, 
    1703       end_node 
    1704   }; 
    1705   struct test_node bearing[] = { 
    1706       { T_STR, 0, "material" }, 
    1707           { T_STR, 0, "steel" }, 
    1708       end_node 
    1709   }; 
    1710   struct test_node map2[] = { 
    1711       { T_STR, 0, "bearing" }, 
    1712           { T_MAP, "x-private:ball", 0, bearing }, 
    1713       end_node 
    1714   }; 
    1715   struct test_node stream[] = { 
    1716       { T_MAP, 0, 0, map1 }, 
    1717       { T_MAP, 0, 0, map2 }, 
    1718       end_node 
    1719   }; 
    1720975documents: 2  
    1721976  
     
    1725980  # The URI is 'tag:yaml.org,2002:str'  
    1726981  - !str a Unicode string  
    1727 python: |  
    1728   [ [ 'a Unicode string' ] ]  
    1729 ruby: |  
    1730   [ 'a Unicode string' ]  
    1731 syck: | 
    1732   struct test_node seq[] = { 
    1733       { T_STR, "tag:yaml.org,2002:str", "a Unicode string" }, 
    1734       end_node 
    1735   }; 
    1736   struct test_node stream[] = { 
    1737       { T_SEQ, 0, 0, seq }, 
    1738       end_node 
    1739   }; 
    1740   
     982php: |  
     983  array( 'a Unicode string' ) 
    1741984---  
    1742985test: Type family under perl.yaml.org  
     986todo: true 
    1743987yaml: |  
    1744988  # The URI is 'tag:perl.yaml.org,2002:Text::Tabs'  
     
    1746990ruby: |  
    1747991  [ YAML::DomainType.new( 'perl.yaml.org,2002', 'Text::Tabs', {} ) ] 
    1748 syck: | 
    1749   struct test_node map[] = { 
    1750       end_node 
    1751   }; 
    1752   struct test_node seq[] = { 
    1753       { T_MAP, "tag:perl.yaml.org,2002:Text::Tabs", 0, map }, 
    1754       end_node 
    1755   }; 
    1756   struct test_node stream[] = { 
    1757       { T_SEQ, 0, 0, seq }, 
    1758       end_node 
    1759   }; 
    1760   
    1761992---  
    1762993test: Type family under clarkevans.com  
     994todo: true 
    1763995yaml: |  
    1764996  # The URI is 'tag:clarkevans.com,2003-02:timesheet'  
     
    1766998ruby: |  
    1767999  [ YAML::DomainType.new( 'clarkevans.com,2003-02', 'timesheet', {} ) ] 
    1768 syck: | 
    1769   struct test_node map[] = { 
    1770       end_node 
    1771   }; 
    1772   struct test_node seq[] = { 
    1773       { T_MAP, "tag:clarkevans.com,2003-02:timesheet", 0, map }, 
    1774       end_node 
    1775   }; 
    1776   struct test_node stream[] = { 
    1777       { T_SEQ, 0, 0, seq }, 
    1778       end_node 
    1779   }; 
    1780   
    17811000---  
    17821001test: URI Escaping  
     1002todo: true 
    17831003yaml: |  
    17841004  same:  
     
    17971017ruby: |  
    17981018  { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value', 'ONE: value' ] }  
    1799 syck: | 
    1800   struct test_node same[] = { 
    1801       { T_STR, "tag:domain.tld,2002:type0", "value" }, 
    1802       { T_STR, "tag:domain.tld,2002:type0", "value" }, 
    1803       end_node 
    1804   }; 
    1805   struct test_node diff[] = { 
    1806       { T_STR, "tag:domain.tld,2002:type%30", "value" }, 
    1807       { T_STR, "tag:domain.tld,2002:type0", "value" }, 
    1808       end_node 
    1809   }; 
    1810   struct test_node map[] = { 
    1811       { T_STR, 0, "same" }, 
    1812           { T_SEQ, 0, 0, same }, 
    1813       { T_STR, 0, "different" }, 
    1814           { T_SEQ, 0, 0, diff }, 
    1815       end_node 
    1816   }; 
    1817   struct test_node stream[] = { 
    1818       { T_MAP, 0, 0, map }, 
    1819       end_node 
    1820   }; 
    1821   
    18221019---  
    18231020test: URI Prefixing  
     1021todo: true 
    18241022yaml: |  
    18251023  # 'tag:domain.tld,2002:invoice' is some type family.  
     
    18491047---  
    18501048test: Overriding anchors  
     1049todo: true 
    18511050yaml: |  
    18521051  anchor : &A001 This scalar has an anchor.  
     
    18761075---  
    18771076test: Flow and block formatting  
     1077todo: true 
    18781078yaml: |  
    18791079  empty: []  
     
    18921092    'block' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ],  
    18931093    "A folded sequence entry\n", 'Sixth item in top sequence' ] }  
    1894 syck: | 
    1895   struct test_node empty[] = { 
    1896       end_node 
    1897   }; 
    1898   struct test_node flow[] = { 
    1899       { T_STR, 0, "one" }, 
    1900       { T_STR, 0, "two" }, 
    1901       { T_STR, 0, "three" }, 
    1902       { T_STR, 0, "four" }, 
    1903       { T_STR, 0, "five" }, 
    1904       end_node 
    1905   }; 
    1906   struct test_node inblock[] = { 
    1907       { T_STR, 0, "Subordinate sequence entry" }, 
    1908       end_node 
    1909   }; 
    1910   struct test_node block[] = { 
    1911       { T_STR, 0, "First item in top sequence" }, 
    1912       { T_SEQ, 0, 0, inblock }, 
    1913       { T_STR, 0, "A folded sequence entry\n" }, 
    1914       { T_STR, 0, "Sixth item in top sequence" }, 
    1915       end_node 
    1916   }; 
    1917   struct test_node map[] = { 
    1918       { T_STR, 0, "empty" }, 
    1919           { T_SEQ, 0, 0, empty }, 
    1920       { T_STR, 0, "flow" }, 
    1921           { T_SEQ, 0, 0, flow }, 
    1922       { T_STR, 0, "block" }, 
    1923           { T_SEQ, 0, 0, block }, 
    1924       end_node 
    1925   }; 
    1926   struct test_node stream[] = { 
    1927       { T_MAP, 0, 0, map }, 
    1928       end_node 
    1929   }; 
    1930   
    19311094---  
    19321095test: Complete mapping test  
     1096todo: true 
    19331097yaml: | 
    19341098 empty: {}  
     
    19961160    end  
    19971161  }  
    1998   
    19991162---  
    20001163test: Literal explicit indentation 
     
    20191182   redundant: |2 
    20201183     This value is indented 2 spaces. 
    2021 ruby: | 
    2022    {  
     1184php: | 
     1185   array(  
    20231186      'leading spaces' => "    This value starts with four spaces.\n",  
    20241187      'leading line break' => "\nThis value starts with a line break.\n",  
    20251188      'leading comment indicator' => "# first line starts with a\n# character.\n",  
    20261189      'redundant' => "This value is indented 2 spaces.\n"  
    2027    }  
    2028  
     1190   ) 
    20291191--- 
    20301192test: Chomping and keep modifiers 
     
    20441206     
    20451207    same as "kept" above: "This has two newlines.\n\n" 
    2046 ruby: |  
    2047     {   
     1208php: |  
     1209    array(   
    20481210      'clipped' => "This has one newline.\n",  
    20491211      'same as "clipped" above' => "This has one newline.\n",  
     
    20521214      'kept' => "This has two newlines.\n\n",  
    20531215      'same as "kept" above' => "This has two newlines.\n\n"  
    2054     }  
    2055   
     1216    ) 
    20561217---  
    20571218test: Literal combinations  
     1219todo: true 
    20581220yaml: |  
    20591221   empty: | 
     
    20891251    
    20901252   both are equal to: "  This has no newline." 
    2091 ruby: |  
    2092    {  
     1253php: |  
     1254   array(  
    20931255     'empty' => '',  
    20941256     'literal' => "The \\ ' \" characters may be\nfreely used. Leading white\n   space " +  
     
    21011263     'also written as' => '  This has no newline.',  
    21021264     'both are equal to' => '  This has no newline.'  
    2103    }  
    2104   
     1265   ) 
    21051266---  
    21061267test: Folded combinations  
     1268todo: true 
    21071269yaml: |  
    21081270   empty: >  
     
    21561318   # Explicit comments may follow  
    21571319   # but must be less indented.  
    2158 ruby: |  
    2159    {  
     1320php: |  
     1321   array(  
    21601322     'empty' => '',  
    2161      'one paragraph' => 'Line feeds are converted to spaces, so this value' +  
     1323     'one paragraph' => 'Line feeds are converted to spaces, so this value'. 
    21621324       " contains no line breaks except for the final one.\n",  
    2163      'multiple paragraphs' => "\nAn empty line, either at the start or in the value:\n" +  
     1325     'multiple paragraphs' => "\nAn empty line, either at the start or in the value:\n". 
    21641326       "Is interpreted as a line break. Thus this value contains three line breaks.\n",  
    2165      'indented text' => "This is a folded paragraph followed by a list:\n" +  
    2166        " * first entry\n * second entry\nFollowed by another folded paragraph, " +  
     1327     'indented text' => "This is a folded paragraph followed by a list:\n". 
     1328       " * first entry\n * second entry\nFollowed by another folded paragraph, ". 
    21671329       "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n",  
    2168      'above is equal to' => "This is a folded paragraph followed by a list:\n" +  
    2169        " * first entry\n * second entry\nFollowed by another folded paragraph, " +  
     1330     'above is equal to' => "This is a folded paragraph followed by a list:\n". 
     1331       " * first entry\n * second entry\nFollowed by another folded paragraph, ". 
    21701332       "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n"  
    2171    }  
    2172   
     1333   ) 
    21731334---  
    21741335test: Single quotes  
     1336todo: true 
    21751337yaml: |  
    21761338   empty: '' 
     
    21831345         line break' 
    21841346   is same as: "this contains six spaces\nand one line break"  
    2185 ruby: |  
    2186    {  
     1347php: |  
     1348   array(  
    21871349     'empty' => '',  
    21881350     'second' => '! : \\ etc. can be used freely.',  
     
    21901352     'span' => "this contains six spaces\nand one line break",  
    21911353     'is same as' => "this contains six spaces\nand one line break"  
    2192    }  
    2193   
     1354   ) 
    21941355---  
    21951356test: Double quotes 
     1357todo: true 
    21961358yaml: | 
    21971359   empty: "" 
     
    22031365         spaces"  
    22041366   is equal to: "this contains four  spaces" 
    2205 ruby: |  
    2206    {  
     1367php: |  
     1368   array(  
    22071369     'empty' => '',  
    22081370     'second' => '! : etc. can be used freely.',  
     
    22111373     'span' => "this contains four  spaces",  
    22121374     'is equal to' => "this contains four  spaces"  
    2213    }  
    2214   
     1375   ) 
    22151376---  
    22161377test: Unquoted strings  
     1378todo: true 
    22171379yaml: |  
    22181380   first: There is no unquoted empty string. 
     
    22391401   note: { one-line keys: but multi-line values }  
    22401402 
    2241 ruby: |  
    2242    {  
     1403php: |  
     1404   array(  
    22431405     'first' => 'There is no unquoted empty string.',  
    22441406     'second' => 12,  
     
    22481410     'flow' => [ 'can span lines', 'like this' ],  
    22491411     'note' => { 'one-line keys' => 'but multi-line values' }  
    2250    }  
    2251   
     1412   ) 
    22521413---  
    22531414test: Spanning sequences  
     1415todo: true 
    22541416yaml: |  
    22551417   # The following are equal seqs  
     
    22611423     - one  
    22621424     - two  
    2263 ruby: |  
    2264    {  
     1425php: |  
     1426   array(  
    22651427     'flow' => [ 'one', 'two' ],  
    22661428     'spanning' => [ 'one', 'two' ],  
    22671429     'block' => [ 'one', 'two' ]  
    2268    }  
    2269   
     1430   ) 
    22701431---  
    22711432test: Flow mappings  
     
    22771438       one: 1  
    22781439       two: 2  
    2279 ruby: |  
    2280    {  
    2281      'flow' => { 'one' => 1, 'two' => 2 },  
    2282      'block' => { 'one' => 1, 'two' => 2 }  
    2283    }  
    2284  
     1440php: |  
     1441   array(  
     1442     'flow' => array( 'one' => 1, 'two' => 2 ),  
     1443     'block' => array( 'one' => 1, 'two' => 2 ) 
     1444   ) 
    22851445--- 
    22861446test: Representations of 12 
     1447todo: true 
    22871448yaml: | 
    22881449   - 12 # An integer  
     
    23021463   - foo/bar 
    23031464   - /a.*b/ 
    2304 ruby: | 
    2305    [ 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' ] 
    2306  
     1465php: | 
     1466   array( 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' ) 
    23071467--- 
    23081468test: "Null" 
     1469todo: true 
    23091470yaml: | 
    23101471   canonical: ~ 
     
    23241485         only two with values. 
    23251486 
    2326 ruby: | 
    2327    {  
    2328      'canonical' => nil,  
    2329      'english' => nil,  
    2330      'sparse' => [ nil, '2nd entry', nil, '4th entry', nil ],  
     1487php: | 
     1488   array ( 
     1489     'canonical' => null,  
     1490     'english' => null,  
     1491     'sparse' => array( null, '2nd entry', null, '4th entry', null ]),  
    23311492     'four' => 'This mapping has five keys, only two with values.' 
    2332    }  
    2333  
     1493   )  
    23341494--- 
    23351495test: Omap 
     1496todo: true 
    23361497yaml: | 
    23371498   # Explicitly typed dictionary. 
     
    23521513--- 
    23531514test: Pairs 
     1515todo: true 
    23541516yaml: | 
    23551517  # Explicitly typed pairs. 
     
    23711533--- 
    23721534test: Set 
     1535todo: true 
    23731536yaml: | 
    23741537  # Explicitly typed set. 
     
    23921555   logical:  true  
    23931556   answer: no  
    2394 ruby: |  
    2395    {  
     1557php: |  
     1558   array(  
    23961559     false => 'used as key',  
    23971560     'logical' => true,  
    23981561     'answer' => false  
    2399    }  
    2400  
     1562   ) 
    24011563---  
    24021564test: Integer  
     
    24061568   octal: 014  
    24071569   hexadecimal: 0xC  
    2408 ruby: |  
    2409    {  
     1570php: |  
     1571   array(  
    24101572     'canonical' => 12345,  
    24111573     'decimal' => 12345,  
    24121574     'octal' => 12,  
    24131575     'hexadecimal' => 12   
    2414    }  
    2415   
     1576   ) 
    24161577---  
    24171578test: Float  
     
    24221583   negative infinity: -.inf 
    24231584   not a number: .NaN  
    2424 ruby: |  
    2425   {   
     1585php: |  
     1586  array(   
    24261587    'canonical' => 1230.15,   
    24271588    'exponential' => 1230.15,   
    24281589    'fixed' => 1230.15,  
    2429     'negative infinity' => -1.0/0.0,  
    2430     'not a number' => 0.0/0.0  
    2431   }  
    2432   if obj_y['not a number'].nan?   # NaN comparison doesn't work right against 0.0/0.0  
    2433     obj_r['not a number'] = obj_y['not a number']  
    2434   end  
    2435   
     1590    'negative infinity' => log(0),  
     1591    'not a number' => -log(0)  
     1592  ) 
    24361593---  
    24371594test: Timestamp  
     1595todo: true 
    24381596yaml: |  
    24391597   canonical:       2001-12-15T02:59:43.1Z  
     
    24421600   date (noon UTC): 2002-12-14  
    24431601ruby: |  
    2444    {  
     1602   array(  
    24451603     'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ),  
    24461604     'valid iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),  
    24471605     'space separated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),  
    24481606     'date (noon UTC)' => Date.new( 2002, 12, 14 )  
    2449    }  
    2450 syck: | 
    2451   struct test_node map[] = { 
    2452       { T_STR, 0, "canonical" }, 
    2453           { T_STR, 0, "2001-12-15T02:59:43.1Z" }, 
    2454       { T_STR, 0, "valid iso8601" }, 
    2455           { T_STR, 0, "2001-12-14t21:59:43.10-05:00" }, 
    2456       { T_STR, 0, "space separated" }, 
    2457           { T_STR, 0, "2001-12-14 21:59:43.10 -05:00" }, 
    2458       { T_STR, 0, "date (noon UTC)" }, 
    2459           { T_STR, 0, "2002-12-14" }, 
    2460       end_node 
    2461   }; 
    2462   struct test_node stream[] = { 
    2463       { T_MAP, 0, 0, map }, 
    2464       end_node 
    2465   }; 
    2466  
    2467   
     1607   ) 
    24681608---  
    24691609test: Binary  
     1610todo: true 
    24701611yaml: |  
    24711612   canonical: !binary "\ 
     
    24931634--- 
    24941635test: Merge key 
     1636todo: true 
    24951637yaml: | 
    24961638  --- 
     
    25451687---  
    25461688test: Default key  
     1689todo: true 
    25471690yaml: |  
    25481691   ---     # Old schema  
     
    25681711---  
    25691712test: Special keys  
     1713todo: true 
    25701714yaml: |  
    25711715   "!": These three keys  
  • branches/1.1/test/unit/util/fixtures/yaml/YtsTypeTransfers.yml

    r7892 r7923  
    167167---  
    168168test: Integers  
     169dump_skip: true 
    169170brief: >  
    170171    An integer is a series of numbers, optionally  
     
    199200---  
    200201test: Floats  
     202dump_skip: true 
    201203brief: >  
    202204     Floats are represented by numbers with decimals,  
  • branches/1.1/test/unit/util/fixtures/yaml/index.yml

    r7892 r7923  
    99- YtsFoldedScalars 
    1010- YtsNullsAndEmpties 
    11 #- YtsSpecificationExamples 
     11- YtsSpecificationExamples 
    1212- YtsTypeTransfers 
  • branches/1.1/test/unit/util/sfYamlDumperTest.php

    r7919 r7923  
    1313require_once(dirname(__FILE__).'/../../../lib/util/sfYamlDumper.class.php'); 
    1414 
    15 $t = new lime_test(69, new lime_output_color()); 
     15$t = new lime_test(134, new lime_output_color()); 
    1616 
    1717$parser = new sfYamlParser(); 
     
    3535 
    3636    $test = $parser->parse($yaml); 
    37     if (isset($test['todo']) && $test['todo']) 
     37    if (isset($test['dump_skip']) && $test['dump_skip']) 
     38    { 
     39      continue; 
     40    } 
     41    else if (isset($test['todo']) && $test['todo']) 
    3842    { 
    3943      $t->todo($test['test']); 
     
    4347      $expected = eval('return '.trim($test['php']).';'); 
    4448 
    45       $t->is($parser->parse($dumper->dump($expected, 10)), $expected, $test['test'].' (dumper)'); 
     49      $t->is_deeply($parser->parse($dumper->dump($expected, 10)), $expected, $test['test']); 
    4650    } 
    4751  } 
  • branches/1.1/test/unit/util/sfYamlParserTest.php

    r7919 r7923  
    1212require_once(dirname(__FILE__).'/../../../lib/util/sfYamlParser.class.php'); 
    1313 
    14 $t = new lime_test(66, new lime_output_color()); 
     14$t = new lime_test(133, new lime_output_color()); 
    1515 
    1616$parser = new sfYamlParser(); 
     
    4141      $expected = var_export(eval('return '.trim($test['php']).';'), true); 
    4242 
    43       $t->is(var_export($parser->parse($test['yaml']), true), $expected, $test['test'].' (parser)'); 
     43      $t->is(var_export($parser->parse($test['yaml']), true), $expected, $test['test']); 
    4444    } 
    4545  } 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.