Fixed initialisation issue for concepts with BNF definition
This commit is contained in:
@@ -485,6 +485,27 @@ def test_i_can_detect_duplicates_when_reference():
|
||||
assert res[1].value.body == [(foo, 0, 0, "twenty")]
|
||||
|
||||
|
||||
def test_i_can_parse_concept_reference_that_is_not_in_grammar():
|
||||
context = get_context()
|
||||
one = Concept(name="one")
|
||||
two = Concept(name="two")
|
||||
foo = Concept(name="foo")
|
||||
context.sheerka.add_in_cache(one)
|
||||
context.sheerka.add_in_cache(two)
|
||||
|
||||
concepts = {foo: Sequence("twenty", OrderedChoice(one, two))}
|
||||
parser = ConceptLexerParser()
|
||||
parser.initialize(context, concepts)
|
||||
|
||||
res = parser.parse(context, "twenty two")
|
||||
assert res.status
|
||||
assert res.value.body == [(foo, 0, 2, "twenty two")]
|
||||
|
||||
res = parser.parse(context, "twenty one")
|
||||
assert res.status
|
||||
assert res.value.body == [(foo, 0, 2, "twenty one")]
|
||||
|
||||
|
||||
def test_i_can_parse_zero_or_more():
|
||||
context = get_context()
|
||||
foo = Concept(name="foo")
|
||||
@@ -741,6 +762,7 @@ def test_infinite_recursion_does_not_fail_if_a_concept_is_missing():
|
||||
|
||||
assert foo in parser.concepts_grammars
|
||||
|
||||
|
||||
def test_i_can_detect_indirect_infinite_recursion_with_optional():
|
||||
# TODO infinite recursion with optional
|
||||
pass
|
||||
|
||||
+13
-7
@@ -319,6 +319,7 @@ def test_list_of_concept_is_sorted_by_id():
|
||||
|
||||
assert concepts[0].id < concepts[-1].id
|
||||
|
||||
|
||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
#
|
||||
# E V A L U A T I O N S
|
||||
@@ -597,9 +598,7 @@ def test_i_can_create_concept_with_bnf_definition():
|
||||
sheerka = get_sheerka(False, False)
|
||||
a = Concept("a")
|
||||
sheerka.add_in_cache(a)
|
||||
sheerka.concepts_grammars = ConceptLexerParser().initialize(
|
||||
get_context(sheerka),
|
||||
{a: OrderedChoice("one", "two")}).body
|
||||
sheerka.concepts_definition_cache = {a: OrderedChoice("one", "two")}
|
||||
|
||||
res = sheerka.evaluate_user_input("def concept plus from bnf a ('plus' plus)?")
|
||||
assert len(res) == 1
|
||||
@@ -637,7 +636,6 @@ def test_i_can_eval_bnf_definitions():
|
||||
assert sheerka.isinstance(res[0].value, concept_a)
|
||||
|
||||
|
||||
|
||||
def test_i_can_eval_bnf_definitions_with_variables():
|
||||
sheerka = get_sheerka()
|
||||
concept_a = sheerka.evaluate_user_input("def concept a from bnf 'one' | 'two'")[0].body.body
|
||||
@@ -659,18 +657,26 @@ def test_i_can_eval_bnf_definitions_from_separate_instances():
|
||||
but make sure that the BNF are correctly persisted and loaded
|
||||
"""
|
||||
sheerka = get_sheerka(False)
|
||||
concept_a = sheerka.evaluate_user_input("def concept a from bnf 'one' | 'two'")[0].body.body
|
||||
concept_a = sheerka.evaluate_user_input("def concept a from bnf 'one' 'two'")[0].body.body
|
||||
|
||||
res = get_sheerka(False).evaluate_user_input("one")
|
||||
res = get_sheerka(False).evaluate_user_input("one two")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].value, concept_a)
|
||||
|
||||
res = get_sheerka(False).evaluate_user_input("two")
|
||||
# add another bnf definition
|
||||
concept_b = sheerka.evaluate_user_input("def concept b from bnf a 'three'")[0].body.body
|
||||
|
||||
res = get_sheerka(False).evaluate_user_input("one two") # previous one still works
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].value, concept_a)
|
||||
|
||||
res = get_sheerka(False).evaluate_user_input("one two three") # new one works
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].value, concept_b)
|
||||
|
||||
|
||||
def get_sheerka(use_dict=True, skip_builtins_in_db=True):
|
||||
root = "mem://" if use_dict else root_folder
|
||||
|
||||
Reference in New Issue
Block a user