From db8a622d4687954b67dc675158bac07ed5d57cfa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 26 Sep 2009 21:19:15 -0700 Subject: start_document is working --- test/helper.rb | 2 ++ test/psych/test_parser.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++ test/test_psych.rb | 12 ++++++++---- 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 test/helper.rb create mode 100644 test/psych/test_parser.rb (limited to 'test') diff --git a/test/helper.rb b/test/helper.rb new file mode 100644 index 0000000..8e77fed --- /dev/null +++ b/test/helper.rb @@ -0,0 +1,2 @@ +require "test/unit" +require "psych" diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb new file mode 100644 index 0000000..748d67b --- /dev/null +++ b/test/psych/test_parser.rb @@ -0,0 +1,49 @@ +require 'helper' + +module Psych + class TestParser < Test::Unit::TestCase + class EventCatcher < Parser::Handler + attr_reader :calls + def initialize + @calls = [] + end + + (Parser::Handler.instance_methods(true) - + Object.instance_methods).each do |m| + class_eval %{ + def #{m} *args + super + @calls << [:#{m}, args] + end + } + end + end + + def setup + @parser = Psych::Parser.new EventCatcher.new + end + + def test_end_stream + @parser.parse("--- foo\n") + assert_called :end_stream + end + + def test_start_stream + @parser.parse("--- foo\n") + assert_called :start_stream + end + + def test_start_document + @parser.parse("%YAML 1.1\n---\n\"foo\"\n") + assert_called :start_document, [[1,1]] + end + + def assert_called call, with = nil, parser = @parser + if with + assert parser.handler.calls.any? { |x| x == [call, with] } + else + assert parser.handler.calls.any? { |x| x.first == call } + end + end + end +end diff --git a/test/test_psych.rb b/test/test_psych.rb index 33a3cc0..dbf892a 100644 --- a/test/test_psych.rb +++ b/test/test_psych.rb @@ -1,8 +1,12 @@ -require "test/unit" -require "psych" +require 'helper' class TestPsych < Test::Unit::TestCase - def test_sanity - flunk "write tests or I will kneecap you" + def test_simple + assert_equal 'foo', Psych.parse("--- foo\n") + end + + def test_libyaml_version + assert Psych.libyaml_version + assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION end end -- cgit v1.2.3