#!/usr/bin/env ruby
# $Id: tc_resolve.rb,v 1.1 2004/04/03 16:43:57 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.

$LOAD_PATH.unshift('../../lib')
$LOAD_PATH.unshift('../../compat')
require 'test/unit'
require 'qwik/resolve'

class TC_Resolve < Test::Unit::TestCase
  def setup()
    @config = Qwik::Config.new(true)
    @config.data_dir = './'
    @dir = './test/'.path
    @dir.rmtree if @dir.directory?
    @dir.rmdir  if @dir.directory?
    @dir.mkdir if !@dir.directory?
    @site = Qwik::Site.new(@config, 'test')
    options = Hash.new('')
    options['site'] = @site
    @site.plugin = Qwik::Plugin.new(@config, options)
  end

  def test_parser()
    s = 'a'
    assert_instance_of(Qwik::WikiText, s.w)
    assert_instance_of(String, s.w.html(@site))
    assert_equal("<p>a</p>", s.w.html(@site))
    assert_equal("a", s.w.html_p(@site))
  end

  def test_plugin()
    assert_equal("<br />", "{{br}}".w.html_p(@site))
    assert_equal("<em>t</em>", "''t''".w.html_p(@site))
#    assert_equal("", "''{{null}}''".w.html_p(@site))
    assert_equal("<em></em>", "''{{null}}''".w.html_p(@site))
    assert_equal("<strong>t</strong>", "'''t'''".w.html_p(@site))
#    assert_equal("", "'''{{null}}'''".w.html_p(@site))
    assert_equal("<strong></strong>", "'''{{null}}'''".w.html_p(@site))
    assert_equal("", "{{null}}".w.html_p(@site))
    assert_equal("nosuch plugin", "{{nosuchplugin}}".w.html_p(@site))

    # test_br
    assert_equal("t<br />s", "t~\ns\n".w.html_p(@site))
    assert_equal("\342\200\276", "~".sjistou8)
    assert_equal("t<br />s", "t~\ns\n".sjistou8.w.html_p(@site))
  end

  def test_message
    g = Qxhtml.new
    str = g.div{[
	g.h3{'h3'},
	g.dl{[
	    g.dt{'dt'},
	    g.dd{'dd'}
	  ]},
	g.p{'p'}
      ]}.to_s
    assert_equal('<div><h3>h3</h3><dl><dt>dt</dt><dd>dd</dd></dl><p>p</p></div>', str)
    str = "** h3\n:dt:dd\np".w.html(@site).delete("\n")
    assert_equal("<h3>h3</h3><dl><dt>dt</dt><dd>dd</dd></dl><p>p</p>", str)
  end

  def teardown()
    @dir.rmtree if @dir.directory?
    @dir.rmdir  if @dir.directory?
  end
end
