# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

module Qwik
  class CSS
    INHIBIT_PATTERN = %w(@i \\ javascript vbscript cookie eval expression behavior behaviour binding include-source)

    def initialize(body)
      @body = body
      @body.freeze
    end
    attr_reader :body

    def valid?
      INHIBIT_PATTERN.each {|c|
	if @body.include?(c)
	  return false
	end
      }
      true
    end

    def self.valid?(str)
      CSS.new(str).valid?
    end
  end
end

$debug = true if $0 == __FILE__
if $debug
  require "test/unit"

  class TC_CSS < Test::Unit::TestCase
    def assert(e, s)
      assert_equal(e, Qwik::CSS.valid?(s))
    end

    def test_css_valid
      assert(true,  "h2 { color: red }")
      assert(false, "@import\n}}")
      assert(false, "\\important")
      assert(true,  "")
      assert(true,  "text-align:center;")
      assert(true,  "ok@style")
      assert(true,  "ok.style")
      assert(false, "@i")
    end
  end
end
