require 'helper'

class TestParsingAndOutput < Test::Unit::TestCase
  subset = BBCoder::Subset.create { }
  
  should "return text if it has no tags" do
    assert_equal "this is a test", subset.render("this is a test")
  end
  
  should "return a strong tag containing the right text for a bold tag" do
    assert_equal "<strong>this is a test</strong>", subset.render("[b]this is a test[/b]")
  end
  
  should "return a strong tag containing the right text with the right text before" do
    assert_equal "abc<strong>this is a test</strong>", subset.render("abc[b]this is a test[/b]")
  end
  
  should "return a strong tag containing the right text with the right text before (with space)" do
    assert_equal "abc <strong>this is a test</strong>", subset.render("abc [b]this is a test[/b]")
  end
  
  should "return a strong tag containing the right text with some text after it" do
    assert_equal "<strong>this is a test</strong>abc", subset.render("[b]this is a test[/b]abc")
  end
  
  should "return a strong tag containing the right text with some text after it (with space)" do
    assert_equal "<strong>this is a test</strong> abc", subset.render("[b]this is a test[/b] abc")
  end
  
  should "return a strong tag containing a italic tag with 'is' inside it, right text etc" do
    assert_equal "<strong>this <em>is</em> a test</strong>", subset.render("[b]this [i]is[/i] a test[/b]")
  end
  
  should "return a font color tag with the correct color" do
    assert_equal "<span style='color: #fff;'>this is a test</span>", subset.render("[color=#fff]this is a test[/color]")
  end
  
  should "return the contents of tags that don't exist (fail silently)" do
    assert_equal "this is abcdefghi test", subset.render("this is [ttt]abcde[g]f[/g]ghi[/ttt] test")
  end
  
  should "remove html tags from input" do
    assert_equal "this is a test", subset.render("this is <b>a</b> test")
  end
  
  should "remove script tags and their content" do
    assert_equal "this is a  test", subset.render("this is a <script type='text/javascript'>alert('hello');</script> test")
  end
end
