summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-26 21:19:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-26 21:19:15 -0700
commitdb8a622d4687954b67dc675158bac07ed5d57cfa (patch)
tree6e80b7bebf224d6d9f9435ba9d9bd8216ae94b67 /test
parentec8ae73b763f8d814adbae4868bac5f7b6c49a48 (diff)
downloadpsych-db8a622d4687954b67dc675158bac07ed5d57cfa.zip
start_document is working
Diffstat (limited to 'test')
-rw-r--r--test/helper.rb2
-rw-r--r--test/psych/test_parser.rb49
-rw-r--r--test/test_psych.rb12
3 files changed, 59 insertions, 4 deletions
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