Added first implementation of concepts ambiguity resolution + Jenkins file test
This commit is contained in:
@@ -3,6 +3,7 @@ import ast
|
||||
import core.builtin_helpers
|
||||
import pytest
|
||||
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
@@ -142,3 +143,73 @@ class TestBuiltinHelpers(TestUsingMemoryBasedSheerka):
|
||||
assert len(actual) == len(expected)
|
||||
for i in range(len(actual)):
|
||||
assert self.dump_ast(actual[i]) == self.dump_ast(expected[i])
|
||||
|
||||
@pytest.mark.parametrize("concepts, expected", [
|
||||
([], []),
|
||||
([Concept("foo", pre="True"), Concept("bar")], ["foo"]),
|
||||
([Concept("foo").def_var("a"), Concept("bar")], ["bar"]),
|
||||
])
|
||||
def test_i_can_resolve_ambiguity_when_empty(self, concepts, expected):
|
||||
context = self.get_context()
|
||||
res = core.builtin_helpers.resolve_ambiguity(context, concepts)
|
||||
assert [c.name for c in res] == expected
|
||||
|
||||
# @pytest.mark.parametrize("return_values", [
|
||||
# None,
|
||||
# []
|
||||
# ])
|
||||
# def test_i_can_resolve_simple_ambiguity_when_no_return_values(self, return_values):
|
||||
# context = self.get_context()
|
||||
#
|
||||
# assert core.builtin_helpers.remove_ambiguity(context, return_values) == return_values
|
||||
|
||||
# def test_resolve_ambiguity_concepts_with_no_variable_take_precedence(self):
|
||||
# context = self.get_context()
|
||||
# return_values = [
|
||||
# self.pretval(Concept("hello a").def_var("a", "world"), "hello word"),
|
||||
# self.pretval(Concept("hello world"), "hello word"),
|
||||
# # self.pretval(Concept("hello world", pre="False"), "hello word"),
|
||||
# self.retval(Concept("not a parser result")),
|
||||
# self.retval(Concept("status is false"), status=False),
|
||||
# self.pretval(Concept("false parser result"), status=False),
|
||||
# ]
|
||||
#
|
||||
# ret = core.builtin_helpers.remove_ambiguity(context, return_values)
|
||||
# assert ret.status
|
||||
# assert ret.parents == return_values
|
||||
#
|
||||
# filtered = ret.body
|
||||
# assert context.sheerka.isinstance(ret.body, BuiltinConcepts.FILTERED)
|
||||
# assert filtered.body == [
|
||||
# return_values[2],
|
||||
# return_values[3],
|
||||
# return_values[4],
|
||||
# return_values[1],
|
||||
# ]
|
||||
# assert filtered.iterable == return_values
|
||||
# assert filtered.predicate == "remove_ambiguity(context, iterable)"
|
||||
#
|
||||
# def test_resolve_ambiguity_failed_pre_condition_are_discarded(self):
|
||||
# context = self.get_context()
|
||||
# return_values = [
|
||||
# self.pretval(Concept("hello world"), "hello word"),
|
||||
# self.pretval(Concept("hello world", pre="False"), "hello word"),
|
||||
# ]
|
||||
#
|
||||
# ret = core.builtin_helpers.remove_ambiguity(context, return_values)
|
||||
# filtered = ret.body
|
||||
# assert context.sheerka.isinstance(ret.body, BuiltinConcepts.FILTERED)
|
||||
# assert filtered.body == [
|
||||
# return_values[0],
|
||||
# ]
|
||||
#
|
||||
# def test_resolve_ambiguity_original_return_value_is_returned_when_nothing_to_filter(self):
|
||||
# context = self.get_context()
|
||||
# return_values = [
|
||||
# self.pretval(Concept("hello a").def_var("a", "world"), "hello word"),
|
||||
# self.retval(Concept("not a parser result")),
|
||||
# self.retval(Concept("status is false"), status=False),
|
||||
# self.pretval(Concept("false parser result"), status=False),
|
||||
# ]
|
||||
#
|
||||
# assert core.builtin_helpers.remove_ambiguity(context, return_values) == return_values
|
||||
|
||||
Reference in New Issue
Block a user