require "runit/testcase"
require "runit/cui/testrunner"
require "MyoPyx"

class TestListener
	attr_reader :count
	def initialize
		@count = 0
	end
	def start_element name, attributes
		@count += 1 if name=="Continent"
	end
	def end_element name
	end
	def text string
	end
end

class Tester < RUNIT::TestCase
	def test_validate
		File.open("cities.pyx") do |f|
			pyx = MyoPyx.new
			pyx.parse f
		end
	end

	def test_parse
		File.open("cities.pyx") do |f|
			pyx = MyoPyx.new
			list = TestListener.new
			pyx.add_listener list, "Continent"
			pyx.parse f
			assert_equals 8, list.count
		end
	end

	def test_bad_tag_order
		File.open("bad1.pyx") do |f|
			pyx = MyoPyx.new
			pyx.parse f
			assert_fail "Should have gotten an bad tag order error!"
		end
	rescue
		# This is the correct behavior
	end

	def test_bad_content
		File.open("bad2.pyx") do |f|
			pyx = MyoPyx.new
			pyx.parse f
			assert_fail "Should have gotten an bad markup error!"
		end
	rescue
		# This is the correct behavior
	end
end

RUNIT::CUI::TestRunner.run( Tester.suite )
