# Path: djangocodemirror/templatetags/djangocodemirror_tags.py
# @register.simple_tag
# def codemirror_instance(config_name, varname, element_id, assets=True):
#     """
#     Return HTML to init a CodeMirror instance for an element.
# 
#     This will output the whole HTML needed to initialize a CodeMirror instance
#     with needed assets loading. Assets can be omitted with the ``assets``
#     option.
# 
#     Example:
#         ::
# 
#             {% load djangocodemirror_tags %}
#             {% codemirror_instance 'a-config-name' 'foo_codemirror' 'foo' %}
# 
#     Arguments:
#         config_name (string): A registred config name.
#         varname (string): A Javascript variable name.
#         element_id (string): An HTML element identifier (without
#             leading ``#``) to attach to a CodeMirror instance.
# 
#     Keyword Arguments:
#         assets (Bool): Adds needed assets before the HTML if ``True``, else
#             only CodeMirror instance will be outputed. Default value is
#             ``True``.
# 
#     Returns:
#         string: HTML.
#     """
#     output = io.StringIO()
# 
#     manifesto = CodemirrorAssetTagRender()
#     manifesto.register(config_name)
# 
#     if assets:
#         output.write(manifesto.css_html())
#         output.write(manifesto.js_html())
# 
#     html = manifesto.codemirror_html(config_name, varname, element_id)
#     output.write(html)
# 
#     content = output.getvalue()
#     output.close()
# 
#     return mark_safe(content)
# 
# Path: sandbox/forms.py
# class SampleForm(forms.Form):
#     """
#     Just a very basic form for tests
#     """
#     foo = CodeMirrorField(label="Foo",
#                           required=True,
#                           config_name="basic",
#                           initial='Hello World!')


import pytest
from djangocodemirror.templatetags.djangocodemirror_tags import (
    codemirror_instance,
)
from sandbox.forms import SampleForm
# -*- coding: utf-8 -*-
"""
Tests against template tags for Codemirror config
"""




def test_codemirror_instance_without_assets():
    html = codemirror_instance('basic', 'foo_codemirror', 'id_foo', assets=False)

    output = ("""<script>var foo_codemirror = CodeMirror.fromTextArea("""
              """document.getElementById("id_foo"),"""
              """{"mode": "rst"});"""
              """</script>""")

    assert html == output


def test_codemirror_instance_varname_dash():

# Path: djangocodemirror/templatetags/djangocodemirror_tags.py
# @register.simple_tag
# def codemirror_instance(config_name, varname, element_id, assets=True):
#     """
#     Return HTML to init a CodeMirror instance for an element.
# 
#     This will output the whole HTML needed to initialize a CodeMirror instance
#     with needed assets loading. Assets can be omitted with the ``assets``
#     option.
# 
#     Example:
#         ::
# 
#             {% load djangocodemirror_tags %}
#             {% codemirror_instance 'a-config-name' 'foo_codemirror' 'foo' %}
# 
#     Arguments:
#         config_name (string): A registred config name.
#         varname (string): A Javascript variable name.
#         element_id (string): An HTML element identifier (without
#             leading ``#``) to attach to a CodeMirror instance.
# 
#     Keyword Arguments:
#         assets (Bool): Adds needed assets before the HTML if ``True``, else
#             only CodeMirror instance will be outputed. Default value is
#             ``True``.
# 
#     Returns:
#         string: HTML.
#     """
#     output = io.StringIO()
# 
#     manifesto = CodemirrorAssetTagRender()
#     manifesto.register(config_name)
# 
#     if assets:
#         output.write(manifesto.css_html())
#         output.write(manifesto.js_html())
# 
#     html = manifesto.codemirror_html(config_name, varname, element_id)
#     output.write(html)
# 
#     content = output.getvalue()
#     output.close()
# 
#     return mark_safe(content)
# 
# Path: sandbox/forms.py
# class SampleForm(forms.Form):
#     """
#     Just a very basic form for tests
#     """
#     foo = CodeMirrorField(label="Foo",
#                           required=True,
#                           config_name="basic",
#                           initial='Hello World!')


# Path: tests/003_templatetags/test_004_codemirror_instance.py
import pytest
from djangocodemirror.templatetags.djangocodemirror_tags import (
    codemirror_instance,
)
from sandbox.forms import SampleForm

# -*- coding: utf-8 -*-
"""
Tests against template tags for Codemirror config
"""




def test_codemirror_instance_without_assets():
    html = codemirror_instance('basic', 'foo_codemirror', 'id_foo', assets=False)

    output = ("""<script>var foo_codemirror = CodeMirror.fromTextArea("""
              """document.getElementById("id_foo"),"""
              """{"mode": "rst"});"""
              """</script>""")

    assert html == output


def test_codemirror_instance_varname_dash():

    html = codemirror_instance('basic', 'foo_codemirror-0', 'id_foo', assets=False)