diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-26 23:33:38 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-26 23:33:38 -0700 |
commit | 4f9d7c2a74e025da75e1eaa52ab2ef06a5a37cb6 (patch) | |
tree | 98e44da327b731a7e01b3ee78b2a2051abdc5bfe | |
parent | a78acf40e25f14093ae8d60c04f7f00e99330a38 (diff) | |
download | psych-4f9d7c2a74e025da75e1eaa52ab2ef06a5a37cb6.zip |
scalar found
-rw-r--r-- | ext/psych/parser.c | 9 | ||||
-rw-r--r-- | lib/psych/parser/handler.rb | 5 | ||||
-rw-r--r-- | test/psych/test_parser.rb | 7 |
3 files changed, 20 insertions, 1 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c index c7237e5..4ae3625 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -72,6 +72,15 @@ static VALUE parse_string(VALUE self, VALUE string) Qnil ); break; + case YAML_SCALAR_EVENT: + { + VALUE val = rb_str_new( + event.data.scalar.value, + event.data.scalar.length + ); + rb_funcall(handler, rb_intern("scalar"), 1, val); + } + 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 00573df..599dfe2 100644 --- a/lib/psych/parser/handler.rb +++ b/lib/psych/parser/handler.rb @@ -25,6 +25,11 @@ module Psych end ### + # Called when a scalar +value+ is found + def scalar value + 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 83e5482..7d6335b 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -23,6 +23,11 @@ module Psych @parser = Psych::Parser.new EventCatcher.new end + def test_scalar + @parser.parse("--- foo\n") + assert_called :scalar, ['foo'] + end + def test_alias @parser.parse(<<-eoyml) %YAML 1.1 @@ -71,7 +76,7 @@ module Psych def assert_called call, with = nil, parser = @parser if with assert( - parser.handler.calls.any? { |x| x == [call, with] }, + parser.handler.calls.any? { |x| x.compact == [call, with] }, "#{[call,with].inspect} not in #{parser.handler.calls.inspect}" ) else |