Concept validation must be requested
This commit is contained in:
@@ -1225,6 +1225,28 @@ class TestConceptLexerParser(TestUsingMemoryBasedSheerka):
|
||||
OneOrMore(ConceptExpression(baz, rule_name="baz")), rule_name="oc"), rule_name="s")
|
||||
assert parse_res.value.value == expected
|
||||
|
||||
def test_i_concept_validation_is_not_set_when_no_variables(self):
|
||||
foo = Concept(name="foo")
|
||||
grammar = {foo: "foo"}
|
||||
|
||||
context, res, wrapper, return_value = self.execute([foo], grammar, "foo")
|
||||
assert not return_value[0].concept.metadata.need_validation
|
||||
|
||||
def test_i_concept_validation_is_set_when_unnamed_variables_are_found(self):
|
||||
foo = Concept(name="foo")
|
||||
grammar = {foo: Sequence("foo", OrderedChoice("a", "b"))}
|
||||
|
||||
context, res, wrapper, return_value = self.execute([foo], grammar, "foo a")
|
||||
assert not return_value[0].concept.metadata.need_validation
|
||||
|
||||
def test_i_concept_validation_is_set_when_named_variables_are_found(self):
|
||||
foo = Concept(name="foo")
|
||||
grammar = {foo: Sequence("foo", OrderedChoice("a", "b", rule_name="var"))}
|
||||
|
||||
context, res, wrapper, return_value = self.execute([foo], grammar, "foo a")
|
||||
assert return_value[0].concept.metadata.need_validation
|
||||
|
||||
|
||||
#
|
||||
# def test_i_can_parse_basic_arithmetic_operations_and_resolve_properties(self):
|
||||
# context = self.get_context()
|
||||
|
||||
@@ -93,7 +93,7 @@ class TestConceptsWithConceptsParser(TestUsingMemoryBasedSheerka):
|
||||
assert return_value.compiled["b"] == bar
|
||||
|
||||
# sanity check, I can evaluate the result
|
||||
evaluated = context.sheerka.evaluate_concept(context, return_value, True)
|
||||
evaluated = context.sheerka.evaluate_concept(self.get_context(context.sheerka, True), return_value)
|
||||
assert evaluated.key == return_value.key
|
||||
assert evaluated.get_prop("a") == foo.init_key()
|
||||
assert evaluated.get_prop("b") == bar.init_key()
|
||||
@@ -116,7 +116,7 @@ class TestConceptsWithConceptsParser(TestUsingMemoryBasedSheerka):
|
||||
assert return_value.compiled["b"] == [ReturnValueConcept(parser.name, True, right_parser_result)]
|
||||
|
||||
# sanity check, I can evaluate the result
|
||||
evaluated = context.sheerka.evaluate_concept(context, return_value, True)
|
||||
evaluated = context.sheerka.evaluate_concept(self.get_context(context.sheerka, True), return_value)
|
||||
assert evaluated.key == return_value.key
|
||||
assert evaluated.get_prop("a") == 2
|
||||
assert evaluated.get_prop("b") == 4
|
||||
@@ -139,7 +139,7 @@ class TestConceptsWithConceptsParser(TestUsingMemoryBasedSheerka):
|
||||
assert return_value.compiled["b"] == [ReturnValueConcept(parser.name, True, code_parser_result)]
|
||||
|
||||
# sanity check, I can evaluate the result
|
||||
evaluated = context.sheerka.evaluate_concept(context, return_value, True)
|
||||
evaluated = context.sheerka.evaluate_concept(self.get_context(context.sheerka, True), return_value)
|
||||
assert evaluated.key == return_value.key
|
||||
assert evaluated.get_prop("a") == foo.init_key()
|
||||
assert evaluated.get_prop("b") == 2
|
||||
|
||||
@@ -56,10 +56,12 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
source = "hello world"
|
||||
results = ExactConceptParser().parse(context, source)
|
||||
concept_found = results[0].value.value
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].status
|
||||
assert results[0].value.value == concept
|
||||
assert concept_found == concept
|
||||
assert not concept_found.metadata.need_validation
|
||||
|
||||
def test_i_can_recognize_concepts_defined_several_times(self):
|
||||
context = self.get_context()
|
||||
@@ -75,9 +77,11 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
assert results[0].status
|
||||
assert results[0].value.value.name == "hello a"
|
||||
assert metadata_prop(results[0].value.value, "a") == "world"
|
||||
assert results[0].value.value.metadata.need_validation
|
||||
|
||||
assert results[1].status
|
||||
assert results[1].value.value.name == "hello world"
|
||||
assert not results[1].value.value.metadata.need_validation
|
||||
|
||||
def test_i_can_recognize_a_concept_with_variables(self):
|
||||
context = self.get_context()
|
||||
@@ -88,10 +92,12 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].status
|
||||
|
||||
concept_found = results[0].value.value
|
||||
assert concept_found.key == concept.key
|
||||
assert metadata_prop(concept_found, "a") == "10"
|
||||
assert metadata_prop(concept_found, "b") == "5"
|
||||
assert concept_found.metadata.need_validation
|
||||
|
||||
def test_i_can_recognize_a_concept_with_duplicate_variables(self):
|
||||
context = self.get_context()
|
||||
@@ -102,10 +108,12 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].status
|
||||
|
||||
concept_found = results[0].value.value
|
||||
assert concept_found.key == concept.key
|
||||
assert metadata_prop(concept_found, "a") == "10"
|
||||
assert metadata_prop(concept_found, "b") == "5"
|
||||
assert concept_found.metadata.need_validation
|
||||
|
||||
def test_i_can_manage_unknown_concept(self):
|
||||
context = self.get_context()
|
||||
@@ -136,3 +144,4 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
assert len(results) == 1
|
||||
assert results[0].status
|
||||
assert results[0].value.value == concept
|
||||
assert not results[0].value.value.metadata.need_validation
|
||||
|
||||
Reference in New Issue
Block a user