#!/usr/bin/env python

import unittest
import re

from genshi.template import MarkupTemplate

tmpl_data="""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/">

  <py:match path="div[@id='content']/h1" once="True">
      <h1>Create New Foo</h1>
  </py:match>
    
  <py:match path="body" once="true" buffer="false"><body>
    ${select('*|text()')}
  </body></py:match>

  <py:match path="body" once="true" buffer="false"><body>
    <div id="main">
      ${select('*|text()')}
    </div>
  </body></py:match>

  <body>
    <div id="content" class="ticket">
      <h1>Create New Ticket</h1>
    </div>
  </body>
</html>"""


class TestNoMatchWithSingleSlash(unittest.TestCase):
    def test_no_match(self):
        tmpl = MarkupTemplate(tmpl_data)
        output = tmpl.generate().render('xhtml', doctype='xhtml')
        print output
        self.assertTrue("Create New Foo" in output)

    def test_match_with_double_slash(self):
        # Not sure if this is the wanted behavior
        tmpl = MarkupTemplate(tmpl_data.replace("]/h1", "]//h1"))
        output = tmpl.generate().render('xhtml', doctype='xhtml')
        self.assertTrue("Create New Foo" in output)



