require 'test/unit' require './clothesline' class ClothAdd < String def initialize(str, restrictions = []) super str end def to_html(options = {}) (options[:prefix] || "foo") + self end end class ClothReverse < String def initialize(str, restrictions = []) super str end def to_html(dont = false) unless dont self.reverse else self end end end module Override class ClothReverse < String def initialize(str) super str end alias_method :to_html, :to_s end end class TestClothesLine < Test::Unit::TestCase def test_single c = ClothesLine.new(ClothAdd) assert_equal "foobar", c.new("bar").to_html assert_equal "footsteps", c.new("tsteps").to_html end def test_multiple c = ClothesLine.new(ClothAdd, ClothReverse) assert_equal "raboof", c.new("bar").to_html assert_equal "spetstoof", c.new("tsteps").to_html end def test_parametrized c = ClothesLine.new([ClothAdd, {:prefix => "quux"}]) assert_equal "quuxbar", c.new("bar").to_html assert_equal "quuxtsteps", c.new("tsteps").to_html c = ClothesLine.new([ClothAdd, {:prefix => "quux"}], [ClothReverse, true]) assert_equal "quuxbar", c.new("bar").to_html assert_equal "quuxtsteps", c.new("tsteps").to_html end def test_parsing c = ClothesLine.parse("ClothAdd ClothReverse") assert_equal "raboof", c.new("bar").to_html assert_equal "spetstoof", c.new("tsteps").to_html assert_equal ClothesLine.parse("ClothAdd ClothReverse"), ClothesLine.parse("ClothAdd, ClothReverse") assert_equal ClothesLine.parse("ClothAdd ClothReverse"), ClothesLine.parse("ClothAdd | ClothReverse") assert_equal "ClothAdd ClothReverse", ClothesLine.parse("ClothAdd ClothReverse").to_clothesline assert_equal "ClothAdd ClothReverse", ClothesLine.parse("ClothAdd, ClothReverse").to_clothesline assert_equal "ClothAdd ClothReverse", ClothesLine.parse("ClothAdd | ClothReverse").to_clothesline end def test_parsing_requires c = ClothesLine.parse("BlueCloth ClothReverse") assert_equal ">p/p<", c.new("bar").to_html assert_equal ">p/<>me/mep<", c.new("tstep*s*").to_html c = ClothesLine.parse("ClothReverse RedCloth") assert_equal "

rab

", c.new("bar").to_html assert_equal "

!s petst

", c.new("tstep *s*!").to_html end def test_parsing_overrides c = ClothesLine.parse("BlueCloth ClothReverse", Override) assert_equal "

bar

", c.new("bar").to_html assert_equal "

tsteps

", c.new("tstep*s*").to_html c = ClothesLine.parse("ClothReverse RedCloth", Override) assert_equal "

bar

", c.new("bar").to_html assert_equal "

tstep s!

", c.new("tstep *s*!").to_html assert_equal "ClothReverse RedCloth", c.to_clothesline end end