Exemplo n.º 1
0
    def test_2(self):
        h="""<template>\n     \n   \t     \n     <div>XXX</div> \t \n    </template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")

        h="""<template type="xxx">\n     \n   \t     \n     <div>XXX</div> \t \n    </template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")

        h="""<template> gsfdsgfd   <div>XXX</div>     gfdsgfd    </template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"gsfdsgfd   <div>XXX</div>     gfdsgfd")    # acceptable, but not good
        self.assertEqual(r.rootTag,"div")    # acceptable, but not good
Exemplo n.º 2
0
    def test_1(self):
        h="""<template><div>XXX</div></template>"""
        r=vbuild.VueParser(h)
        self.assertTrue(isinstance(r.html,vbuild.Content))
        self.assertEqual(repr(r.html),"<div>XXX</div>")
        self.assertEqual(r.script,None)
        self.assertEqual(r.styles,[])
        self.assertEqual(r.scopedStyles,[])
        self.assertEqual(r.rootTag,"div")

        h="""<template type="xxx"><div>XXX</div></template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")
Exemplo n.º 3
0
def test_1():
    h = """<template><div>XXX</div></template>"""
    r = vbuild.VueParser(h)
    assert isinstance(r.html, vbuild.Content)
    assert repr(r.html) == "<div>XXX</div>"
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []
    assert r.rootTag == "div"

    h = """<template type="xxx"><div>XXX</div></template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"
Exemplo n.º 4
0
    def test_bad_not_openclose(self):
        h="""<template type="xxx"><div>XXX</div>"""
        r=vbuild.VueParser(h)
        self.assertEqual(r.html,None)
        self.assertEqual(r.script,None)
        self.assertEqual(r.styles,[])
        self.assertEqual(r.scopedStyles,[])

        h="""<div>XXX</div></template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(r.html,None)
        self.assertEqual(r.script,None)
        self.assertEqual(r.styles,[])
        self.assertEqual(r.scopedStyles,[])
Exemplo n.º 5
0
def test_2():
    h = """<template>\n     \n   \t     \n     <div>XXX</div> \t \n    </template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"

    h = """<template type="xxx">\n     \n   \t     \n     <div>XXX</div> \t \n    </template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"

    h = """<template> gsfdsgfd   <div>XXX</div>     gfdsgfd    </template>"""
    r = vbuild.VueParser(h)
    assert (repr(r.html) == "gsfdsgfd   <div>XXX</div>     gfdsgfd"
            )  # acceptable, but not good
    assert r.rootTag == "div"  # acceptable, but not good
Exemplo n.º 6
0
def test_bad_not_openclose():
    h = """<template type="xxx"><div>XXX</div>"""
    r = vbuild.VueParser(h)
    assert r.html == None
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []

    h = """<div>XXX</div></template>"""
    r = vbuild.VueParser(h)
    assert r.html == None
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []
Exemplo n.º 7
0
def test_bad_not_at_root():
    h = """<a><template type="xxx"><div>XXX</div></template></a>"""
    r = vbuild.VueParser(h)
    assert r.html == None
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []
Exemplo n.º 8
0
 def test_empty(self):
     h="""<template></template>"""
     r=vbuild.VueParser(h)
     self.assertEqual(repr(r.html),"")
     self.assertEqual(r.script,None)
     self.assertEqual(r.styles,[])
     self.assertEqual(r.scopedStyles,[])
     self.assertTrue(r.rootTag is None)
Exemplo n.º 9
0
def test_malformed():
    h = """<template><div><br>XXX</div></template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div><br>XXX</div>"
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []
    assert r.rootTag == "div"
Exemplo n.º 10
0
def test_empty():
    h = """<template></template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == ""
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []
    assert r.rootTag is None
Exemplo n.º 11
0
 def test_malformed(self):
     h="""<template><div><br>XXX</div></template>"""
     r=vbuild.VueParser(h)
     self.assertEqual(repr(r.html),"<div><br>XXX</div>")
     self.assertEqual(r.script,None)
     self.assertEqual(r.styles,[])
     self.assertEqual(r.scopedStyles,[])
     self.assertEqual(r.rootTag,"div")
Exemplo n.º 12
0
    def __init__(self, filename, content, component):
        """ Create a VBuild class, by providing a :
                filename: which will be used to name the component, and create the namespace for the template
                content: the string buffer which contains the sfc/vue component

                Overridden to provide change some behaviour. (Like, not using a full path as unique....)

                DOES NOT SUPPORT PYTHON MODULES
        """
        if not filename:
            raise vbuild.VBuildException("Component %s should be named" %
                                         filename)

        self.component = component

        if type(content) != type(filename):  # only py2, transform
            if type(content) == vbuild.unicode:  # filename to the same type
                filename = filename.decode("utf8")  # of content to avoid
            else:  # troubles with implicit
                filename = filename.encode("utf8")  # ascii conversions (regex)

        name = os.path.splitext(os.path.basename(filename))[0]

        unique = component.name + "-" + name

        tplId = "tpl-" + unique
        dataId = "data-" + unique

        vp = vbuild.VueParser(content, filename)
        if vp.html is None:
            raise vbuild.VBuildException(
                "Component %s doesn't have a template" % filename)
        else:
            html = re.sub(r"^<([\w-]+)", r"<\1 %s" % dataId, vp.html.value)

            self.tags = [name]
            self._html = [(tplId, html)]

            self._styles = []
            for style in vp.styles:
                self._styles.append(("", style, filename))
            for style in vp.scopedStyles:
                self._styles.append(("*[%s]" % dataId, style, filename))

            # and set self._script !
            try:
                self._script = [
                    _VueJs(name, tplId, vp.script and vp.script.value)
                ]
            except Exception as e:
                raise vbuild.VBuildException(
                    "JS Component %s contains a bad script" % filename)
Exemplo n.º 13
0
    def test_full(self):
        h="""<template><div>XXX</div></template><style lang="sass">style</style><script lang="python">script</script>"""
        r=vbuild.VueParser(h)
        self.assertTrue(isinstance(r.html,vbuild.Content))
        self.assertTrue(isinstance(r.script,vbuild.Content))
        self.assertEqual(type(r.styles),list)
        self.assertTrue(isinstance(r.styles[0],vbuild.Content))

        self.assertEqual(repr(r.script),"script")
        self.assertEqual(repr(r.styles[0]),"style")
        self.assertEqual(r.script.type,"python")
        self.assertEqual(r.styles[0].type,"sass")

        self.assertEqual(r.html.type,None)  # not used for html (now)

        h="""<template><div>XXX</div></template><style scoped>style</style><script>script</script>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.script),"script")
        self.assertEqual(repr(r.scopedStyles[0]),"style")
        self.assertEqual(r.script.type,None)
        self.assertEqual(r.scopedStyles[0].type,None)
        self.assertEqual(r.html.type,None)  # not used for html (now)
Exemplo n.º 14
0
def test_full():
    h = """<template><div>XXX</div></template><style lang="sass">style</style><script lang="python">script</script>"""
    r = vbuild.VueParser(h)
    assert isinstance(r.html, vbuild.Content)
    assert isinstance(r.script, vbuild.Content)
    assert type(r.styles) == list
    assert isinstance(r.styles[0], vbuild.Content)

    assert repr(r.script) == "script"
    assert repr(r.styles[0]) == "style"
    assert r.script.type == "python"
    assert r.styles[0].type == "sass"

    assert r.html.type == None  # not used for html (now)

    h = """<template><div>XXX</div></template><style scoped>style</style><script>script</script>"""
    r = vbuild.VueParser(h)
    assert repr(r.script) == "script"
    assert repr(r.scopedStyles[0]) == "style"
    assert r.script.type == None
    assert r.scopedStyles[0].type == None
    assert r.html.type == None  # not used for html (now)
Exemplo n.º 15
0
def test_3():
    h = """<template type="xxx">
        <div>XXX</div></template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"

    h = """<template type="xxx"><div>XXX</div>
    </template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"

    h = """<template type="xxx">
        <div>XXX</div>
    </template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"

    h = """<template type="xxx">\r\n<div>XXX</div>\r\n</template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"
    h = """<template type="xxx">\n<div>XXX</div>\n</template>"""
    r = vbuild.VueParser(h)
    assert repr(r.html) == "<div>XXX</div>"
Exemplo n.º 16
0
    def test_3(self):
        h="""<template type="xxx">
            <div>XXX</div></template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")

        h="""<template type="xxx"><div>XXX</div>
        </template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")

        h="""<template type="xxx">
            <div>XXX</div>
        </template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")

        h="""<template type="xxx">\r\n<div>XXX</div>\r\n</template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")
        h="""<template type="xxx">\n<div>XXX</div>\n</template>"""
        r=vbuild.VueParser(h)
        self.assertEqual(repr(r.html),"<div>XXX</div>")
Exemplo n.º 17
0
def test_more_than_one_template():
    h = """<template><div>jo</div></template><template><div>jo</div></template>"""
    with pytest.raises(vbuild.VBuildException):
        vbuild.VueParser(h)  # Component  contains more than one template
Exemplo n.º 18
0
 def test_bad_no_template(self):
     h="""<templite type="xxx"> <div>XXX</div> <div>XXX</div> </templite>"""
     r=vbuild.VueParser(h)
     self.assertEqual(r.html,None)
Exemplo n.º 19
0
 def test_bad_script_bad(self):
     h="""<template> <div>XXX</div></template><script> gdsf gfds """
     r=vbuild.VueParser(h)
     self.assertEqual(r.script,None)
Exemplo n.º 20
0
 def test_bad_style_bad(self):
     h="""<template> <div>XXX</div></template><style> gdsf gfds """
     r=vbuild.VueParser(h)
     self.assertEqual(r.script,None)
     self.assertEqual(r.styles,[])
     self.assertEqual(r.scopedStyles,[])
Exemplo n.º 21
0
def test_str():
    r = vbuild.VueParser(ts)
    assert type(ts) == type(r.html.value)
Exemplo n.º 22
0
def test_bad_style_bad():
    h = """<template> <div>XXX</div></template><style> gdsf gfds """
    r = vbuild.VueParser(h)
    assert r.script == None
    assert r.styles == []
    assert r.scopedStyles == []
Exemplo n.º 23
0
def test_unicode():
    r = vbuild.VueParser(tu)
    assert type(tu) == type(r.html.value)
Exemplo n.º 24
0
def test_bad_script_bad():
    h = """<template> <div>XXX</div></template><script> gdsf gfds """
    r = vbuild.VueParser(h)
    assert r.script == None
Exemplo n.º 25
0
def test_bad_no_template():
    h = """<templite type="xxx"> <div>XXX</div> <div>XXX</div> </templite>"""
    r = vbuild.VueParser(h)
    assert r.html == None
Exemplo n.º 26
0
def test_bad_more_than_one_root():
    h = """<template type="xxx"> <div>XXX</div> <div>XXX</div> </template>"""
    with pytest.raises(vbuild.VBuildException):
        vbuild.VueParser(
            h)  # Component mycomp.vue can have only one top level tag
Exemplo n.º 27
0
 def test_unicode(self):
     r=vbuild.VueParser(tu)
     self.assertEqual( type(tu) , type(r.html.value) )
Exemplo n.º 28
0
 def test_str(self):
     r=vbuild.VueParser(ts)
     self.assertEqual( type(ts) , type(r.html.value) )