Working on #98 : Persist attribute value when global_truth is set to true
This commit is contained in:
@@ -5,7 +5,7 @@ from core.concept import Concept, DEFINITION_TYPE_DEF
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from parsers.SequenceNodeParser import SequenceNodeParser
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.parsers.parsers_utils import compute_expected_array, CN, CNC, SCN, get_test_obj, compare_with_test_object, \
|
||||
from tests.parsers.parsers_utils import compute_expected_array, CN, SCN, get_test_obj, compare_with_test_object, \
|
||||
UTN
|
||||
|
||||
|
||||
@@ -275,6 +275,26 @@ class TestSequenceNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert concept_found.get_hints().is_evaluated
|
||||
assert not concept_found.get_hints().is_instance
|
||||
|
||||
def test_i_can_parse_when_variable_is_not_a_parameter(self):
|
||||
concepts_map = {
|
||||
"foo": Concept("foo").def_var("a"), # 'a' is not a parameter (but a property like its color for ex)
|
||||
}
|
||||
|
||||
text, expected = "foo", ["foo"]
|
||||
sheerka, context, parser = self.init_parser(concepts_map, create_new=True, use_sheerka=True)
|
||||
res = parser.parse(context, ParserInput(text))
|
||||
wrapper = res.body
|
||||
lexer_nodes = res.body.body
|
||||
|
||||
assert res.status
|
||||
|
||||
expected_array = compute_expected_array(concepts_map, text, expected)
|
||||
assert sheerka.isinstance(wrapper, BuiltinConcepts.PARSER_RESULT)
|
||||
compare_with_test_object(lexer_nodes, expected_array)
|
||||
assert not lexer_nodes[0].concept.get_hints().is_evaluated
|
||||
assert lexer_nodes[0].concept.get_hints().use_copy
|
||||
assert lexer_nodes[0].concept.get_hints().is_instance
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"foo",
|
||||
f"foo one",
|
||||
|
||||
@@ -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(")),
|
||||
|
||||
Reference in New Issue
Block a user