diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-26 21:55:50 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-26 21:55:50 -0700 |
commit | 8e40ad6074f9eb5958735878e44aa2ca9fcdda1c (patch) | |
tree | 3afb243c8e336ccfb3b7b3979f355c48aa1a7554 | |
parent | 850df20bf83d182703d075951bfb95fb4531748a (diff) | |
download | psych-8e40ad6074f9eb5958735878e44aa2ca9fcdda1c.zip |
implicit start and end document
-rw-r--r-- | ext/psych/parser.c | 5 | ||||
-rw-r--r-- | lib/psych/parser/handler.rb | 5 | ||||
-rw-r--r-- | test/psych/test_parser.rb | 14 |
3 files changed, 22 insertions, 2 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c index a9b0667..2efdb09 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -60,6 +60,11 @@ static VALUE parse_string(VALUE self, VALUE string) ); } break; + case YAML_DOCUMENT_END_EVENT: + rb_funcall(handler, rb_intern("end_document"), 1, + event.data.document_end.implicit == 1 ? Qtrue : Qfalse + ); + break; case YAML_STREAM_END_EVENT: rb_funcall(handler, rb_intern("end_stream"), 0); done = 1; diff --git a/lib/psych/parser/handler.rb b/lib/psych/parser/handler.rb index 211ebf1..5b330a0 100644 --- a/lib/psych/parser/handler.rb +++ b/lib/psych/parser/handler.rb @@ -15,6 +15,11 @@ module Psych end ### + # Called with the document ends. + def end_document implicit = true + end + + ### # Called when the YAML stream ends def end_stream end diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index 187bace..13d4376 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -33,9 +33,19 @@ module Psych assert_called :start_stream end - def test_start_document_implicit + def test_end_document_implicit + @parser.parse("\"foo\"\n") + assert_called :end_document, [true] + end + + def test_end_document_explicit @parser.parse("\"foo\"\n") - assert_called :start_document, [[], [], true] + assert_called :end_document, [true] + end + + def test_start_document_implicit + @parser.parse("\"foo\"\n...") + assert_called :end_document, [false] end def test_start_document_version |