#!/usr/bin/env ruby
# $Id: tc_parser.rb,v 1.9 2004/04/20 13:05: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/wikitext'

class TC_Parser < Test::Unit::TestCase
  def test_parser()
    assert_equal([], "".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"t", :e=>:normal_text}, {:e=>:p_close}], "t".w.tokens)
    assert_equal([{:e=>:p_open}, {:e=>:bracketname, :href=>"0", :s=>"0"}, {:e=>:p_close}], "[[0]]".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"t", :href=>"t", :e=>:bracketname}, {:e=>:p_close}], "[[t]]".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"t", :href=>"0", :e=>:bracketname}, {:e=>:p_close}], "[[t|0]]".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"t", :href=>"s", :e=>:bracketname}, {:e=>:p_close}], "[[t|s]]".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"http://example.com/", :href=>"http://example.com/", :e=>:reference}, {:e=>:p_close}], "[[http://example.com/]]".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"t", :href=>"http://example.com/", :e=>:reference}, {:e=>:p_close}], "[[t|http://example.com/]]".w.tokens)
    assert_equal([{:e=>:p_open}, {:s=>"http://example.com/t.gif", :href=>"http://example.com/t.gif", :e=>:image}, {:e=>:p_close}], "[[http://example.com/t.gif]]".w.tokens)
    assert_equal([{:lv=>1, :e=>:heading1_open}, {:s=>" t", :e=>:normal_text}, {:lv=>1, :e=>:heading1_close}], "* t".w.tokens)
    assert_equal([{:e=>:table_open}, {:e=>:table_row_open}, {:e=>:table_data_open}, {:s=>"a", :e=>:normal_text}, {:e=>:table_data_close}, {:e=>:table_row_close}, {:e=>:table_close}], "|a".w.tokens)
    assert_equal([{:e=>:table_open}, {:e=>:table_row_open}, {:e=>:table_data_open}, {:s=>"a", :e=>:normal_text}, {:e=>:table_data_close}, {:e=>:table_data_open}, {:s=>"b", :e=>:normal_text}, {:e=>:table_data_close}, {:e=>:table_row_close}, {:e=>:table_close}], "|a|b".w.tokens)
    assert_equal([{:e=>:table_open}, {:e=>:table_row_open}, {:e=>:table_data_open}, {:s=>"a", :e=>:normal_text}, {:e=>:table_data_close}, {:e=>:table_row_close}, {:e=>:table_close}], ",a".w.tokens)
    assert_equal([{:e=>:table_open}, {:e=>:table_row_open}, {:e=>:table_data_open}, {:s=>"a", :e=>:normal_text}, {:e=>:table_data_close}, {:e=>:table_data_open}, {:s=>"b", :e=>:normal_text}, {:e=>:table_data_close}, {:e=>:table_row_close}, {:e=>:table_close}], ",a,b".w.tokens)
  end
end
