#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) require File.join( currentPath, '../test_helper' ) class TestSimplifiedDirectiveBase < Test::Unit::TestCase def test_nothing_yet end end =begin comment out for now class SimplifiedDirectiveExample < MasterView::SimplifiedDirectiveBase end class TestSimplifiedDirectiveBase < Test::Unit::TestCase def setup @sde = SimplifiedDirectiveExample.new('product, desc, {:foo => :bar}, :readonly => false') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) end def test_args @sde.arg :obj @sde.arg :method @sde.arg :options @sde.arg :html_options @sde.arg :not_there assert @sde.instance_variables.include?('@obj') assert @sde.instance_variables.include?('@method') assert @sde.instance_variables.include?('@options') assert @sde.instance_variables.include?('@html_options') assert @sde.instance_variables.include?('@not_there') assert_equal 'product', @sde.instance_variable_get('@obj') assert_equal 'desc', @sde.instance_variable_get('@method') assert_equal '{:foo => :bar}', @sde.instance_variable_get('@options') assert_equal ':readonly => false', @sde.instance_variable_get('@html_options') assert_equal nil, @sde.instance_variable_get('@not_there') end def test_arg_quote @sde.arg :obj, :quote => true @sde.arg :method, :quote => false assert_equal '\'product\'', @sde.instance_variable_get('@obj') assert_equal 'desc', @sde.instance_variable_get('@method') end def test_prepare_output @sde.arg :obj @sde.arg :method @sde.arg :options @sde.arg :html_options assert_equal 'test', @sde.prepare_output('test') assert_equal 'test product', @sde.prepare_output('test', :obj) assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method) assert_equal 'test product, desc, {:foo => :bar}', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, {:foo => :bar}, :readonly => false', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_mixed @sde.arg :obj @sde.arg :method @sde.arg :options @sde.arg :html_options assert_equal 'test product, :foo', @sde.prepare_output('test', :obj, :foo) assert_equal 'test product, :foo, :bar', @sde.prepare_output('test', :obj, :foo, :bar) assert_equal 'test product, desc, {:foo => :bar}, :hello', @sde.prepare_output('test', :obj, :method, :options, :hello) assert_equal 'test product, desc, {:foo => :bar}, :hello, 1', @sde.prepare_output('test', :obj, :method, :options, :hello, 1) assert_equal 'test product, desc, {:foo => :bar}, :hello, 1, [:a, :b]', @sde.prepare_output('test', :obj, :method, :options, :hello, 1, [:a, :b]) end def test_prepare_output_quote @sde.arg :obj, :quote => true @sde.arg :method, :quote => true @sde.arg :options @sde.arg :html_options assert_equal 'test', @sde.prepare_output('test') assert_equal 'test \'product\'', @sde.prepare_output('test', :obj) assert_equal 'test \'product\', \'desc\'', @sde.prepare_output('test', :obj, :method) assert_equal 'test \'product\', \'desc\', {:foo => :bar}', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test \'product\', \'desc\', {:foo => :bar}, :readonly => false', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil @sde = SimplifiedDirectiveExample.new('product, desc, {:foo => :bar}, :readonly => false') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options @sde.arg :html_options @sde.instance_variable_set("@options", nil) assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, nil, :readonly => false', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_needs_brackets @sde = SimplifiedDirectiveExample.new('product, desc, :foo => :bar') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options @sde.arg :html_options @sde.instance_variable_set("@html_options", ':hello => :world') assert_equal 'test product, desc, :foo => :bar', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, { :foo => :bar }, :hello => :world', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_empty_string @sde = SimplifiedDirectiveExample.new('product, desc, :foo => :bar') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options @sde.arg :html_options @sde.instance_variable_set("@options", '') @sde.instance_variable_set("@html_options", ':hello => :world') assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, nil, :hello => :world', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil_opt_default_string @sde = SimplifiedDirectiveExample.new('product, desc') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options, :default => '{}' @sde.arg :html_options @sde.instance_variable_set("@html_options", ':readonly => true') assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, {}, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil_opt_default_hash @sde = SimplifiedDirectiveExample.new('product, desc') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options, :default => {} @sde.arg :html_options @sde.instance_variable_set("@html_options", ':readonly => true') assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, {}, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil_opt_default_array @sde = SimplifiedDirectiveExample.new('product, desc') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options, :default => [] @sde.arg :html_options @sde.instance_variable_set("@html_options", ':readonly => true') assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, [], :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil_opt_default_symbol @sde = SimplifiedDirectiveExample.new('product, desc') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options, :default => :foo @sde.arg :html_options @sde.instance_variable_set("@html_options", ':readonly => true') assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, :foo, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil_opt_default_fixnum @sde = SimplifiedDirectiveExample.new('product, desc') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options, :default => 123 @sde.arg :html_options @sde.instance_variable_set("@html_options", ':readonly => true') assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, 123, :readonly => true', @sde.prepare_output('test', :obj, :method, :options, :html_options) end def test_prepare_output_middle_nil_opt_default_hash_mixed @sde = SimplifiedDirectiveExample.new('product, desc') @sde.save_directive_call_stack(MasterView::ParserMock.createMockDCS()) @sde.arg :obj @sde.arg :method @sde.arg :options, :default => {} assert_equal 'test product, desc', @sde.prepare_output('test', :obj, :method, :options) assert_equal 'test product, desc, {}, 123', @sde.prepare_output('test', :obj, :method, :options, 123) end def test_merge_common_str @sde.element_attrs['class'] = 'red' @sde.element_attrs['id'] = 'id1' @sde.arg :obj @sde.arg :method @sde.arg :options, :default => {} @sde.arg :html_options, :append_element_attrs => [:common_html] assert_equal ':readonly => false, :class => "red", :id => "id1"', @sde.instance_variable_get('@html_options') end def test_merge_common_array @sde.element_attrs['class'] = 'red' @sde.element_attrs['id'] = 'id1' @sde.arg :obj @sde.arg :method @sde.arg :options, :default => {} @sde.arg :html_options, :append_element_attrs => [:common_html] assert_equal ':readonly => false, :class => "red", :id => "id1"', @sde.instance_variable_get('@html_options') end def test_render_nothing @sde.arg :obj assert_equal nil, @sde.render_nothing end def test_render @sde.arg :obj result = @sde.render @sde.prepare_output 'test', :obj assert_equal ['test product'], result result = @sde.render @sde.prepare_output 'hello', :obj assert_equal ['test product', 'hello product'], result end def test_render_erb_content @sde.arg :obj result = @sde.render @sde.erb_content 'test', :obj assert_equal ['<%= test product %>'], result result = @sde.render @sde.erb_content 'hello', :obj assert_equal ['<%= test product %>', '<%= hello product %>'], result end def test_merge_hash_into_str assert_equal '', @sde.merge_hash_into_str({}, '') assert_equal ':foo => :bar', @sde.merge_hash_into_str({}, ':foo => :bar') assert_equal ':foo => :bar', @sde.merge_hash_into_str({:foo => :bar}, '') assert_equal ':foo => :baz, :foo => :bar', @sde.merge_hash_into_str({:foo => :bar}, ':foo => :baz') assert_equal ':foo => :baz, :foo => :bar, :goo => :hello', @sde.merge_hash_into_str({:goo => :hello, :foo => :bar}, ':foo => :baz') assert_equal '"class" => "red"', @sde.merge_hash_into_str({'class' => 'red'}, '') assert_equal '{}', @sde.merge_hash_into_str({}, '{}') assert_equal '{:foo => :bar}', @sde.merge_hash_into_str({}, '{:foo => :bar}') assert_equal '{:foo => :bar}', @sde.merge_hash_into_str({:foo => :bar}, '{ }') assert_equal '{:foo => :baz, :foo => :bar}', @sde.merge_hash_into_str({:foo => :bar}, ' {:foo => :baz} ') assert_equal '{:foo => :baz, :foo => :bar, :goo => :hello}', @sde.merge_hash_into_str({:goo => :hello, :foo => :bar}, '{:foo => :baz}') assert_equal '{"class" => "red"}', @sde.merge_hash_into_str({'class' => 'red'}, '{}') end end =end