Files
Sheerka-Old/tests/out/test_DeveloperVisitor.py
T

41 lines
1.8 KiB
Python

from core.sheerka.services.SheerkaDebugManager import NullDebugLogger
from core.sheerka.services.SheerkaOut import SheerkaOut
from core.sheerka.services.SheerkaRuleManager import FormatAstList, FormatAstVariable
from out.DeveloperVisitor import DeveloperVisitor
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
class TestDeveloperVisitor(TestUsingMemoryBasedSheerka):
def test_i_can_develop_list(self):
sheerka, context = self.init_concepts()
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"a": ["a", "b", "c"]}
res = dev_visitor.visit(context, FormatAstList("a"), bag)
assert res == FormatAstList(variable="a", items=[
FormatAstVariable(name="__item", index=0, value="a"),
FormatAstVariable(name="__item", index=1, value="b"),
FormatAstVariable(name="__item", index=2, value="c"),
])
def test_i_can_develop_list_of_list(self):
sheerka, context = self.init_concepts()
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"a": [["a1", "a2"], ["b1"]]}
res = dev_visitor.visit(context, FormatAstList("a"), bag)
assert res == FormatAstList(variable="a", items=[
FormatAstList(variable="__item", index=0, debug=True, prefix='[', suffix=']', items=[
FormatAstVariable(name="__item", index=0, debug=True, value="a1"),
FormatAstVariable(name="__item", index=1, debug=True, value="a2"),
]),
FormatAstList(variable="__item", index=1, debug=True, prefix='[', suffix=']', items=[
FormatAstVariable(name="__item", index=0, debug=True, value="b1"),
]),
])