Refactored Concept class for better separation of metadata, compiled and values
This commit is contained in:
@@ -59,19 +59,21 @@ def get_context():
|
||||
|
||||
def get_expected(concept, text=None):
|
||||
c = Concept(name=concept.name)
|
||||
c.cached_asts[ConceptParts.BODY] = DoNotResolve(text or concept.name)
|
||||
c.compiled[ConceptParts.BODY] = DoNotResolve(text or concept.name)
|
||||
c.init_key()
|
||||
return c
|
||||
|
||||
|
||||
def cbody(concept):
|
||||
"""cbody stands for compiled body"""
|
||||
return concept.cached_asts[ConceptParts.BODY]
|
||||
if not ConceptParts.BODY in concept.compiled:
|
||||
return None
|
||||
return concept.compiled[ConceptParts.BODY]
|
||||
|
||||
|
||||
def cprop(concept, prop_name):
|
||||
"""cbody stands for compiled property"""
|
||||
return concept.cached_asts[prop_name]
|
||||
return concept.compiled[prop_name]
|
||||
|
||||
|
||||
def init(concepts, grammar):
|
||||
@@ -402,14 +404,15 @@ def test_i_can_use_a_reference_with_a_body():
|
||||
assert context.sheerka.isinstance(res[0].value, BuiltinConcepts.PARSER_RESULT)
|
||||
assert res[0].value.body == [cnode("foo", 0, 2, "one two")]
|
||||
concept_found_1 = res[0].value.body[0].concept
|
||||
assert concept_found_1.body == "'foo'"
|
||||
assert concept_found_1.metadata.body == "'foo'"
|
||||
assert cbody(concept_found_1) is None
|
||||
|
||||
assert res[1].status
|
||||
assert context.sheerka.isinstance(res[1].value, BuiltinConcepts.PARSER_RESULT)
|
||||
assert res[1].value.body == [cnode("bar", 0, 2, "one two")]
|
||||
concept_found_2 = res[1].value.body[0].concept
|
||||
# the body and the prop['foo'] are the same concept 'foo'
|
||||
assert cbody(concept_found_2) == foo
|
||||
# the body and the prop['foo'] are the same concept 'foo'
|
||||
assert id(cprop(concept_found_2, "foo")) == id(cbody(concept_found_2))
|
||||
|
||||
|
||||
@@ -513,7 +516,7 @@ def test_i_can_parse_when_reference_has_a_body():
|
||||
assert res.status
|
||||
assert res.value.body == [cnode("foo", 0, 0, "twenty")]
|
||||
concept_found = res.value.body[0].concept
|
||||
assert concept_found.body == "'one'"
|
||||
assert concept_found.metadata.body == "'one'"
|
||||
|
||||
|
||||
def test_i_can_parse_multiple_results():
|
||||
@@ -1089,7 +1092,7 @@ def test_i_get_multiple_props_when_zero_or_more():
|
||||
assert return_value == [cnode("foo", 0, 4, "one one one")]
|
||||
concept_found = return_value[0].concept
|
||||
assert cbody(concept_found) == DoNotResolve("one one one")
|
||||
assert len(concept_found.cached_asts["one"]) == 3
|
||||
assert len(concept_found.compiled["one"]) == 3
|
||||
assert cprop(concept_found, "one")[0] == get_expected(one)
|
||||
assert cprop(concept_found, "one")[1] == get_expected(one)
|
||||
assert cprop(concept_found, "one")[2] == get_expected(one)
|
||||
|
||||
Reference in New Issue
Block a user