diff --git a/ext/psych/psych_emitter.c b/ext/psych/psych_emitter.c index e71bcb62..110eb031 100644 --- a/ext/psych/psych_emitter.c +++ b/ext/psych/psych_emitter.c @@ -182,8 +182,8 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp) Check_Type(tuple, T_ARRAY); if(RARRAY_LEN(tuple) < 2) { - xfree(head); - rb_raise(rb_eRuntimeError, "tag tuple must be of length 2"); + xfree(head); + rb_raise(rb_eRuntimeError, "tag tuple must be of length 2"); } name = RARRAY_AREF(tuple, 0); value = RARRAY_AREF(tuple, 1); diff --git a/ext/psych/psych_parser.c b/ext/psych/psych_parser.c index f08bddfe..26e2d41e 100644 --- a/ext/psych/psych_parser.c +++ b/ext/psych/psych_parser.c @@ -91,12 +91,12 @@ static VALUE make_exception(yaml_parser_t * parser, VALUE path) ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError")); return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6, - path, - SIZET2NUM(line), - SIZET2NUM(column), - SIZET2NUM(parser->problem_offset), - parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil, - parser->context ? rb_usascii_str_new2(parser->context) : Qnil); + path, + SIZET2NUM(line), + SIZET2NUM(column), + SIZET2NUM(parser->problem_offset), + parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil, + parser->context ? rb_usascii_str_new2(parser->context) : Qnil); } } @@ -269,10 +269,10 @@ static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path) yaml = transcode_string(yaml, &parser_encoding); yaml_parser_set_encoding(parser, parser_encoding); yaml_parser_set_input_string( - parser, - (const unsigned char *)RSTRING_PTR(yaml), - (size_t)RSTRING_LEN(yaml) - ); + parser, + (const unsigned char *)RSTRING_PTR(yaml), + (size_t)RSTRING_LEN(yaml) + ); } while(!done) { @@ -304,147 +304,147 @@ static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path) switch(event.type) { case YAML_STREAM_START_EVENT: { - VALUE args[2]; + VALUE args[2]; - args[0] = handler; - args[1] = INT2NUM(event.data.stream_start.encoding); - rb_protect(protected_start_stream, (VALUE)args, &state); + args[0] = handler; + args[1] = INT2NUM(event.data.stream_start.encoding); + rb_protect(protected_start_stream, (VALUE)args, &state); } break; case YAML_DOCUMENT_START_EVENT: { - VALUE args[4]; - /* Get a list of tag directives (if any) */ - VALUE tag_directives = rb_ary_new(); - /* Grab the document version */ - VALUE version = event.data.document_start.version_directive ? - rb_ary_new3( - (long)2, - INT2NUM(event.data.document_start.version_directive->major), - INT2NUM(event.data.document_start.version_directive->minor) - ) : rb_ary_new(); - - if(event.data.document_start.tag_directives.start) { - yaml_tag_directive_t *start = - event.data.document_start.tag_directives.start; - yaml_tag_directive_t *end = - event.data.document_start.tag_directives.end; - for(; start != end; start++) { - VALUE handle = Qnil; - VALUE prefix = Qnil; - if(start->handle) { - handle = rb_str_new2((const char *)start->handle); - PSYCH_TRANSCODE(handle, encoding, internal_enc); - } - - if(start->prefix) { - prefix = rb_str_new2((const char *)start->prefix); - PSYCH_TRANSCODE(prefix, encoding, internal_enc); - } - - rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix)); - } - } - args[0] = handler; - args[1] = version; - args[2] = tag_directives; - args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse; - rb_protect(protected_start_document, (VALUE)args, &state); + VALUE args[4]; + /* Get a list of tag directives (if any) */ + VALUE tag_directives = rb_ary_new(); + /* Grab the document version */ + VALUE version = event.data.document_start.version_directive ? + rb_ary_new3( + (long)2, + INT2NUM(event.data.document_start.version_directive->major), + INT2NUM(event.data.document_start.version_directive->minor) + ) : rb_ary_new(); + + if(event.data.document_start.tag_directives.start) { + yaml_tag_directive_t *start = + event.data.document_start.tag_directives.start; + yaml_tag_directive_t *end = + event.data.document_start.tag_directives.end; + for(; start != end; start++) { + VALUE handle = Qnil; + VALUE prefix = Qnil; + if(start->handle) { + handle = rb_str_new2((const char *)start->handle); + PSYCH_TRANSCODE(handle, encoding, internal_enc); + } + + if(start->prefix) { + prefix = rb_str_new2((const char *)start->prefix); + PSYCH_TRANSCODE(prefix, encoding, internal_enc); + } + + rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix)); + } + } + args[0] = handler; + args[1] = version; + args[2] = tag_directives; + args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse; + rb_protect(protected_start_document, (VALUE)args, &state); } break; case YAML_DOCUMENT_END_EVENT: { - VALUE args[2]; + VALUE args[2]; - args[0] = handler; - args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse; - rb_protect(protected_end_document, (VALUE)args, &state); + args[0] = handler; + args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse; + rb_protect(protected_end_document, (VALUE)args, &state); } break; case YAML_ALIAS_EVENT: { - VALUE args[2]; - VALUE alias = Qnil; - if(event.data.alias.anchor) { - alias = rb_str_new2((const char *)event.data.alias.anchor); - PSYCH_TRANSCODE(alias, encoding, internal_enc); - } - - args[0] = handler; - args[1] = alias; - rb_protect(protected_alias, (VALUE)args, &state); + VALUE args[2]; + VALUE alias = Qnil; + if(event.data.alias.anchor) { + alias = rb_str_new2((const char *)event.data.alias.anchor); + PSYCH_TRANSCODE(alias, encoding, internal_enc); + } + + args[0] = handler; + args[1] = alias; + rb_protect(protected_alias, (VALUE)args, &state); } break; case YAML_SCALAR_EVENT: { - VALUE args[7]; - VALUE anchor = Qnil; - VALUE tag = Qnil; - VALUE plain_implicit, quoted_implicit, style; - VALUE val = rb_str_new( - (const char *)event.data.scalar.value, - (long)event.data.scalar.length - ); - - PSYCH_TRANSCODE(val, encoding, internal_enc); - - if(event.data.scalar.anchor) { - anchor = rb_str_new2((const char *)event.data.scalar.anchor); - PSYCH_TRANSCODE(anchor, encoding, internal_enc); - } - - if(event.data.scalar.tag) { - tag = rb_str_new2((const char *)event.data.scalar.tag); - PSYCH_TRANSCODE(tag, encoding, internal_enc); - } - - plain_implicit = - event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue; - - quoted_implicit = - event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue; - - style = INT2NUM(event.data.scalar.style); - - args[0] = handler; - args[1] = val; - args[2] = anchor; - args[3] = tag; - args[4] = plain_implicit; - args[5] = quoted_implicit; - args[6] = style; - rb_protect(protected_scalar, (VALUE)args, &state); + VALUE args[7]; + VALUE anchor = Qnil; + VALUE tag = Qnil; + VALUE plain_implicit, quoted_implicit, style; + VALUE val = rb_str_new( + (const char *)event.data.scalar.value, + (long)event.data.scalar.length + ); + + PSYCH_TRANSCODE(val, encoding, internal_enc); + + if(event.data.scalar.anchor) { + anchor = rb_str_new2((const char *)event.data.scalar.anchor); + PSYCH_TRANSCODE(anchor, encoding, internal_enc); + } + + if(event.data.scalar.tag) { + tag = rb_str_new2((const char *)event.data.scalar.tag); + PSYCH_TRANSCODE(tag, encoding, internal_enc); + } + + plain_implicit = + event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue; + + quoted_implicit = + event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue; + + style = INT2NUM(event.data.scalar.style); + + args[0] = handler; + args[1] = val; + args[2] = anchor; + args[3] = tag; + args[4] = plain_implicit; + args[5] = quoted_implicit; + args[6] = style; + rb_protect(protected_scalar, (VALUE)args, &state); } break; case YAML_SEQUENCE_START_EVENT: { - VALUE args[5]; - VALUE anchor = Qnil; - VALUE tag = Qnil; - VALUE implicit, style; - if(event.data.sequence_start.anchor) { - anchor = rb_str_new2((const char *)event.data.sequence_start.anchor); - PSYCH_TRANSCODE(anchor, encoding, internal_enc); - } - - tag = Qnil; - if(event.data.sequence_start.tag) { - tag = rb_str_new2((const char *)event.data.sequence_start.tag); - PSYCH_TRANSCODE(tag, encoding, internal_enc); - } - - implicit = - event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue; - - style = INT2NUM(event.data.sequence_start.style); - - args[0] = handler; - args[1] = anchor; - args[2] = tag; - args[3] = implicit; - args[4] = style; - - rb_protect(protected_start_sequence, (VALUE)args, &state); + VALUE args[5]; + VALUE anchor = Qnil; + VALUE tag = Qnil; + VALUE implicit, style; + if(event.data.sequence_start.anchor) { + anchor = rb_str_new2((const char *)event.data.sequence_start.anchor); + PSYCH_TRANSCODE(anchor, encoding, internal_enc); + } + + tag = Qnil; + if(event.data.sequence_start.tag) { + tag = rb_str_new2((const char *)event.data.sequence_start.tag); + PSYCH_TRANSCODE(tag, encoding, internal_enc); + } + + implicit = + event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue; + + style = INT2NUM(event.data.sequence_start.style); + + args[0] = handler; + args[1] = anchor; + args[2] = tag; + args[3] = implicit; + args[4] = style; + + rb_protect(protected_start_sequence, (VALUE)args, &state); } break; case YAML_SEQUENCE_END_EVENT: @@ -452,32 +452,32 @@ static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path) break; case YAML_MAPPING_START_EVENT: { - VALUE args[5]; - VALUE anchor = Qnil; - VALUE tag = Qnil; - VALUE implicit, style; - if(event.data.mapping_start.anchor) { - anchor = rb_str_new2((const char *)event.data.mapping_start.anchor); - PSYCH_TRANSCODE(anchor, encoding, internal_enc); - } - - if(event.data.mapping_start.tag) { - tag = rb_str_new2((const char *)event.data.mapping_start.tag); - PSYCH_TRANSCODE(tag, encoding, internal_enc); - } - - implicit = - event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue; - - style = INT2NUM(event.data.mapping_start.style); - - args[0] = handler; - args[1] = anchor; - args[2] = tag; - args[3] = implicit; - args[4] = style; - - rb_protect(protected_start_mapping, (VALUE)args, &state); + VALUE args[5]; + VALUE anchor = Qnil; + VALUE tag = Qnil; + VALUE implicit, style; + if(event.data.mapping_start.anchor) { + anchor = rb_str_new2((const char *)event.data.mapping_start.anchor); + PSYCH_TRANSCODE(anchor, encoding, internal_enc); + } + + if(event.data.mapping_start.tag) { + tag = rb_str_new2((const char *)event.data.mapping_start.tag); + PSYCH_TRANSCODE(tag, encoding, internal_enc); + } + + implicit = + event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue; + + style = INT2NUM(event.data.mapping_start.style); + + args[0] = handler; + args[1] = anchor; + args[2] = tag; + args[3] = implicit; + args[4] = style; + + rb_protect(protected_start_mapping, (VALUE)args, &state); } break; case YAML_MAPPING_END_EVENT: diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index cedec46c..812a15df 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -1,8 +1,6 @@ # -*- coding: us-ascii; mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- # frozen_string_literal: true -# vim:sw=4:ts=4 -# $Id$ -# + require_relative 'helper' require 'ostruct' @@ -36,30 +34,30 @@ def test_multiline_regexp def test_regexp_with_n assert_cycle(Regexp.new('',Regexp::NOENCODING)) end - # - # Tests modified from 00basic.t in Psych.pm - # - def test_basic_map - # Simple map - assert_parse_only( - { 'one' => 'foo', 'three' => 'baz', 'two' => 'bar' }, < 'foo', 'three' => 'baz', 'two' => 'bar' }, < 'simple string', 2 => 42, 3 => '1 Single Quoted String', - 4 => 'Psych\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n", - 6 => "A \"chomped\" block", 7 => "A folded\n string\n", 8 => ": started string" }, - < 'simple string', 2 => 42, 3 => '1 Single Quoted String', + 4 => 'Psych\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n", + 6 => "A \"chomped\" block", 7 => "A folded\n string\n", 8 => ": started string" }, + < 65, 'avg' => 0.278, 'rbi' => 147 }, < 65, 'avg' => 0.278, 'rbi' => 147 }, < - [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ], - 'national' => - [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] }, < + [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ], + 'national' => + [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] }, < 'Mark McGwire', 'hr' => 65, 'avg' => 0.278}, - {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288} - ], < 'Mark McGwire', 'hr' => 65, 'avg' => 0.278}, + {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288} + ], < - { 'hr' => 65, 'avg' => 0.278 }, - 'Sammy Sosa' => - { 'hr' => 63, 'avg' => 0.288 } - }, < + { 'hr' => 65, 'avg' => 0.278 }, + 'Sammy Sosa' => + { 'hr' => 63, 'avg' => 0.288 } + }, < [ 'Mark McGwire', 'Sammy Sosa' ], - 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] }, < [ 'Mark McGwire', 'Sammy Sosa' ], + 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] }, < - [ 'Mark McGwire', 'Sammy Sosa' ], - 'rbi' => - [ 'Sammy Sosa', 'Ken Griffey' ] }, < + [ 'Mark McGwire', 'Sammy Sosa' ], + 'rbi' => + [ 'Sammy Sosa', 'Ken Griffey' ] }, <"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}], < [ 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 ) ] }, < [ 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 ) ] }, < - [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), - Date.new( 2001, 8, 14 ) ], - [ 'Detroit Tigers', 'Chicago Cubs' ] => - [ Date.new( 2001, 7, 23 ) ] - }, < + [ 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 } ] }, < 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 } ] }, < Mark McGwire\'s year was crippled by a knee injury. EOY - ) - end + ) + end - def test_spec_preserve_indent - # Preserve indented spaces - assert_parse_only( - "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n", < Sammy Sosa completed another fine season with great stats. @@ -385,13 +383,13 @@ def test_spec_preserve_indent What a year! EOY - ) - end + ) + end - def test_spec_indentation_determines_scope - assert_parse_only( - { 'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n", - 'stats' => "65 Home Runs\n0.278 Batting Average\n" }, < 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n", + 'stats' => "65 Home Runs\n0.278 Batting Average\n" }, < Mark set a major league @@ -400,14 +398,14 @@ def test_spec_indentation_determines_scope 65 Home Runs 0.278 Batting Average EOY - ) - end - - def test_spec_multiline_scalars - # Multiline flow scalars - assert_parse_only( - { 'plain' => 'This unquoted scalar spans many lines.', - 'quoted' => "So does this quoted scalar.\n" }, < 'This unquoted scalar spans many lines.', + 'quoted' => "So does this quoted scalar.\n" }, < 12345, 'decimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex }, < 12345, 'decimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex }, < 685230, 'decimal' => 685230, 'octal' => 02472256, 'hexadecimal' => 0x0A74AE, 'sexagesimal' => 685230 }, < 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15, - 'negative infinity' => -1.0/0.0 }, < 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15, + 'negative infinity' => -1.0/0.0 }, < nil, true => true, false => false, 'string' => '12345' }, < nil, true => true, false => false, 'string' => '12345' }, < 'Chris', 'family' => 'Dumars', 'address' => - { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', - 'state' => 'MI', 'postal' => 48046 } } - assert_parse_only( - { '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" }, < 'Chris', 'family' => 'Dumars', 'address' => + { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak', + 'state' => 'MI', 'postal' => 48046 } } + assert_parse_only( + { '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" }, < mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ), - 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } ) - when 1 - assert_equal( doc, { 'Time' => mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ), - 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } ) - when 2 - assert_equal( doc, { '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" } ] } ) - end - doc_ct += 1 - } - assert_equal( doc_ct, 3 ) - end - - def test_spec_root_fold - y = Psych::load( < mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ), + 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } ) + when 1 + assert_equal( doc, { 'Time' => mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ), + 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } ) + when 2 + assert_equal( doc, { '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" } ] } ) + end + doc_ct += 1 + } + assert_equal( doc_ct, 3 ) + end + + def test_spec_root_fold + y = Psych::load( < 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } ) - end + ) + assert_equal( y, { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } ) + end - def test_spec_oneline_docs - doc_ct = 0 - Psych::load_stream( < { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, < { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, <"contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"}, <"contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"}, < 12, 'also int' => 12, 'string' => '12' }, < 12, 'also int' => 12, 'string' => '12' }, < [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value' ] }, < [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value' ] }, < 'This scalar has an anchor.', 'override' => a001, 'alias' => a001 }, < 'This scalar has an anchor.', 'override' => a001, 'alias' => a001 }, < The alias node below is a repeated use of this value. alias : *A001 EOY - ) - end + ) + end - def test_spec_explicit_families + def test_spec_explicit_families Psych.add_domain_type( "somewhere.com/2002", 'type' ) { |type, val| "SOMEWHERE: #{val}" } - assert_parse_only( - { '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" }, < '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" }, <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"]], <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"]], < [], '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' ] }, < [], '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' ] }, < {}, '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.' ] } }, < {}, '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 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"}, <" 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 }, < 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"}, <"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"}, <"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" ) }, < 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" }, < arrow_gif, 'base64' => arrow_gif, + 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n" }, < /a.b/, 'complex' => %r'\A"((?:[^"]|\")+)"', - 'case-insensitive' => /George McFly/i }, < /a.b/, 'complex' => %r'\A"((?:[^"]|\")+)"', + 'case-insensitive' => /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 + ) + end + + ## + ## Test the Psych::Stream class -- INACTIVE at the moment + ## + #def test_document + # y = Psych::Stream.new( :Indent => 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