Changeset 7923
- Timestamp:
- 03/16/08 22:03:59 (1 year ago)
- Files:
-
- branches/1.1/lib/util/sfYamlInline.class.php (modified) (1 diff)
- branches/1.1/lib/util/sfYamlParser.class.php (modified) (6 diffs)
- branches/1.1/test/unit/util/fixtures/yaml/YtsSpecificationExamples.yml (modified) (63 diffs)
- branches/1.1/test/unit/util/fixtures/yaml/YtsTypeTransfers.yml (modified) (2 diffs)
- branches/1.1/test/unit/util/fixtures/yaml/index.yml (modified) (1 diff)
- branches/1.1/test/unit/util/sfYamlDumperTest.php (modified) (3 diffs)
- branches/1.1/test/unit/util/sfYamlParserTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/util/sfYamlInline.class.php
r7922 r7923 70 70 return 'false'; 71 71 case ctype_digit($value): 72 return (int) $value;72 return is_string($value) ? "'$value'" : (int) $value; 73 73 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); 75 75 case false !== strpos($value, "\n"): 76 76 return sprintf('"%s"', str_replace(array('"', "\n"), array('\\"', '\n'), $value)); branches/1.1/lib/util/sfYamlParser.class.php
r7919 r7923 161 161 if ($this->isCurrentLineEmpty()) 162 162 { 163 if ( !$this->isCurrentLineComment())163 if ($this->isCurrentLineBlank()) 164 164 { 165 165 $data[] = substr($this->currentLine, $newIndent); … … 227 227 protected function parseValue($value) 228 228 { 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); 245 238 } 246 239 } … … 249 242 * Parses a folded scalar. 250 243 * 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 ''; 263 274 } 264 275 265 276 $textIndent = $matches['indent']; 266 267 $text = $matches['text'].$separator; 277 $previousIndent = 0; 278 279 $text .= $matches['text'].$separator; 268 280 while ($this->currentLineNb + 1 < count($this->lines)) 269 281 { 270 282 $this->moveToNextLine(); 271 283 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); 275 293 } 276 294 else if (preg_match('#^(?P<text> *)$#', $this->currentLine, $matches)) … … 317 335 $notEOF = $this->moveToNextLine(); 318 336 319 while ($ this->isCurrentLineEmpty() && $notEOF)337 while ($notEOF && $this->isCurrentLineEmpty()) 320 338 { 321 339 $notEOF = $this->moveToNextLine(); … … 339 357 340 358 /** 341 * Returns true if the current line is emptyor if it is a comment line.359 * Returns true if the current line is blank or if it is a comment line. 342 360 * 343 361 * @return Boolean Returns true if the current line is empty or if it is a comment line, false otherwise … … 345 363 protected function isCurrentLineEmpty() 346 364 { 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, ' '); 348 376 } 349 377 branches/1.1/test/unit/util/fixtures/yaml/YtsSpecificationExamples.yml
r7892 r7923 129 129 --- 130 130 test: Sequence of sequences 131 todo: true132 131 spec: 2.5 133 132 yaml: | … … 135 134 - [ Mark McGwire , 65 , 0.278 ] 136 135 - [ 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 136 php: | 137 array( 138 array( 'name', 'hr', 'avg' ), 139 array( 'Mark McGwire', 65, 0.278 ), 140 array( 'Sammy Sosa', 63, 0.288 ) 141 ) 185 142 --- 186 143 test: Mapping of mappings … … 193 150 avg: 0.288 194 151 } 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 { 152 ruby: | 153 array( 209 154 'Mark McGwire' => 210 { 'hr' => 65, 'avg' => 0.278 },155 array( 'hr' => 65, 'avg' => 0.278 ), 211 156 '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 --- 160 test: Two documents in a stream each with a leading comment 244 161 todo: true 245 162 spec: 2.7 … … 255 172 - Chicago Cubs 256 173 - 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 ]265 174 ruby: | 266 175 y = YAML::Stream.new 267 176 y.add( [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] ) 268 177 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_node275 };276 struct test_node seq2[] = {277 { T_STR, 0, "Chicago Cubs" },278 { T_STR, 0, "St Louis Cardinals" },279 end_node280 };281 struct test_node stream[] = {282 { T_SEQ, 0, 0, seq1 },283 { T_SEQ, 0, 0, seq2 },284 end_node285 };286 178 documents: 2 287 179 … … 303 195 perl: | 304 196 [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] 305 python: |306 [[ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ]]307 ruby: |308 y = YAML::Stream.new309 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_node320 };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_node329 };330 struct test_node stream[] = {331 { T_MAP, 0, 0, map1 },332 { T_MAP, 0, 0, map2 },333 end_node334 };335 197 documents: 2 336 198 337 199 --- 338 200 test: Single document with two comments 339 todo: true340 201 spec: 2.9 341 202 yaml: | … … 347 208 - Sammy Sosa 348 209 - 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 210 php: | 211 array( 212 'hr' => array( 'Mark McGwire', 'Sammy Sosa' ), 213 'rbi' => array( 'Sammy Sosa', 'Ken Griffey' ) 214 ) 387 215 --- 388 216 test: Node for Sammy Sosa appears twice in this document … … 654 482 65 Home Runs 655 483 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 484 php: | 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 ) 691 490 --- 692 491 test: Quoted scalars 492 todo: true 693 493 spec: 2.17 694 494 yaml: | … … 700 500 quoted: ' # not a ''comment''.' 701 501 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 }711 502 ruby: | 712 503 { … … 718 509 "hexesc"=>"\r\n is \r\n" 719 510 } 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 731 511 --- 732 512 test: Multiline flow scalars 513 todo: true 733 514 spec: 2.18 734 515 yaml: | … … 739 520 quoted: "So does this 740 521 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 }746 522 ruby: | 747 523 { … … 749 525 'quoted' => "So does this quoted scalar.\n" 750 526 } 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_node764 };765 struct test_node stream[] = {766 { T_MAP, 0, 0, map },767 end_node768 };769 770 527 --- 771 528 test: Integers … … 774 531 canonical: 12345 775 532 decimal: +12,345 776 sexagecimal: 3:25:45777 533 octal: 014 778 534 hexadecimal: 0xC 779 perl: | 780 { 781 canonical => 12345, 782 decimal => 12345, 783 octal => oct("014"), 784 hexadecimal => hex("0xC"), 785 } 786 ruby: | 787 { 535 php: | 536 array( 788 537 'canonical' => 12345, 789 538 '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 ) 820 542 --- 821 543 # FIX: spec shows parens around -inf and NaN … … 825 547 canonical: 1.23015e+3 826 548 exponential: 12.3015e+02 827 sexagecimal: 20:30.15828 549 fixed: 1,230.15 829 550 negative infinity: -.inf 830 551 not a number: .NaN 831 p erl: |832 {552 php: | 553 array( 833 554 'canonical' => 1230.15, 834 555 'exponential' => 1230.15, 835 556 '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 ) 880 560 --- 881 561 test: Miscellaneous … … 886 566 false: n 887 567 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, 568 php: | 569 array( 570 '' => null, 571 1 => true, 572 0 => false, 900 573 '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 ) 926 575 --- 927 576 test: Timestamps 577 todo: true 928 578 spec: 2.22 929 579 yaml: | … … 932 582 spaced: 2001-12-14 21:59:43.10 -05:00 933 583 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 { 584 php: | 585 array( 943 586 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ), 944 587 'iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 945 588 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 946 589 '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 ) 965 591 --- 966 592 test: legacy Timestamps test 593 todo: true 967 594 spec: legacy D4 968 595 yaml: | … … 971 598 spaced: 2001-12-14 21:59:43.00 -05:00 972 599 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 { 600 php: | 601 array( 982 602 'canonical' => Time::utc( 2001, 12, 15, 2, 59, 43, 0 ), 983 603 'iso8601' => YAML::mktime( 2001, 2, 28, 21, 59, 43, 0, "-05:00" ), 984 604 'spaced' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0, "-05:00" ), 985 605 '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 ) 1004 607 --- 1005 608 test: Various explicit families 609 todo: true 1006 610 spec: 2.23 1007 611 yaml: | … … 1028 632 'application specific tag' => "SOMETHING: The semantics of the tag\nabove may be different for\ndifferent documents.\n" 1029 633 } 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_node1039 };1040 struct test_node stream[] = {1041 { T_MAP, 0, 0, map },1042 end_node1043 };1044 1045 634 --- 1046 635 test: Application specific family 636 todo: true 1047 637 spec: 2.24 1048 638 yaml: | … … 1116 706 "Shape Container" 1117 707 ] 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_node1125 };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_node1132 };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_node1139 };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_node1146 };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_node1155 };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_node1161 };1162 struct test_node stream[] = {1163 { T_SEQ, "tag:clarkevans.com,2002:graph/shape", 0, seq },1164 end_node1165 };1166 1167 708 # --- 1168 709 # test: Unordered set … … 1178 719 --- 1179 720 test: Ordered mappings 721 todo: true 1180 722 spec: 2.26 1181 723 yaml: | … … 1193 735 'Ken Griffy', 58 1194 736 ] 1195 syck: |1196 struct test_node map1[] = {1197 { T_STR, 0, "Mark McGwire" },1198 { T_STR, 0, "65" },1199 end_node1200 };1201 struct test_node map2[] = {1202 { T_STR, 0, "Sammy Sosa" },1203 { T_STR, 0, "63" },1204 end_node1205 };1206 struct test_node map3[] = {1207 { T_STR, 0, "Ken Griffy" },1208 { T_STR, 0, "58" },1209 end_node1210 };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_node1216 };1217 struct test_node stream[] = {1218 { T_SEQ, "tag:yaml.org,2002:omap", 0, seq },1219 end_node1220 };1221 1222 737 --- 1223 738 test: Invoice 739 todo: true 1224 740 spec: 2.27 1225 741 yaml: | … … 1268 784 'tax' => 251.42, 'total' => 4443.52, 1269 785 '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_node1281 };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_node1292 };1293 struct test_node products[] = {1294 { T_MAP, 0, 0, prod1 },1295 { T_MAP, 0, 0, prod2 },1296 end_node1297 };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_node1308 };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_node1317 };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_node1336 };1337 struct test_node stream[] = {1338 { T_MAP, "tag:clarkevans.com,2002:invoice", 0, map },1339 end_node1340 };1341 1342 786 --- 1343 787 test: Log file 788 todo: true 1344 789 spec: 2.28 1345 790 yaml: | … … 1381 826 { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" }, 1382 827 { '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_node1392 };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_node1401 };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_node1410 };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_node1419 };1420 struct test_node stack[] = {1421 { T_MAP, 0, 0, file1 },1422 { T_MAP, 0, 0, file2 },1423 end_node1424 };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_node1435 };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_node1441 };1442 828 documents: 3 1443 829 … … 1455 841 # These are three throwaway comment 1456 842 # lines (the first line is empty). 1457 ruby: |1458 {843 php: | 844 array( 1459 845 '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 ) 1472 847 --- 1473 848 test: Document with a single value 849 todo: true 1474 850 yaml: | 1475 851 --- > … … 1480 856 ruby: | 1481 857 "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_node1486 };1487 1488 858 --- 1489 859 test: Document stream 860 todo: true 1490 861 yaml: | 1491 862 --- … … 1513 884 'url' => '/toc.html' 1514 885 } ) 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_node1526 };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_node1537 };1538 struct test_node stream[] = {1539 { T_MAP, 0, 0, map1 },1540 { T_MAP, 0, 0, map2 },1541 end_node1542 };1543 886 documents: 2 1544 887 … … 1550 893 date : 2001-01-23 1551 894 total : 4443.52 1552 ruby: |1553 {1554 'invoice' => 34843, 1555 'date' => Date.new( 2001, 1, 23),895 php: | 896 array( 897 'invoice' => 34843, 898 'date' => mktime(0, 0, 0, 1, 23, 2001), 1556 899 '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 ) 1573 901 --- 1574 902 test: Single-line documents 903 todo: true 1575 904 yaml: | 1576 905 # The following is a sequence of three documents. … … 1585 914 y.add( [] ) 1586 915 y.add( '' ) 1587 syck: |1588 struct test_node map[] = {1589 end_node1590 };1591 struct test_node seq[] = {1592 end_node1593 };1594 struct test_node stream[] = {1595 { T_MAP, 0, 0, map },1596 { T_SEQ, 0, 0, seq },1597 { T_STR, 0, "" },1598 end_node1599 };1600 916 documents: 3 1601 917 1602 918 --- 1603 919 test: Document with pause 920 todo: true 1604 921 yaml: | 1605 922 # A communication channel based on a YAML stream. … … 1623 940 { "payload" => "Whatever", "sent at" => YAML::mktime( 2002, 6, 6, 12, 5, 53, 0.47 ) } 1624 941 ) 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_node1632 };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_node1639 };1640 struct test_node stream[] = {1641 { T_MAP, 0, 0, map1 },1642 { T_MAP, 0, 0, map2 },1643 end_node1644 };1645 942 documents: 2 1646 943 … … 1651 948 also int: ! "12" 1652 949 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 950 php: | 951 array( 'integer' => 12, 'also int' => 12, 'string' => '12' ) 1670 952 --- 1671 953 test: Private types 954 todo: true 1672 955 yaml: | 1673 956 # Both examples below make use of the 'x-private:ball' … … 1690 973 { 'material' => 'steel' } ) } 1691 974 ) 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_node1699 };1700 struct test_node map1[] = {1701 { T_STR, 0, "pool" },1702 { T_MAP, "x-private:ball", 0, pool },1703 end_node1704 };1705 struct test_node bearing[] = {1706 { T_STR, 0, "material" },1707 { T_STR, 0, "steel" },1708 end_node1709 };1710 struct test_node map2[] = {1711 { T_STR, 0, "bearing" },1712 { T_MAP, "x-private:ball", 0, bearing },1713 end_node1714 };1715 struct test_node stream[] = {1716 { T_MAP, 0, 0, map1 },1717 { T_MAP, 0, 0, map2 },1718 end_node1719 };1720 975 documents: 2 1721 976 … … 1725 980 # The URI is 'tag:yaml.org,2002:str' 1726 981 - !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 982 php: | 983 array( 'a Unicode string' ) 1741 984 --- 1742 985 test: Type family under perl.yaml.org 986 todo: true 1743 987 yaml: | 1744 988 # The URI is 'tag:perl.yaml.org,2002:Text::Tabs' … … 1746 990 ruby: | 1747 991 [ YAML::DomainType.new( 'perl.yaml.org,2002', 'Text::Tabs', {} ) ] 1748 syck: |1749 struct test_node map[] = {1750 end_node1751 };1752 struct test_node seq[] = {1753 { T_MAP, "tag:perl.yaml.org,2002:Text::Tabs", 0, map },1754 end_node1755 };1756 struct test_node stream[] = {1757 { T_SEQ, 0, 0, seq },1758 end_node1759 };1760 1761 992 --- 1762 993 test: Type family under clarkevans.com 994 todo: true 1763 995 yaml: | 1764 996 # The URI is 'tag:clarkevans.com,2003-02:timesheet' … … 1766 998 ruby: | 1767 999 [ YAML::DomainType.new( 'clarkevans.com,2003-02', 'timesheet', {} ) ] 1768 syck: |1769 struct test_node map[] = {1770 end_node1771 };1772 struct test_node seq[] = {1773 { T_MAP, "tag:clarkevans.com,2003-02:timesheet", 0, map },1774 end_node1775 };1776 struct test_node stream[] = {1777 { T_SEQ, 0, 0, seq },1778 end_node1779 };1780 1781 1000 --- 1782 1001 test: URI Escaping 1002 todo: true 1783 1003 yaml: | 1784 1004 same: … … 1797 1017 ruby: | 1798 1018 { '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_node1804 };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_node1809 };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_node1816 };1817 struct test_node stream[] = {1818 { T_MAP, 0, 0, map },1819 end_node1820 };1821 1822 1019 --- 1823 1020 test: URI Prefixing 1021 todo: true 1824 1022 yaml: | 1825 1023 # 'tag:domain.tld,2002:invoice' is some type family. … … 1849 1047 --- 1850 1048 test: Overriding anchors 1049 todo: true 1851 1050 yaml: | 1852 1051 anchor : &A001 This scalar has an anchor. … … 1876 1075 --- 1877 1076 test: Flow and block formatting 1077 todo: true 1878 1078 yaml: | 1879 1079 empty: [] … … 1892 1092 'block' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ], 1893 1093 "A folded sequence entry\n", 'Sixth item in top sequence' ] } 1894 syck: |1895 struct test_node empty[] = {1896 end_node1897 };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_node1905 };1906 struct test_node inblock[] = {1907 { T_STR, 0, "Subordinate sequence entry" },1908 end_node1909 };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_node1916 };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_node1925 };1926 struct test_node stream[] = {1927 { T_MAP, 0, 0, map },1928 end_node1929 };1930 1931 1094 --- 1932 1095 test: Complete mapping test 1096 todo: true 1933 1097 yaml: | 1934 1098 empty: {} … … 1996 1160 end 1997 1161 } 1998 1999 1162 --- 2000 1163 test: Literal explicit indentation … … 2019 1182 redundant: |2 2020 1183 This value is indented 2 spaces. 2021 ruby: |2022 {1184 php: | 1185 array( 2023 1186 'leading spaces' => " This value starts with four spaces.\n", 2024 1187 'leading line break' => "\nThis value starts with a line break.\n", 2025 1188 'leading comment indicator' => "# first line starts with a\n# character.\n", 2026 1189 'redundant' => "This value is indented 2 spaces.\n" 2027 } 2028 1190 ) 2029 1191 --- 2030 1192 test: Chomping and keep modifiers … … 2044 1206 2045 1207 same as "kept" above: "This has two newlines.\n\n" 2046 ruby: |2047 {1208 php: | 1209 array( 2048 1210 'clipped' => "This has one newline.\n", 2049 1211 'same as "clipped" above' => "This has one newline.\n", … … 2052 1214 'kept' => "This has two newlines.\n\n", 2053 1215 'same as "kept" above' => "This has two newlines.\n\n" 2054 } 2055 1216 ) 2056 1217 --- 2057 1218 test: Literal combinations 1219 todo: true 2058 1220 yaml: | 2059 1221 empty: | … … 2089 1251 2090 1252 both are equal to: " This has no newline." 2091 ruby: |2092 {1253 php: | 1254 array( 2093 1255 'empty' => '', 2094 1256 'literal' => "The \\ ' \" characters may be\nfreely used. Leading white\n space " + … … 2101 1263 'also written as' => ' This has no newline.', 2102 1264 'both are equal to' => ' This has no newline.' 2103 } 2104 1265 ) 2105 1266 --- 2106 1267 test: Folded combinations 1268 todo: true 2107 1269 yaml: | 2108 1270 empty: > … … 2156 1318 # Explicit comments may follow 2157 1319 # but must be less indented. 2158 ruby: |2159 {1320 php: | 1321 array( 2160 1322 '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'. 2162 1324 " 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". 2164 1326 "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, ". 2167 1329 "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, ". 2170 1332 "another list:\n\n * first entry\n\n * second entry\n\nAnd a final folded paragraph.\n" 2171 } 2172 1333 ) 2173 1334 --- 2174 1335 test: Single quotes 1336 todo: true 2175 1337 yaml: | 2176 1338 empty: '' … … 2183 1345 line break' 2184 1346 is same as: "this contains six spaces\nand one line break" 2185 ruby: |2186 {1347 php: | 1348 array( 2187 1349 'empty' => '', 2188 1350 'second' => '! : \\ etc. can be used freely.', … … 2190 1352 'span' => "this contains six spaces\nand one line break", 2191 1353 'is same as' => "this contains six spaces\nand one line break" 2192 } 2193 1354 ) 2194 1355 --- 2195 1356 test: Double quotes 1357 todo: true 2196 1358 yaml: | 2197 1359 empty: "" … … 2203 1365 spaces" 2204 1366 is equal to: "this contains four spaces" 2205 ruby: |2206 {1367 php: | 1368 array( 2207 1369 'empty' => '', 2208 1370 'second' => '! : etc. can be used freely.', … … 2211 1373 'span' => "this contains four spaces", 2212 1374 'is equal to' => "this contains four spaces" 2213 } 2214 1375 ) 2215 1376 --- 2216 1377 test: Unquoted strings 1378 todo: true 2217 1379 yaml: | 2218 1380 first: There is no unquoted empty string. … … 2239 1401 note: { one-line keys: but multi-line values } 2240 1402 2241 ruby: |2242 {1403 php: | 1404 array( 2243 1405 'first' => 'There is no unquoted empty string.', 2244 1406 'second' => 12, … … 2248 1410 'flow' => [ 'can span lines', 'like this' ], 2249 1411 'note' => { 'one-line keys' => 'but multi-line values' } 2250 } 2251 1412 ) 2252 1413 --- 2253 1414 test: Spanning sequences 1415 todo: true 2254 1416 yaml: | 2255 1417 # The following are equal seqs … … 2261 1423 - one 2262 1424 - two 2263 ruby: |2264 {1425 php: | 1426 array( 2265 1427 'flow' => [ 'one', 'two' ], 2266 1428 'spanning' => [ 'one', 'two' ], 2267 1429 'block' => [ 'one', 'two' ] 2268 } 2269 1430 ) 2270 1431 --- 2271 1432 test: Flow mappings … … 2277 1438 one: 1 2278 1439 two: 2 2279 ruby: | 2280 { 2281 'flow' => { 'one' => 1, 'two' => 2 }, 2282 'block' => { 'one' => 1, 'two' => 2 } 2283 } 2284 1440 php: | 1441 array( 1442 'flow' => array( 'one' => 1, 'two' => 2 ), 1443 'block' => array( 'one' => 1, 'two' => 2 ) 1444 ) 2285 1445 --- 2286 1446 test: Representations of 12 1447 todo: true 2287 1448 yaml: | 2288 1449 - 12 # An integer … … 2302 1463 - foo/bar 2303 1464 - /a.*b/ 2304 ruby: | 2305 [ 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' ] 2306 1465 php: | 1466 array( 12, '12', '12', '12', '12', '/foo/bar', 'd:/foo/bar', 'foo/bar', '/a.*b/' ) 2307 1467 --- 2308 1468 test: "Null" 1469 todo: true 2309 1470 yaml: | 2310 1471 canonical: ~ … … 2324 1485 only two with values. 2325 1486 2326 ruby: |2327 {2328 'canonical' => n il,2329 'english' => n il,2330 'sparse' => [ nil, '2nd entry', nil, '4th entry', nil ],1487 php: | 1488 array ( 1489 'canonical' => null, 1490 'english' => null, 1491 'sparse' => array( null, '2nd entry', null, '4th entry', null ]), 2331 1492 'four' => 'This mapping has five keys, only two with values.' 2332 } 2333 1493 ) 2334 1494 --- 2335 1495 test: Omap 1496 todo: true 2336 1497 yaml: | 2337 1498 # Explicitly typed dictionary. … … 2352 1513 --- 2353 1514 test: Pairs 1515 todo: true 2354 1516 yaml: | 2355 1517 # Explicitly typed pairs. … … 2371 1533 --- 2372 1534 test: Set 1535 todo: true 2373 1536 yaml: | 2374 1537 # Explicitly typed set. … … 2392 1555 logical: true 2393 1556 answer: no 2394 ruby: |2395 {1557 php: | 1558 array( 2396 1559 false => 'used as key', 2397 1560 'logical' => true, 2398 1561 'answer' => false 2399 } 2400 1562 ) 2401 1563 --- 2402 1564 test: Integer … … 2406 1568 octal: 014 2407 1569 hexadecimal: 0xC 2408 ruby: |2409 {1570 php: | 1571 array( 2410 1572 'canonical' => 12345, 2411 1573 'decimal' => 12345, 2412 1574 'octal' => 12, 2413 1575 'hexadecimal' => 12 2414 } 2415 1576 ) 2416 1577 --- 2417 1578 test: Float … … 2422 1583 negative infinity: -.inf 2423 1584 not a number: .NaN 2424 ruby: |2425 {1585 php: | 1586 array( 2426 1587 'canonical' => 1230.15, 2427 1588 'exponential' => 1230.15, 2428 1589 '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 ) 2436 1593 --- 2437 1594 test: Timestamp 1595 todo: true 2438 1596 yaml: | 2439 1597 canonical: 2001-12-15T02:59:43.1Z … … 2442 1600 date (noon UTC): 2002-12-14 2443 1601 ruby: | 2444 {1602 array( 2445 1603 'canonical' => YAML::mktime( 2001, 12, 15, 2, 59, 43, 0.10 ), 2446 1604 'valid iso8601' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 2447 1605 'space separated' => YAML::mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ), 2448 1606 '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 ) 2468 1608 --- 2469 1609 test: Binary 1610 todo: true 2470 1611 yaml: | 2471 1612 canonical: !binary "\ … … 2493 1634 --- 2494 1635 test: Merge key 1636 todo: true 2495 1637 yaml: | 2496 1638 --- … … 2545 1687 --- 2546 1688 test: Default key 1689 todo: true 2547 1690 yaml: | 2548 1691 --- # Old schema … … 2568 1711 --- 2569 1712 test: Special keys 1713 todo: true 2570 1714 yaml: | 2571 1715 "!": These three keys branches/1.1/test/unit/util/fixtures/yaml/YtsTypeTransfers.yml
r7892 r7923 167 167 --- 168 168 test: Integers 169 dump_skip: true 169 170 brief: > 170 171 An integer is a series of numbers, optionally … … 199 200 --- 200 201 test: Floats 202 dump_skip: true 201 203 brief: > 202 204 Floats are represented by numbers with decimals, branches/1.1/test/unit/util/fixtures/yaml/index.yml
r7892 r7923 9 9 - YtsFoldedScalars 10 10 - YtsNullsAndEmpties 11 #- YtsSpecificationExamples11 - YtsSpecificationExamples 12 12 - YtsTypeTransfers branches/1.1/test/unit/util/sfYamlDumperTest.php
r7919 r7923 13 13 require_once(dirname(__FILE__).'/../../../lib/util/sfYamlDumper.class.php'); 14 14 15 $t = new lime_test( 69, new lime_output_color());15 $t = new lime_test(134, new lime_output_color()); 16 16 17 17 $parser = new sfYamlParser(); … … 35 35 36 36 $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']) 38 42 { 39 43 $t->todo($test['test']); … … 43 47 $expected = eval('return '.trim($test['php']).';'); 44 48 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']); 46 50 } 47 51 } branches/1.1/test/unit/util/sfYamlParserTest.php
r7919 r7923 12 12 require_once(dirname(__FILE__).'/../../../lib/util/sfYamlParser.class.php'); 13 13 14 $t = new lime_test( 66, new lime_output_color());14 $t = new lime_test(133, new lime_output_color()); 15 15 16 16 $parser = new sfYamlParser(); … … 41 41 $expected = var_export(eval('return '.trim($test['php']).';'), true); 42 42 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']); 44 44 } 45 45 }

