#!/usr/bin/env ruby
# $Id: tc_formatter.rb,v 1.32 2004/05/12 18:23:34 eto Exp $
# Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL2.

require "test_common"

class TC_HTMLFormatter < Test::Unit::TestCase
  include TestSession

  def test_formatter
    assert_equal("<h2>t</h2>", "*t".w.html) # test_header
    assert_equal("<h3>t</h3>", "**t".w.html)
    assert_equal("<h2>t</h2>", "* t".w.html) # test_ignore_space
    assert_equal("<h2>t</h2>", "*t ".w.html)
    assert_equal("<h2>t</h2>", "* t ".w.html)
    assert_equal("<h3>t</h3>", "** t".w.html)
    assert_equal("<h3>t</h3>", "**t ".w.html)
    assert_equal("<h3>t</h3>", "** t ".w.html)
    assert_equal("<h2>'</h2>", "*'".w.html) # test_escape
    assert_equal("<h2>&lt;</h2>", "*<".w.html) # test_escape

    assert_equal("<dl><dt>t</dt>\n<dd>s</dd>\n</dl>", ":t:s".w.html) # test_block
    assert_equal("<dl><dt>t</dt>\n<dd />\n</dl>", ":t:".w.html)
    assert_equal("<dl><dt>t</dt>\n</dl>", ":t".w.html)
    assert_equal("<blockquote><p> t</p>\n</blockquote>", "> t".w.html)
    assert_equal("<blockquote><p>t</p>\n</blockquote>", ">t".w.html)
    assert_equal("<div class='table'><table><tr><td>t</td>\n<td>s</td>\n</tr>\n</table></div>", "|t|s|".w.html)

    # test_pre
    assert_equal("<pre>t\n</pre>", " t".w.html)
    assert_equal("<pre>s\nt\n</pre>", " s\n t".w.html)

    # test_name()
    #assert_equal("<h2><span class='date'/><span class='title'><a name='l0'> </a> t</span></h2>", "* t".w.html(@site))

    # test_lines
    assert_equal("<ul><li> t1</li>\n<li> t2</li>\n</ul>", "- t1\n- t2".w.html)
    assert_equal("<p>t1</p>\n<ul><li> t2</li>\n</ul>", "t1\n- t2".w.html)

    # test_inline
    assert_equal("<em>t</em>", "''t''".w.html_p)
    assert_equal("<strong>t</strong>", "'''t'''".w.html_p)

    # test_link
    assert_equal("<p>t</p>", "t".w.html)
#    page = @site["0"]
    page = @site["FrontPage"]
    page.store("*title")
    assert_equal("<a href='FrontPage.html'>FrontPage</a>", "[[FrontPage]]".w.html_p)
    assert_equal("<a href='FrontPage.html'>FrontPage</a>", "[[FrontPage]]".w.html_p(@site))
    page = @site.create("t")
    page.store("t2")
    assert_equal("<a href='t.html'>t</a>", "[[t]]".w.html_p)
    assert_equal("<a href='FrontPage.html'>t</a>", "[[t|FrontPage]]".w.html_p)
    assert_equal("<a href='t.html'>s</a>", "[[s|t]]".w.html_p)
    page = @site.create("1")
    page.store("*あ")
    assert_equal("<a href='1.html'>1</a>", "[[1]]".w.html_p)
    assert_equal("<a href='1.html'>あ</a>", "[[1]]".w.html_p(@site))

    # test_find_title
    assert_equal("<a href='1.html'>あ</a>", "[[あ]]".w.html_p(@site))

    # test_newpage()
    assert_equal("<span class='new'>test</span><a href='_new.html?t=test;f=TestPage' class='new'>?</a>", "[[test]]".w.html_p(@site))
    assert_equal("<span class='new'>い</span><a href='_new.html?t=%82%A2;f=TestPage' class='new'>?</a>", "[[い]]".w.html_p(@site))

    # test_external_link
    assert_equal("<a href='http://example.com/'>http://example.com/</a>", "[[http://example.com/]]".w.html_p)
    assert_equal("<a href='http://example.com/'>http://example.com/</a>", "http://example.com/".w.html_p)
    assert_equal("<a href='http://example.com/'>t</a>", "[[t|http://example.com/]]".w.html_p)

    # test_qwik_text
    assert_equal("<hr />", "====".w.html)
    assert_equal("<ul><li> t</li>\n</ul>", "- t".w.html)
    assert_equal("<ul><li> s</li>\n<ul><li> t</li>\n</ul>\n</ul>", "- s\n-- t".w.html)
    assert_equal("<ol><li> t</li>\n</ol>", "+ t".w.html)

    # test_sjis
    assert_equal("<h2>あ</h2>", "* あ".w.html)
    assert_equal("<h3>あ</h3>", "** あ".w.html)
    assert_equal("<h3>あ</h3>", "** あ".w.html)
    assert_equal("<h3>漢字</h3>", "** 漢字".w.html)
    assert_equal("<h3>待</h3>", "** 待".w.html)

    # test_apos
    assert_equal("'", "'".w.html_p(@site))
    assert_equal("a", "a".w.html_p)
    assert_equal("&lt;", "<".w.html_p)
  end
end
