Esempio n. 1
0
	def testAutoSrip(self) -> None:
		template = Template("""
	{% if value %}
  hello
			{% end %}""")
		result = template.render({"value": True})
		self.assertEqual("\n  hello\n", result)
Esempio n. 2
0
	def testSimpleCondition(self) -> None:
		template = Template("{% if value %}hello{% end %}")

		result = template.render({"value": True})
		self.assertEqual("hello", result)

		result = template.render({"value": False})
		self.assertEqual("", result)
Esempio n. 3
0
	def testInCondition(self) -> None:
		template = Template("{% if value in [10, 23] %}hello{% end %}")

		result = template.render({"value": 1})
		self.assertEqual("", result)

		result = template.render({"value": 23})
		self.assertEqual("hello", result)
Esempio n. 4
0
	def testEqualStringCondition(self) -> None:
		template = Template("{% if value == \"yes\" %}hello{% end %}")

		result = template.render({"value": "no"})
		self.assertEqual("", result)

		result = template.render({"value": "yes"})
		self.assertEqual("hello", result)
Esempio n. 5
0
	def testEqualNumberCondition(self) -> None:
		template = Template("{% if value == 2 %}hello{% end %}")

		result = template.render({"value": 12})
		self.assertEqual("", result)

		result = template.render({"value": 2})
		self.assertEqual("hello", result)
Esempio n. 6
0
	def testNestedCondition(self) -> None:
		template = Template("a{% if value1 %}b{% if value2 %}c{% end %}{% end %}d")

		result = template.render({"value1": True, "value2": True})
		self.assertEqual("abcd", result)

		result = template.render({"value1": False, "value2": True})
		self.assertEqual("ad", result)
Esempio n. 7
0
	def testSripElseIfCondition(self) -> None:
		template = Template("{% if value1 -%} a {%- elif value2 -%} b {%- else -%} c {%- end %}")
		result = template.render({"value1": True, "value2": False})
		self.assertEqual("a", result)
		result = template.render({"value1": False, "value2": True})
		self.assertEqual("b", result)
		result = template.render({"value1": False, "value2": False})
		self.assertEqual("c", result)
Esempio n. 8
0
 def testPipeSubsitution(self) -> None:
     template = Template("{{str | lowerCase | capitalize }}")
     result = template.render({
         "str": "ThIs IS SOMEhting MesSy",
         "lowerCase": lambda x: x.lower(),
         "capitalize": lambda x: x.capitalize()
     })
     self.assertEqual("This is somehting messy", result)
Esempio n. 9
0
 def testForControlNested(self) -> None:
     template = Template(
         "{% for group in message %}{% for letter in group %}{{letter}}{%end%} {%end%}"
     )
     result = template.render({
         "message": [["H", "e", "l", "l", "o"], ["W", "o", "r", "l", "d"]]
     })
     self.assertEqual("Hello World ", result)
Esempio n. 10
0
	def testElseNestedComplexCondition(self) -> None:

		template = Template(
			"{% if value %}hello{% if not value %}never{% end %}{% else %}{% if not value %}good{% else %}never{% end %}bye{% end %}"
		)

		result = template.render({"value": True})
		self.assertEqual("hello", result)

		result = template.render({"value": False})
		self.assertEqual("goodbye", result)
Esempio n. 11
0
	def testElseNestedCondition(self) -> None:
		template = Template("{% if value1 %}0{% if value2 %}1{% else %}2{% end %}{% else %}3{% end %}")

		result = template.render({"value1": True, "value2": True})
		self.assertEqual("01", result)

		result = template.render({"value1": False, "value2": True})
		self.assertEqual("3", result)

		result = template.render({"value1": True, "value2": False})
		self.assertEqual("02", result)
Esempio n. 12
0
	def testElIfCondition(self) -> None:
		template = Template("{% if value1 %}hello{% elif value2 %}goodbye{% else %}what?!{% end %}")

		result = template.render({"value1": True})
		self.assertEqual("hello", result)

		result = template.render({"value1": False, "value2": True})
		self.assertEqual("goodbye", result)

		result = template.render({"value1": False, "value2": False})
		self.assertEqual("what?!", result)
Esempio n. 13
0
 def testDeepSubsitution(self) -> None:
     template = Template("Hello {{a.b.c.d.world}}")
     result = template.render(
         {"a": {
             "b": {
                 "c": {
                     "d": {
                         "world": "World"
                     }
                 }
             }
         }})
     self.assertEqual("Hello World", result)
Esempio n. 14
0
 def testMacroWithSubstitutions(self) -> None:
     template = Template(
         "{% macro hello(data) %}Vector<{{data.type}}, {{data.size}}>{% end %}{{ hello(small) }}\n{{ hello(large) }}"
     )
     result = template.render({
         "small": {
             "type": "int",
             "size": 12
         },
         "large": {
             "type": "float",
             "size": 34
         }
     })
     self.assertEqual("Vector<int, 12>\nVector<float, 34>", result)
Esempio n. 15
0
def formatCc(bdl: Object) -> str:

    template = Template.fromPath(Path(__file__).parent / "template/file.h.btl",
                                 indent=True)
    output = template.render(bdl.tree, Transform())

    return output
Esempio n. 16
0
def compositionCc(composition: Composition) -> str:

    template = Template.fromPath(Path(__file__).parent /
                                 "template/composition.cc.btl",
                                 indent=True)
    output = template.render(composition, Transform(composition))

    return output
Esempio n. 17
0
    def testForStrip(self) -> None:
        template = Template(
            "{% for char in sequence -%}   {{char}}        \t {%- end %}")
        result = template.render({"sequence": ["a", "b", "c", "d"]})
        self.assertEqual("abcd", result)

        template = Template(
            "{% for char in sequence %}   {{char}}        \t {%- end %}")
        result = template.render({"sequence": ["a", "b", "c", "d"]})
        self.assertEqual("   a   b   c   d", result)

        template = Template(
            "{% for char in sequence -%}   {{char}}\t{% end %}")
        result = template.render({"sequence": ["a", "b", "c", "d"]})
        self.assertEqual("a\tb\tc\td\t", result)
Esempio n. 18
0
def formatBdl(bdl: Object) -> str:

    template = Template.fromPath(Path(__file__).parent /
                                 "template/file.bdl.btl",
                                 indent=True)
    output = template.render(
        bdl.tree, {
            "typeToStr": _typeToStr,
            "namespaceToStr": _namespaceToStr,
            "inlineComment": _inlineComment,
            "normalComment": _normalComment,
            "inheritanceToStr": _inheritanceToStr
        })

    return output
Esempio n. 19
0
    def testForStripNested(self) -> None:
        template = Template(
            "{% for a in sequence -%}  {% for b in sequence -%} {{a}}{{b}}       {%- end %} {%- end %}"
        )
        result = template.render({"sequence": ["a", "b"]})
        self.assertEqual("aaabbabb", result)

        template = Template(
            "{% for a in sequence -%} {% for b in sequence %} {{a}}{{b}}       {%- end %} {%- end %}"
        )
        result = template.render({"sequence": ["a", "b"]})
        self.assertEqual(" aa ab ba bb", result)
Esempio n. 20
0
 def testSimpleComment(self) -> None:
     template = Template("a {# hello #} b")
     result = template.render({})
     self.assertEqual("a  b", result)
Esempio n. 21
0
 def testAutoStripComment(self) -> None:
     template = Template("{# Comment #}  \n here ")
     result = template.render({})
     self.assertEqual(" here ", result)
Esempio n. 22
0
 def testEmptyComment(self) -> None:
     template = Template("em{# #}pty")
     result = template.render({})
     self.assertEqual("empty", result)
Esempio n. 23
0
 def testIndent(self) -> None:
     template = Template("    {{ a }}", indent=True)
     result = template.render({"a": "0\n1\n2"})
     self.assertEqual("    0\n    1\n    2", result)
Esempio n. 24
0
 def testStripSpecialChars(self) -> None:
     template = Template(" {  12 }  }}   \n     a ")
     result = template.render({"a": "0"})
     self.assertEqual(" {  12 }  }}   \n     a ", result)
Esempio n. 25
0
 def testStripVarious(self) -> None:
     template = Template("{{a -}} | {{- a}} | {{a}} | {{- a -}} |")
     result = template.render({"a": "0"})
     self.assertEqual("0|0 | 0 |0|", result)
Esempio n. 26
0
 def testStripRight(self) -> None:
     template = Template("{{world -}} ld")
     result = template.render({"world": "Wor"})
     self.assertEqual("World", result)
Esempio n. 27
0
 def testStripLeft(self) -> None:
     template = Template("Hel {{-world}}")
     result = template.render({"world": "lo"})
     self.assertEqual("Hello", result)
Esempio n. 28
0
 def testNoStrip(self) -> None:
     template = Template("   Hello {{world}}    I am   happy ")
     result = template.render({"world": "World"})
     self.assertEqual("   Hello World    I am   happy ", result)
Esempio n. 29
0
 def testSimpleSubsitution(self) -> None:
     template = Template("Hello {{world}}")
     result = template.render({"world": "World"})
     self.assertEqual("Hello World", result)
Esempio n. 30
0
 def testCallableNestedSubsitution(self) -> None:
     template = Template("Hello {{a.b}}")
     result = template.render({"a": lambda: {"b": lambda: "Me!"}})
     self.assertEqual("Hello Me!", result)