require "test/unit/testcase"
require "rexml/light/node"
require "rexml/parsers/lightparser"

include REXML::Light

class LightTester < Test::Unit::TestCase
	def test_add_element
		doc = Node.new
		foo = doc << "foo"
		assert_equal( "foo", foo.name )
	end
	
	def test_add_attribute
		foo = Node.new( "a" )
		foo["attr"] = "bar"
		assert_equal( "bar", foo["attr"] )
	end

	# FIXME INCOMPLETE
=begin
	def test_write_document
		r = make_small_document
		assert_equal( "<a><b/><c/></a>", r.to_s )
	end

	def test_add_attribute_under_namespace
		foo = Node.new("a")
		foo["attr", "a"] = "1"
		foo["attr", "b"] = "2"
		foo["attr"] = "3"
		assert_equal( '1', foo['attr', 'a'] )
		assert_equal( '2', foo['attr', 'b'] )
		assert_equal( '3', foo['attr'] )
	end

	def test_change_namespace_of_element
		foo = Node.new
		assert_equal( '', foo.namespace )
		foo.namespace = 'a'
		assert_equal( 'a', foo.namespace )
	end
=end

	def test_access_child_elements
		foo = make_small_document
		assert_equal( 1, foo.size )
		a = foo[0]
		assert_equal( 2, a.size )
		assert_equal( 'b', a[0].name )
		assert_equal( 'c', a[1].name )
	end

	def test_itterate_over_children
		foo = make_small_document
		ctr = 0
		foo[0].each { ctr += 1 }
		assert_equal( 2, ctr )
	end

	def test_add_text
		foo = Node.new( "a" )
		foo.el!
		foo << "Sean"
		sean = foo[0]
		assert( sean.text? )
	end

	def test_add_instruction
	end

	def test_add_comment
	end

	def test_get_root

	end

	def test_auto
		a = Node.new("foo")
	end

	def make_small_document
		r = Node.new
		a = r << "a"
		a.el!
		(a << "b").el!
		(a << "c").el!
		r
	end
end
