Working on #98 : Persist attribute value when global_truth is set to true

This commit is contained in:
2021-08-03 11:26:57 +02:00
parent e69745adc8
commit c798c2c570
22 changed files with 496 additions and 106 deletions
+40
View File
@@ -1114,6 +1114,33 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
# check metadata
assert expected_concept.get_metadata().variables == [("a", "twenty one")]
def test_i_can_parse_when_all_variables_are_not_parameters(self):
my_map = {
"foo": Concept("foo a").def_var("a", "'default_a'").def_var("b", "'default_b'"), # 'b' is not a parameter
"bar": Concept("bar b").def_var("a", "'default_a'").def_var("b", "'default_b'"), # 'a' is not a parameter
"baz": Concept("baz")
}
sheerka, context, parser = self.init_parser(my_map)
text = "foo baz"
res = parser.parse(context, ParserInput(text))
assert res.status
assert len(res.body.body) == 1
expected_concept = res.body.body[0].concept
assert sheerka.isinstance(expected_concept.get_compiled()["a"], "baz")
assert "b" not in expected_concept.get_compiled()
assert expected_concept.get_metadata().variables == [("a", "baz"), ("b", "'default_b'")]
text = "bar baz"
res = parser.parse(context, ParserInput(text))
assert res.status
assert len(res.body.body) == 1
expected_concept = res.body.body[0].concept
assert sheerka.isinstance(expected_concept.get_compiled()["b"], "baz")
assert "a" not in expected_concept.get_compiled()
assert expected_concept.get_metadata().variables == [("a", "'default_a'"), ("b", "baz")]
def test_i_can_parse_sequences(self):
sheerka, context, parser = self.init_parser()
@@ -1335,6 +1362,19 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
assert not res.status
assert sheerka.isinstance(res.body, BuiltinConcepts.IS_EMPTY)
def test_i_cannot_parse_concept_when_variable_is_not_a_parameter(self):
my_map = {
"foo": Concept("foo").def_var("a") # 'a' is not a parameter (but a property like its color for ex)
}
sheerka, context, parser = self.init_parser(my_map)
text = "foo"
res = parser.parse(context, ParserInput(text))
assert not res.status
assert sheerka.isinstance(res.body, BuiltinConcepts.NOT_FOR_ME)
assert res.body.body == text
@pytest.mark.parametrize("expression, expected", [
("function(", ([], "function(")),
("before the function(", (["before the "], "function(")),