# Path: flatland/schema/scalars.py
# class String(Scalar):
#     """A regular old Unicode string."""
# 
#     strip = True
#     """If true, strip leading and trailing whitespace during conversion."""
# 
#     def adapt(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return None
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     def serialize(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``u'' if *value* is ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return u''
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     @property
#     def is_empty(self):
#         """True if the String is missing or has no value."""
#         return True if (not self.value and self.u == u'') else False
# 
# Path: flatland/out/generic.py
# class Markup(unicode):
#     """A unicode string of HTML markup that should not be escaped in output."""
#     __slots__ = ()
# 
#     # Not a full featured implementation.
# 
#     def __html__(self):
#         return self
# 
# Path: tests/markup/_util.py
# def render_genshi_06(markup, language, schema, wrap=True, **context):
#     if wrap:
#         markup = _wrap_with_xmlns(markup, language)
#     return _render_genshi_06(markup, language, schema, **context)
# 
# def need(capability):
#     def decorator(fn):
#         @wraps(fn)
#         def decorated(*args, **kw):
#             if not have[capability]:
#                 raise SkipTest
#             return fn(*args, **kw)
#         return decorated
#     return decorator


from flatland import String
from flatland.out.generic import Markup
from genshi.template.base import TemplateSyntaxError
from tests._util import assert_raises
from tests.markup._util import render_genshi_06 as render, need
    from flatland.out import genshi_06


def test_attribute_removal():
    markup = """\
<input type="checkbox" form:bind="form" value="xyzzy" checked="checked" />
"""
    expected = """\
<input type="checkbox" value="xyzzy" name="element" />"""

    rendered = render(markup, 'xhtml', schema)
    assert rendered == expected


def test_stream_preserved():
    markup = """\
<py:def function="stream_fn()"><b py:if="1">lumpy.</b></py:def>
<py:def function="flattenable_fn()"><py:if test="1">flat.</py:if></py:def>
<button form:bind="form">
  <em>wow!</em> ${1 + 1}
</button>
<button form:bind="form">${stream_fn()}</button>
<button form:bind="form">${flattenable_fn()}</button>
"""
    expected = """\
<button name="element" value="">
  <em>wow!</em> 2
</button>
<button name="element" value=""><b>lumpy.</b></button>
<button name="element" value="">flat.</button>"""


# Path: flatland/schema/scalars.py
# class String(Scalar):
#     """A regular old Unicode string."""
# 
#     strip = True
#     """If true, strip leading and trailing whitespace during conversion."""
# 
#     def adapt(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return None
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     def serialize(self, value):
#         """Return a Unicode representation.
# 
#         :returns: a ``unicode`` value or ``u'' if *value* is ``None``
# 
#         If :attr:`strip` is true, leading and trailing whitespace will be
#         removed.
# 
#         """
#         if value is None:
#             return u''
#         elif self.strip:
#             return unicode(value).strip()
#         else:
#             return unicode(value)
# 
#     @property
#     def is_empty(self):
#         """True if the String is missing or has no value."""
#         return True if (not self.value and self.u == u'') else False
# 
# Path: flatland/out/generic.py
# class Markup(unicode):
#     """A unicode string of HTML markup that should not be escaped in output."""
#     __slots__ = ()
# 
#     # Not a full featured implementation.
# 
#     def __html__(self):
#         return self
# 
# Path: tests/markup/_util.py
# def render_genshi_06(markup, language, schema, wrap=True, **context):
#     if wrap:
#         markup = _wrap_with_xmlns(markup, language)
#     return _render_genshi_06(markup, language, schema, **context)
# 
# def need(capability):
#     def decorator(fn):
#         @wraps(fn)
#         def decorated(*args, **kw):
#             if not have[capability]:
#                 raise SkipTest
#             return fn(*args, **kw)
#         return decorated
#     return decorator


# Path: tests/markup/test_genshi_06.py
from flatland import String
from flatland.out.generic import Markup
from genshi.template.base import TemplateSyntaxError
from tests._util import assert_raises
from tests.markup._util import render_genshi_06 as render, need
    from flatland.out import genshi_06



def test_attribute_removal():
    markup = """\
<input type="checkbox" form:bind="form" value="xyzzy" checked="checked" />
"""
    expected = """\
<input type="checkbox" value="xyzzy" name="element" />"""

    rendered = render(markup, 'xhtml', schema)
    assert rendered == expected


def test_stream_preserved():
    markup = """\
<py:def function="stream_fn()"><b py:if="1">lumpy.</b></py:def>
<py:def function="flattenable_fn()"><py:if test="1">flat.</py:if></py:def>
<button form:bind="form">
  <em>wow!</em> ${1 + 1}
</button>
<button form:bind="form">${stream_fn()}</button>
<button form:bind="form">${flattenable_fn()}</button>
"""
    expected = """\
<button name="element" value="">
  <em>wow!</em> 2
</button>
<button name="element" value=""><b>lumpy.</b></button>
<button name="element" value="">flat.</button>"""


    rendered = render(markup, 'xhtml', schema)