Fixed #131 : Implement ExprToConditions
Fixed #130 : ArithmeticOperatorParser Fixed #129 : python_wrapper : create_namespace Fixed #128 : ExpressionParser: Cannot parse func(x) infixed concept 'xxx'
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from parsers.ExactConceptParser import ExactConceptParser
|
||||
import pytest
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, DEFINITION_TYPE_DEF
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import Token, TokenKind, Tokenizer
|
||||
from parsers.BaseExpressionParser import NameExprNode
|
||||
from parsers.ExactConceptParser import ExactConceptParser, NotSupportedElement
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.parsers.parsers_utils import CMV, compare_with_test_object
|
||||
|
||||
@@ -189,6 +192,18 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
assert concept_found.get_hints().need_validation
|
||||
assert not concept_found.get_hints().is_evaluated
|
||||
|
||||
def test_i_cannot_parse_when_expression_contains_expr_token(self):
|
||||
sheerka, context = self.init_concepts()
|
||||
|
||||
tokens = list(Tokenizer("foo bar baz", yield_eof=False))
|
||||
tokens.append(Token(TokenKind.EXPR, NameExprNode(-1, -1, []), -1, -1, -1))
|
||||
|
||||
ret = ExactConceptParser().parse(context, ParserInput(None, tokens))
|
||||
|
||||
assert not ret.status
|
||||
assert sheerka.isinstance(ret.body, BuiltinConcepts.NOT_FOR_ME)
|
||||
assert isinstance(ret.body.reason, NotSupportedElement)
|
||||
|
||||
def test_i_can_manage_unknown_concept(self):
|
||||
context = self.get_context(self.get_sheerka(singleton=True))
|
||||
source = "def concept hello" # this is not a concept by itself
|
||||
@@ -209,6 +224,22 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
assert res.value.reason.body == source
|
||||
assert res.value.body == source
|
||||
|
||||
@pytest.mark.parametrize("text, concept_def", [
|
||||
("foo x", Concept("foo", definition="foo x", definition_type=DEFINITION_TYPE_DEF).def_var("x")),
|
||||
("foo", Concept("foo", definition="'foo' ('a'|'b')=x").def_var("x")),
|
||||
])
|
||||
def test_i_choose_concept_definition_over_concept_instance(self, text, concept_def):
|
||||
sheerka, context, foo = self.init_concepts(concept_def, create_new=True)
|
||||
|
||||
res = ExactConceptParser().parse(context, ParserInput(text))
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
|
||||
concept_found = res[0].body.body
|
||||
assert concept_found.get_hints().is_evaluated
|
||||
assert not concept_found.get_hints().is_instance
|
||||
|
||||
# def test_i_can_detect_concept_from_tokens(self):
|
||||
# context = self.get_context(self.get_sheerka(singleton=True))
|
||||
# concept = get_concept("hello world", [])
|
||||
|
||||
Reference in New Issue
Block a user