# vim:sw=4:ts=4 # $Id: basic.rb 230 2005-09-22 03:50:44Z why $ # require 'runit/testcase' require 'runit/cui/testrunner' require 'yaml' # [ruby-core:01946] module YAML_Tests StructTest = Struct::new( :c ) end class YAML_Unit_Tests < RUNIT::TestCase # # Convert between YAML and the object to verify correct parsing and # emitting # def assert_to_yaml( obj, yaml ) assert_equal( obj, YAML::load( yaml ) ) assert_equal( obj, YAML::parse( yaml ).transform ) assert_equal( obj, YAML::load( obj.to_yaml ) ) assert_equal( obj, YAML::parse( obj.to_yaml ).transform ) assert_equal( obj, YAML::load( obj.to_yaml( :UseVersion => true, :UseHeader => true, :SortKeys => true ) ) ) # yb = YAML::Parser.new # yb.resolver = YAML.resolver # yb.input = :bytecode # assert_equal( obj, yb.load( YAML::Syck::compile( yaml ) ) ) end # # Test bytecode parser # def assert_bytecode( obj, yaml ) yp = YAML::Parser.new yp.input = :bytecode assert_equal( obj, yp.load( yaml ) ) end # # Test parser only # def assert_parse_only( obj, yaml ) assert_equal( obj, YAML::load( yaml ) ) assert_equal( obj, YAML::parse( yaml ).transform ) yp = YAML::Parser.new yp.input = :bytecode assert_equal( obj, yp.load( YAML::Syck::compile( yaml ) ) ) end def assert_path_segments( path, segments ) YAML::YPath.each_path( path ) { |choice| assert_equal( choice.segments, segments.shift ) } assert_equal( segments.length, 0, "Some segments leftover: #{ segments.inspect }" ) end # # Make a time with the time zone # def mktime( year, mon, day, hour, min, sec, usec, zone = "Z" ) usec = usec.to_s.to_f * 1000000 val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec ) if zone != "Z" hour = zone[0,3].to_i * 3600 min = zone[3,2].to_i * 60 ofs = (hour + min) val = Time.at( val.to_f - ofs ) end return val end # # Tests modified from 00basic.t in YAML.pm # def test_basic_map # Simple map map = { 'one' => 'foo', 'three' => 'baz', 'two' => 'bar' } assert_to_yaml( map, < 'simple string', 2 => 42, 3 => '1 Single Quoted String', 4 => 'YAML\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n", 6 => "A \"chomped\" block", 7 => "A folded\n string\n" } assert_to_yaml( basic, < A folded string EOY ) assert_bytecode( basic, "D\nM\nS1\nSsimple string\nS2\nS42\nS3\nS1 Single Quoted String\nS4\nSYAML's Double \"Quoted\" String\n" + "S5\nSA block\nN\nC with several\nN\nC lines.\nN\nS6\nSA \"chomped\" block\nS7\nSA folded\nN\nC string\nN\nE\n" ) end # # Test the specification examples # - Many examples have been changes because of whitespace problems that # caused the two to be inequivalent, or keys to be sorted wrong # def test_spec_simple_implicit_sequence # Simple implicit sequence seq = [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ] assert_to_yaml( seq, < 65, 'avg' => 0.278, 'rbi' => 147 } assert_to_yaml( map, < [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ], 'national' => [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] } assert_to_yaml( nest, < 'Mark McGwire', 'hr' => 65, 'avg' => 0.278}, {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288} ] assert_to_yaml( nest, < { 'hr' => 65, 'avg' => 0.278 }, 'Sammy Sosa' => { 'hr' => 63, 'avg' => 0.288 } } assert_to_yaml( map, < [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } assert_to_yaml( nest, < [ 'Mark McGwire', 'Sammy Sosa' ], 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] } assert_to_yaml( anc1, <"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}] assert_to_yaml( anc2, <["fareref", "currency", "departure", "arrival"], "FARES"=>[{"arrival"=>"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}]} assert_to_yaml( anc3, < [ Date.new( 2001, 7, 23 ) ], [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ] } assert_to_yaml( complex, < [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ], [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ] }, < 34843, 'date' => Date.new( 2001, 1, 23 ), 'bill-to' => 'Chris Dumars', 'product' => [ { 'item' => 'Super Hoop', 'quantity' => 1 }, { 'item' => 'Basketball', 'quantity' => 4 }, { 'item' => 'Big Shoes', 'quantity' => 1 } ] } assert_to_yaml( seq, < nil }, [ { 'five' => [ 'six' ] } ], [ 'seven' ] ], [ 'eight', 'nine' ] ] assert_to_yaml( seq, < Mark McGwire's year was crippled by a knee injury. EOY # Force a few elaborate folded blocks assert_to_yaml( [ < ruby -ropen-uri -e 'eval(open("http://go.hobix.com/").read)' STR1 Ok, so the idea here is that one whole weblahhg is contained in a single directory. What is stored in the directory?
  hobix.yaml <- configuration

  entries/   <- edit and organize
                your news items,
                articles and so on.

  skel/      <- contains your
                templates

  htdocs/    <- html is created here,
                store all your images here,
                this is your viewable
                websyht

  lib/       <- extra hobix libraries
                (plugins) go here
One weblahhg can be shared with many authors. In the @hobix.yaml@ file, you can store information about each author, as well as information about others who contribute to your websyht. You also have a file of your own, a configuration file called @.hobixrc@, which contains a list of the weblahhgs you belong to. h2. Pull One From the Sky If you would like to create your own weblahhg from scratch:
  hobix create blahhg
You will be prompted for a full path where the new weblahhg can be created. Don't worry if the directory doesn't yet exist, Hobix will take care of clearing a path for it. Once you give it the path, Hobix will create all the necessary directories, as well as the @hobix.yaml@. You should also have a set of sample templates to get you started. In fact, if you want to generate the default site:
  hobix regen blahhg
h2. Joining Hands With Others To join an existing weblahhg:
  hobix add other-blahhg /path/to/other-blahhg/hobix.yaml
You don't need to be on a weblahhg's author list to join the weblahhg. You just need permissions to edit the file. h2. Leaving in a Cloud of Keystrokes To remove a weblahhg from your configuration:
  hobix del other-blahhg
Please don't be afraid to edit your configuration file yourself, should the commandline not suit your style. See, here's my @.hobixrc@:
  --- 
  weblogs: 
    hobix: /usr/local/www/hobix.com/www/hobix.yaml
    why: /usr/local/www/whytheluckystiff.net/www/hobix.yaml
  username: why
  use editor: true
That's a YAML file. Very simple to edit. You can manually edit your information, safely add or edit your weblogs, and save back to your @.hobixrc@. Enough then. Time to trick out your new Hoblahhg. You will be guided through an automatic installation (or upgrade) of Hobix. STR2 NOW BUNKING together: the ruby and yaml scripts up at http://go.hobix.com/. Hey ,, the life and unity we feel is tree-mending-US!! Try:
  ruby -ropen-uri -e'eval open("http://go.hobix.com/").read'
No longer are curtains dropping ON the actors' arms !! No longer are swift currents ON the actors' legs !! The actors have a bottomless cereal container, witness. STR3 --- - |+ Here's what you're going to need: * Ruby 1.8.0 or higher. ** Linux/FreeBSD: "Get the latest, please.":http://ruby-lang.org/en/20020102.html ** Windows: "Installer for Windows.":http://rubyinstaller.sourceforge.net/ ** Mac: "OSX disk image.":http://homepage.mac.com/discord/Ruby/ * Once Ruby is installed, open a command prompt and type:
    ruby -ropen-uri -e 'eval(open("http://go.hobix.com/").read)'
  
- | Ok, so the idea here is that one whole weblahhg is contained in a single directory. What is stored in the directory?
    hobix.yaml <- configuration

    entries/   <- edit and organize
                  your news items,
                  articles and so on.

    skel/      <- contains your
                  templates

    htdocs/    <- html is created here,
                  store all your images here,
                  this is your viewable
                  websyht

    lib/       <- extra hobix libraries
                  (plugins) go here
  
One weblahhg can be shared with many authors. In the @hobix.yaml@ file, you can store information about each author, as well as information about others who contribute to your websyht. You also have a file of your own, a configuration file called @.hobixrc@, which contains a list of the weblahhgs you belong to. h2. Pull One From the Sky If you would like to create your own weblahhg from scratch:
    hobix create blahhg
  
You will be prompted for a full path where the new weblahhg can be created. Don't worry if the directory doesn't yet exist, Hobix will take care of clearing a path for it. Once you give it the path, Hobix will create all the necessary directories, as well as the @hobix.yaml@. You should also have a set of sample templates to get you started. In fact, if you want to generate the default site:
    hobix regen blahhg
  
h2. Joining Hands With Others To join an existing weblahhg:
    hobix add other-blahhg /path/to/other-blahhg/hobix.yaml
  
You don't need to be on a weblahhg's author list to join the weblahhg. You just need permissions to edit the file. h2. Leaving in a Cloud of Keystrokes To remove a weblahhg from your configuration:
    hobix del other-blahhg
  
Please don't be afraid to edit your configuration file yourself, should the commandline not suit your style. See, here's my @.hobixrc@:
    --- 
    weblogs: 
      hobix: /usr/local/www/hobix.com/www/hobix.yaml
      why: /usr/local/www/whytheluckystiff.net/www/hobix.yaml
    username: why
    use editor: true
  
That's a YAML file. Very simple to edit. You can manually edit your information, safely add or edit your weblogs, and save back to your @.hobixrc@. Enough then. Time to trick out your new Hoblahhg. You will be guided through an automatic installation (or upgrade) of Hobix. - | NOW BUNKING together: the ruby and yaml scripts up at http://go.hobix.com/. Hey ,, the life and unity we feel is tree-mending-US!! Try:
    ruby -ropen-uri -e'eval open("http://go.hobix.com/").read'
  
No longer are curtains dropping ON the actors' arms !! No longer are swift currents ON the actors' legs !! The actors have a bottomless cereal container, witness. EOY assert_bytecode( fold, "D\nQ\nSMark McGwire's year was crippled by a knee injury.\nN\nE\n" ) end def test_spec_preserve_indent # Preserve indented spaces fold = "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" assert_to_yaml( fold, < Sammy Sosa completed another fine season with great stats. 63 Home Runs 0.288 Batting Average What a year! EOY assert_bytecode( fold, "D\nSSammy Sosa completed another fine season with great stats.\nN\nN\nC 63 Home Runs\nN\nC 0.288 Batting Average\nN\nN\nCWhat a year!\nN\n" ) end def test_spec_indentation_determines_scope map = { 'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n", 'stats' => "65 Home Runs\n0.278 Batting Average\n" } assert_to_yaml( map, < Mark set a major league home run record in 1998. stats: | 65 Home Runs 0.278 Batting Average EOY assert_bytecode( map, "D\nM\nSname\nSMark McGwire\nSaccomplishment\nSMark set a major league home run record in 1998.\nN\nSstats\nS65 Home Runs\nN\nC0.278 Batting Average\nN\nE\n" ) end # def test_spec_quoted_scalars # assert_to_yaml( # {"tie-fighter"=>"|\\-*-/|", "control"=>"\0101998\t1999\t2000\n", "unicode"=>"Sosa did fine." + ["263A".hex].pack('U*'), "quoted"=>" # not a 'comment'.", "single"=>"\"Howdy!\" he cried.", "hexesc"=>"\r\n is \r\n"}, < 'This unquoted scalar spans many lines.', 'quoted' => "So does this quoted scalar.\n" } assert_to_yaml( map, < 12345, 'decimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex } assert_to_yaml( map, < 685230, 'decimal' => 685230, 'octal' => '02472256'.oct, 'hexadecimal' => '0x0A74AE'.hex, 'sexagesimal' => 685230 } assert_to_yaml( map, < 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15, 'sexagecimal' => 1230.15, 'negative infinity' => -1.0/0.0 } assert_to_yaml( map, < nil, true => true, false => false, 'string' => '12345' } assert_to_yaml( map, < 'Chris', 'family' => 'Dumars', 'address' => { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', 'state' => 'MI', 'postal' => 48046 } } invoice = { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'bill-to' => id001, 'ship-to' => id001, 'product' => [ { 'sku' => 'BL394D', 'quantity' => 4, 'description' => 'Basketball', 'price' => 450.00 }, { 'sku' => 'BL4438H', 'quantity' => 1, 'description' => 'Super Hoop', 'price' => 2392.00 } ], 'tax' => 251.42, 'total' => 4443.52, 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" } assert_to_yaml( invoice, < Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. EOY assert_bytecode( invoice, "D\nM\nSinvoice\nS34843\nSdate\nS2001-01-23\nSbill-to\nAid001\n" + "M\nSgiven\nSChris\nSfamily\nT!str\nSDumars\nSaddress\n" + "M\nSlines\nS458 Walkman Dr.\nN\nCSuite #292\nN\nScity\nSRoyal Oak\nSstate\nSMI\nSpostal\nS48046\nE\nE\n" + "Sship-to\nRid001\nSproduct\nQ\n" + "T!map\nM\nSsku\nSBL394D\nSquantity\nS4\nSdescription\nSBasketball\nSprice\nS450.00\nE\n" + "M\nSsku\nSBL4438H\nSquantity\nS1\nSdescription\nSSuper Hoop\nSprice\nS2392.00\nE\nE\n" + "Stax\nS251.42\nStotal\nS4443.52\nScomments\n" + "SLate afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\nN\n" + "E\n" ) end def test_spec_log_file doc_ct = 0 doc1 = { 'Time' => mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ), 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } doc2 = { 'Time' => mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ), 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } doc3 = { 'Date' => mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ), 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n", 'Stack' => [ { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" }, { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } YAML::load_documents( < This is an error message for the log file --- Time: 2001-11-23 15:02:31 -05:00 User: ed Warning: > A slightly different error message. --- Date: 2001-11-23 15:03:17 -05:00 User: ed Fatal: > Unknown variable "bar" Stack: - file: TopClass.py line: 23 code: | x = MoreObject("345\\n") - file: MoreClass.py line: 58 code: |- foo = bar EOY ) { |doc| case doc_ct when 0 assert_equals( doc, doc1 ) when 1 assert_equals( doc, doc2 ) when 2 assert_equals( doc, doc3 ) end doc_ct += 1 } assert_equals( doc_ct, 3 ) doc_ct = 0 yp = YAML::Parser.new yp.input = :bytecode yp.load_documents( "D\nM\nSTime\nS2001-11-23 15:01:42 -05:00\nSUser\nSed\nSWarning\nSThis is an error message for the log file\nN\nE\n" + "D\nM\nSTime\nS2001-11-23 15:02:31 -05:00\nSUser\nSed\nSWarning\nSA slightly different error message.\nN\nE\n" + "D\nM\nSDate\nS2001-11-23 15:03:17 -05:00\nSUser\nSed\nSFatal\nSUnknown variable \"bar\"\nN\nSStack\n" + "Q\nM\nSfile\nSTopClass.py\nSline\nS23\nScode\nSx = MoreObject(\"345\\n\")\nN\nE\n" + "M\nSfile\nSMoreClass.py\nSline\nS58\nScode\nSfoo = bar\nE\nE\nE\n" ) { |doc| case doc_ct when 0 assert_equals( doc, doc1 ) when 1 assert_equals( doc, doc2 ) when 2 assert_equals( doc, doc3 ) end doc_ct += 1 } assert_equals( doc_ct, 3 ) end def test_spec_root_fold y = YAML::load( < 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. EOY ) assert_equals( y, "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" ) end def test_spec_root_mapping y = YAML::load( < 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } ) end # def test_spec_oneline_docs # doc_ct = 0 # YAML::load_documents( < { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } } assert_to_yaml( map, <"contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"} assert_to_yaml( map, < 12, 'also int' => 12, 'string' => '12' } assert_to_yaml( map, < 8, 'color' => 'black' } ) # when 1 # assert_equals( doc['bearing'].type_id, 'x-private:ball' ) # assert_equals( doc['bearing'].transform.value, { 'material' => 'steel' } ) # end # doc_ct += 1 # } # assert_equals( doc_ct, 2 ) # # doc_ct = 0 # YAML::Syck::Parser.new( :Input => :Bytecode, :Model => :Generic )::load_documents( # "D\nc Private types are per-document.\nM\nSpool\nT!!ball\n" + # "M\nSnumber\nS8\nScolor\nSblack\nE\nE\n" + # "D\nM\nSbearing\nT!!ball\nM\nSmaterial\nSsteel\nE\nE\n" # ) { |doc| # case doc_ct # when 0 # assert_equals( doc['pool'].type_id, 'x-private:ball' ) # assert_equals( doc['pool'].transform.value, { 'number' => 8, 'color' => 'black' } ) # when 1 # assert_equals( doc['bearing'].type_id, 'x-private:ball' ) # assert_equals( doc['bearing'].transform.value, { 'material' => 'steel' } ) # end # doc_ct += 1 # } # assert_equals( doc_ct, 2 ) # end def test_spec_url_escaping YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val| "ONE: #{val}" } YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val| "TWO: #{val}" } map = { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value' ] } assert_to_yaml( map, < 'This scalar has an anchor.', 'override' => a001, 'alias' => a001 } assert_to_yaml( anc, < The alias node below is a repeated use of this value. alias : *A001 EOY assert_bytecode( anc, "D\nM\nSanchor\nAA001\nSThis scalar has an anchor.\nSoverride\nAA001\n" + "SThe alias node below is a repeated use of this value.\nN\nSalias\nRA001\nE\n" ) end def test_spec_explicit_families YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val| "SOMEWHERE: #{val}" } map = { 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'hmm' => "SOMEWHERE: family above is short for\nhttp://somewhere.com/type\n" } assert_to_yaml( map, <7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]] assert_to_yaml( seq, < [], 'in-line' => [ 'one', 'two', 'three', 'four', 'five' ], 'nested' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ], "A multi-line sequence entry\n", 'Sixth item in top sequence' ] }, < A multi-line sequence entry - Sixth item in top sequence EOY ) end def test_spec_builtin_map # Assortment of mappings assert_to_yaml( { 'empty' => {}, 'in-line' => { 'one' => 1, 'two' => 2 }, 'spanning' => { 'one' => 1, 'two' => 2 }, 'nested' => { 'first' => 'First entry', 'second' => { 'key' => 'Subordinate mapping' }, 'third' => [ 'Subordinate sequence', {}, 'Previous mapping is empty.', { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' }, 'The previous entry is equal to the following one.', { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ], 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.', "\a" => 'This key had to be escaped.', "This is a multi-line folded key\n" => "Whose value is also multi-line.\n", [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }, < ? : This key had to be protected. "\\a" : This key had to be escaped. ? > This is a multi-line folded key : > Whose value is also multi-line. ? - This key - is a sequence : - With a sequence value. # The following parses correctly, # but Ruby 1.6.* fails the comparison! # ? # This: key # is a: mapping # : # with a: mapping value. EOY ) end def test_spec_builtin_literal_blocks # Assortment of literal scalar blocks assert_to_yaml( {"both are equal to"=>" This has no newline.", "is equal to"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n", "also written as"=>" This has no newline.", "indented and chomped"=>" This has no newline.", "empty"=>"", "literal"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n"}, < str1, 'same as "clipped" above' => str1, 'stripped' => str2, 'same as "stripped" above' => str2, 'kept' => str3, 'same as "kept" above' => str3 }, <"a single quote ' must be escaped.", "second"=>"! : \\ etc. can be used freely.", "is same as"=>"this contains six spaces\nand one line break", "empty"=>"", "span"=>"this contains six spaces\nand one line break"}, <"this contains four spaces", "third"=>"a \" or a \\ must be escaped.", "second"=>"! : etc. can be used freely.", "empty"=>"", "fourth"=>"this value ends with an LF.\n", "span"=>"this contains four spaces"}, < mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ), "canonical" => mktime( 2001, 12, 15, 2, 59, 43, ".10" ), "date (noon UTC)" => Date.new( 2002, 12, 14), "valid iso8601" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ) }, < arrow_gif, 'base64' => arrow_gif, 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n" }, < /George McFly/i }, < 2, :UseVersion => 0 ) y.add( { 'hi' => 'hello', 'map' => { 'good' => 'two' }, 'time' => Time.now, 'try' => /^po(.*)$/, 'bye' => 'goodbye' } ) y.add( { 'po' => 'nil', 'oper' => 90 } ) y.add( { 'hi' => 'wow!', 'bye' => 'wow!' } ) y.add( { [ 'Red Socks', 'Boston' ] => [ 'One', 'Two', 'Three' ] } ) y.add( [ true, false, false ] ) end # # Test YPath choices parsing # def test_ypath_parsing assert_path_segments( "/*/((one|three)/name|place)|//place", [ ["*", "one", "name"], ["*", "three", "name"], ["*", "place"], ["/", "place"] ] ) end # # Test of Ranges # def test_ranges # Simple numeric assert_to_yaml( 1..3, <"A,","B"=>"B"}, <2, "2"=>3}, <"b"}] * 2, <"b", "c"=>"d"} } # YAML::load( a.to_yaml ) end # # Test Time.now cycle # def test_time_now_cycle # # From Minero Aoki [ruby-core:2305] # require 'yaml' t = Time.now 5.times do assert_equals( t, YAML.load( YAML.dump( t ) ) ) end end # # # # Circular references # # # def test_circular_references # a = []; a[0] = a; a[1] = a # inspect_str = "[[...], [...]]" # assert_equals( inspect_str, YAML::load( a.to_yaml ).inspect ) # end end RUNIT::CUI::TestRunner.run( YAML_Unit_Tests.suite )