#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) class TestDirectiveHelpers < Test::Unit::TestCase include MasterView::Directives include MasterView::DirectiveHelpers include MasterView::ParserHelpers def test_parse_eval_into_array_a a = parse_eval_into_array("hello, world") assert_equal "hello", a[0] assert_equal "world", a[1] end def test_parse_eval_into_array_b a = parse_eval_into_array("'hello', 'world'") assert_equal "hello", a[0] assert_equal "world", a[1] end def test_parse_eval_into_array_c a = parse_eval_into_array("hello, 'world'") assert_equal "hello", a[0] assert_equal "world", a[1] end def test_parse_eval_into_array_d a = parse_eval_into_array("\"hello\", 'world'") assert_equal "hello", a[0] assert_equal "world", a[1] end def test_parse_eval_into_array_e a = parse_eval_into_array("hello, \"world\"") assert_equal "hello", a[0] assert_equal "world", a[1] end def test_parse_eval_into_array_f a = parse_eval_into_array(":foo => :bar") assert_equal( {:foo => :bar}, a[0] ) end def test_parse_eval_into_array_g a = parse_eval_into_array(":foo => :bar, :baz => :cat") assert_equal( {:foo => :bar, :baz => :cat}, a[0] ) end def test_parse_eval_into_array_h a = parse_eval_into_array(":foo => :bar, :baz => 'cat'") assert_equal( {:foo => :bar, :baz => 'cat'}, a[0] ) end def test_parse_eval_into_array_i a = parse_eval_into_array(":foo => 'bar', :baz => :cat") assert_equal( {:foo => 'bar', :baz => :cat}, a[0] ) end def test_parse_eval_into_array_j a = parse_eval_into_array("hello, :foo => :bar, :baz => :cat") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => :cat}, a[1] ) end def test_parse_eval_into_array_k a = parse_eval_into_array("'hello', {:foo => :bar, :baz => :cat}" ) assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => :cat}, a[1] ) end def test_parse_eval_into_array_l a = parse_eval_into_array("\"hello\", {:foo => :bar, :baz => :cat}") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => :cat}, a[1] ) end def test_parse_eval_into_array_m a = parse_eval_into_array("hello, {:foo => :bar, :baz => :cat}") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => :cat}, a[1] ) end def test_parse_eval_into_array_n a = parse_eval_into_array("hello, {:foo => :bar, :baz => :cat}") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => :cat}, a[1] ) end def test_parse_eval_into_array_o a = parse_eval_into_array("hello, {:foo => :bar, :baz => [1,2]}") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => [1,2]}, a[1] ) end def test_parse_eval_into_array_n a = parse_eval_into_array("hello, {:foo => :bar, :baz => ['one', 'two']}") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => ['one', 'two']}, a[1] ) end def test_parse_eval_into_array_o a = parse_eval_into_array("hello, {:foo => :bar, :baz => :cat}, {:dog => :egg}") assert_equal "hello", a[0] assert_equal( {:foo => :bar, :baz => :cat}, a[1] ) assert_equal( {:dog => :egg}, a[2] ) end def test_parse_hash assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar'", ":partial") assert_equal "foo/bar", find_string_val_in_string_hash(':partial => "foo/bar"', ":partial") assert_equal "foo/bar", find_string_val_in_string_hash(":baz => :cat, :partial => 'foo/bar'", ":partial") assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar', :baz => 'cat'", ":partial") assert_equal "foo/bar", find_string_val_in_string_hash(":partial=>'foo/bar'", ":partial") assert_equal "foo/bar", find_string_val_in_string_hash(" :partial => 'foo/bar' ", ":partial") assert_equal "foo/bar", find_string_val_in_string_hash("'hello', :partial => 'foo/bar'", ":partial") assert_equal "foo/bar", find_string_val_in_string_hash("hello, :partial => 'foo/bar'", ":partial") end def test_parse_hash_passing_symbol assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar'", :partial) assert_equal "foo/bar", find_string_val_in_string_hash(':partial => "foo/bar"', :partial) assert_equal "foo/bar", find_string_val_in_string_hash(":baz => :cat, :partial => 'foo/bar'", :partial) assert_equal "foo/bar", find_string_val_in_string_hash(":partial => 'foo/bar', :baz => 'cat'", :partial) assert_equal "foo/bar", find_string_val_in_string_hash(":partial=>'foo/bar'", :partial) assert_equal "foo/bar", find_string_val_in_string_hash(" :partial => 'foo/bar' ", :partial) assert_equal "foo/bar", find_string_val_in_string_hash("'hello', :partial => 'foo/bar'", :partial) assert_equal "foo/bar", find_string_val_in_string_hash("hello, :partial => 'foo/bar'", :partial) end #DEPRECATED # def test_remove_prepended_strings # assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, world, :foo => 'bar', :baz => :cat" ) # assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "'hello', 'world', :foo => 'bar', :baz => :cat" ) # assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, 'world', :foo => 'bar', :baz => :cat" ) # assert_equal ":foo => 'bar', :baz => :cat", remove_prepended_strings( "hello, world, :foo => 'bar', :baz => :cat" ) # assert_equal "{:foo => 'bar', :baz => :cat}", remove_prepended_strings( "hello, world, {:foo => 'bar', :baz => :cat}" ) # assert_equal ':action => :add, :id => %Q[srcitem_#{srcitem.pkey}]', remove_prepended_strings( 'hello, world, :action => :add, :id => %Q[srcitem_#{srcitem.pkey}]' ) # end end