Fixed BNF concept evaluations
This commit is contained in:
@@ -240,13 +240,17 @@ def test_i_can_eval_concept_with_variable():
|
||||
|
||||
def test_i_can_eval_concept_with_variable_and_python_as_body():
|
||||
sheerka = get_sheerka()
|
||||
sheerka.add_in_cache(Concept(name="hello a", body="'hello ' + a").set_prop("a"))
|
||||
hello_a = sheerka.add_in_cache(Concept(name="hello a", body="'hello ' + a").set_prop("a"))
|
||||
sheerka.add_in_cache(Concept(name="foo", body="'foo'"))
|
||||
|
||||
res = sheerka.evaluate_user_input("hello foo")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].value, "hello foo"
|
||||
assert sheerka.isinstance(res[0].value, hello_a)
|
||||
assert res[0].value.body == "hello foo"
|
||||
assert res[0].value.metadata.is_evaluated
|
||||
assert res[0].value.props["a"].value == Concept(name="foo", body="foo").init_key()
|
||||
assert res[0].value.props["a"].value.metadata.is_evaluated
|
||||
|
||||
|
||||
def test_i_can_eval_duplicate_concepts_with_same_value():
|
||||
@@ -259,7 +263,7 @@ def test_i_can_eval_duplicate_concepts_with_same_value():
|
||||
res = sheerka.evaluate_user_input("hello foo")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].value, "hello foo"
|
||||
assert res[0].value.body == "hello foo"
|
||||
assert res[0].who == sheerka.get_evaluator_name(MultipleSameSuccessEvaluator.NAME)
|
||||
|
||||
|
||||
@@ -362,7 +366,11 @@ def test_i_can_eval_bnf_definitions_with_variables():
|
||||
return_value = res[0].value
|
||||
|
||||
assert sheerka.isinstance(return_value, concept_b)
|
||||
assert return_value.props["a"] == Property("a", sheerka.new(concept_a.key, body="one"))
|
||||
assert return_value.body == "one three"
|
||||
assert return_value.metadata.is_evaluated
|
||||
|
||||
assert return_value.props["a"] == Property("a", sheerka.new(concept_a.key, body="one").init_key())
|
||||
assert return_value.props["a"].value.metadata.is_evaluated
|
||||
|
||||
|
||||
def test_i_can_eval_bnf_definitions_from_separate_instances():
|
||||
@@ -390,6 +398,8 @@ def test_i_can_eval_bnf_definitions_from_separate_instances():
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].value, concept_b)
|
||||
assert res[0].value.body == "one two three"
|
||||
assert res[0].value.props["a"] == Property("a", sheerka.new(concept_a.key, body="one two").init_key())
|
||||
|
||||
|
||||
def test_i_can_say_that_a_concept_isa_another_concept():
|
||||
@@ -398,6 +408,7 @@ def test_i_can_say_that_a_concept_isa_another_concept():
|
||||
sheerka.evaluate_user_input("def concept bar")
|
||||
|
||||
res = sheerka.evaluate_user_input("foo isa bar")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, BuiltinConcepts.SUCCESS)
|
||||
|
||||
@@ -436,3 +447,40 @@ def test_i_can_manage_tokenizer_error(text):
|
||||
assert len(res) > 1
|
||||
for r in [r for r in res if r.who.startswith("parsers.")]:
|
||||
assert not r.status
|
||||
|
||||
|
||||
def test_i_can_recognize_concept_from_string():
|
||||
sheerka = get_sheerka()
|
||||
sheerka.add_in_cache(Concept("one", body="1"))
|
||||
|
||||
res = sheerka.evaluate_user_input("'one'")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == "one"
|
||||
|
||||
res = sheerka.evaluate_user_input("eval 'one'")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == "one"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("expression", [
|
||||
"def concept twenties from bnf 'twenty' (one | two)=unit as 20 + unit",
|
||||
"def concept twenties from bnf 'twenty' (one | two)=unit as twenty + unit",
|
||||
"def concept twenties from bnf twenty (one | two)=unit as 20 + unit",
|
||||
"def concept twenties from bnf twenty (one | two)=unit as twenty + unit",
|
||||
])
|
||||
def test_i_can_evaluate_bnf_concepts(expression):
|
||||
sheerka = get_sheerka()
|
||||
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
sheerka.evaluate_user_input("def concept two as 2")
|
||||
sheerka.evaluate_user_input("def concept twenty as 20")
|
||||
sheerka.evaluate_user_input(expression)
|
||||
res = sheerka.evaluate_user_input("eval twenty one")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == 21
|
||||
|
||||
Reference in New Issue
Block a user