require 'runit/testcase' require "amrita/xml" require "amrita/format" require "amrita/amx" class TestXML < RUNIT::TestCase include Amrita include Amx def rexml_to_amrita(s) l = Listener.new REXML::Document.parse_stream(s, l) l.result.to_s end def test_listener a = 'test' assert_equal(a, rexml_to_amrita(a)) a = '

test

' assert_equal(a, rexml_to_amrita(a)) a = '

test

' assert_equal(a, rexml_to_amrita(a)) a = '

testtesttest

' assert_equal(a, rexml_to_amrita(a)) a = '' assert_equal(a, rexml_to_amrita(a)) a = <<-END xhtml sample

title

body text


END assert_equal(' xhtml sample

title

body text


', rexml_to_amrita(a)) end def test_entity a = '&test' # p rexml_to_amrita(a) assert_equal(a, rexml_to_amrita(a)) end def test_amx1 tmpfile="/tmp/amxtest#$$.amx" doc_text = < amx sample

amx is a XML document. It contains model data as well-formed XML, HTML template and a small Ruby code map both.

This is a sample AMX document.

END doc = Amx::Document.new doc_text assert_equal(tmpfile, doc.template_href) template_text = < { :title => doc.elements['document/head/title'], :body => doc.elements.to_a('document/body/p') } END File.open(tmpfile, "w") { |f| f.write template_text } t = Amx::Template[tmpfile] result = "" t.prettyprint=false t.expand(result, doc) assert_equal(<<-END.strip, result.strip) xxxxx amx sample

amx is a XML document. It contains model data as well-formed XML, HTML template and a small Ruby code map both.

This is a sample AMX document.


END ensure File::unlink tmpfile end end #--- main program ---- if __FILE__ == $0 require 'runit/cui/testrunner' if ARGV.size == 0 RUNIT::CUI::TestRunner.run(TestXML.suite) else ARGV.each do |method| RUNIT::CUI::TestRunner.run(TestXML.new(method)) end end end