#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) class TestParser < Test::Unit::TestCase include MasterView::Directives def test_render_level rl = MasterView::RenderLevel.new assert_equal [], rl.render_modes a = MasterView::RenderMode.new b = MasterView::RenderMode.new rl = MasterView::RenderLevel.new [a,b] assert_equal [a,b], rl.render_modes c = MasterView::RenderMode.new rl.push c assert_equal [a,b,c], rl.render_modes end def test_render_mode rm = MasterView::RenderMode.new assert_equal nil, rm.output assert_equal :normal, rm.mode_type assert_equal [], rm.tags a = '/foo/bar' rm = MasterView::RenderMode.new(a) assert_equal a, rm.output assert_equal :normal, rm.mode_type assert_equal [], rm.tags rm = MasterView::RenderMode.new(a, :wide) assert_equal a, rm.output assert_equal :wide, rm.mode_type assert_equal [], rm.tags t1 = nil directives = [:f1, :f2] tag_name = 'foo' attributes = { 'bar' => 'baz', 'can' => 'dog' } mode_type = :wide parent = :parent t2 = MasterView::Tag.new(directives, tag_name, attributes, mode_type, parent) rm.tags << t1 << t2 assert_equal [t1,t2], rm.tags assert_equal t2, rm.tag assert_equal directives, rm.directives assert_equal "foo_bar_baz", rm.determine_method('foo', 'bar', 'baz') end def test_render_mode_render_directives #todo end def test_dcs dcs = MasterView::DirectiveCallStack.new dcs << :a dcs << :b dcs << [:c,:d] assert_equal [:a,:b,:c,:d], dcs.directives_to_call dcs2 = MasterView::DirectiveCallStack.new dcs2 << :e dcs2 << :f assert_equal [:e,:f], dcs2.directives_to_call dcs << dcs2 assert_equal [:a,:b,:c,:d,:e,:f], dcs.directives_to_call assert_equal [], MasterView::DirectiveCallStack.new.render proc1 = lambda { |f| "1" } proc2 = lambda { |f| "2" } dcs3 = MasterView::DirectiveCallStack.new dcs3 << proc1 dcs3 << proc2 assert_equal '1', dcs3.render end def test_directives fs = MasterView::DirectiveSet.new fs << :a fs << :b fs << [:c, :d] assert_equal [:a,:b,:c,:d], fs.directives end def test_directives_determine_dcs #todo end def test_create_call_proc #todo end def test_simple_render_handler s = MasterView::SimpleRenderHandler.new dcs = MasterView::DirectiveCallStack.new directives = [:f1, :f2] tag_name = 'foo' attributes = { 'bar' => 'baz', 'can' => 'dog' } mode_type = :wide parent = :parent t2 = MasterView::Tag.new(directives, tag_name, attributes, mode_type, parent) dcs.context = { :tag => t2 } ret = s.stag(dcs) assert_equal "', ret[3] assert ret.include?(" bar=\"baz\"" ) assert ret.include?(" can=\"dog\"" ) dcs.context[:content_part] = 'hello' assert_equal ['hello'], s.characters(dcs) assert_equal [''], s.comment(dcs) assert_equal [''], s.cdata(dcs) assert_equal [''], s.etag(dcs) end def test_tag directives = [:f1, :f2] tag_name = 'foo' attributes = { 'bar' => 'baz', 'can' => 'dog' } mode_type = :wide parent = :parent t = MasterView::Tag.new(directives, tag_name, attributes, mode_type, parent) assert_equal [:f1, :f2], t.directives assert_equal tag_name, t.tag_name assert_equal attributes, t.attributes assert_equal mode_type, t.mode_type t.stag << :a << :b assert_equal [:a,:b], t.stag t.content << :c << :d assert_equal [:c,:d], t.content t.etag << :e << :f assert_equal [:e, :f], t.etag assert_equal :parent, t.parent con = t.create_context assert_equal t, con[:tag] assert_equal :wide, con[:mode_type] con = t.create_context( :g => :h, :i => :j, :mode_type => :long ) assert_equal t, con[:tag] assert_equal :long, con[:mode_type] assert_equal :h, con[:g] assert_equal :j, con[:i] assert_equal [[:a,:b], [:c,:d], [:e,:f]], t.data end # base, meta, link, hr, br, param, img, area, input, col def test_simplify_element_names r = MasterView::Renderer.new(:output_mio_tree => MasterView::StringHashMIOTree.new ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal [''], r.simplify_empty_elements( ['', ''] ) assert_equal ['', ''], r.simplify_empty_elements( ['', ''] ) assert_equal ['', ''], r.simplify_empty_elements( ['', ''] ) end def test_renderer #todo end def test_parser #todo end end