Fixed minor issues and enhancements
This commit is contained in:
@@ -49,8 +49,7 @@ class TestBuiltinHelpers(TestUsingMemoryBasedSheerka):
|
||||
]
|
||||
res = core.builtin_helpers.expect_one(self.get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert res.value, items[0]
|
||||
assert res.parents == items
|
||||
assert res.value == items[0].body
|
||||
|
||||
def test_i_can_use_expect_when_only_errors_2(self):
|
||||
sheerka = self.get_sheerka()
|
||||
@@ -74,7 +73,6 @@ class TestBuiltinHelpers(TestUsingMemoryBasedSheerka):
|
||||
res = core.builtin_helpers.expect_one(self.get_context(sheerka), items)
|
||||
assert res.status
|
||||
assert res.body == items[0].body
|
||||
assert res.parents == items
|
||||
|
||||
def test_i_can_use_expect_one_when_one_success_2(self):
|
||||
sheerka = self.get_sheerka()
|
||||
|
||||
@@ -193,6 +193,20 @@ class TestAtomsParser(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.isinstance(wrapper, BuiltinConcepts.PARSER_RESULT)
|
||||
assert lexer_nodes == expected_array
|
||||
|
||||
def test_i_can_parse_concepts_with_isa(self):
|
||||
concepts_map = {
|
||||
"one": Concept("one"),
|
||||
"number": Concept("number"),
|
||||
}
|
||||
|
||||
sheerka, context, parser = self.init_parser(concepts_map)
|
||||
sheerka.set_isa(context, sheerka.new("one"), sheerka.new("number"))
|
||||
|
||||
res = parser.parse(context, "one")
|
||||
lexer_nodes = res.body.body
|
||||
expected_array = compute_expected_array(concepts_map, "one", ["one"])
|
||||
assert lexer_nodes == expected_array
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"foo",
|
||||
f"foo one",
|
||||
|
||||
@@ -129,12 +129,14 @@ class TestExactConceptParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_i_can_detect_concepts_too_long(self):
|
||||
context = self.get_context(self.get_sheerka(singleton=True))
|
||||
source = "a very very long concept"
|
||||
source = "a very but finally too long concept"
|
||||
res = ExactConceptParser().parse(context, source)
|
||||
|
||||
assert not res.status
|
||||
assert context.sheerka.isinstance(res.value, BuiltinConcepts.CONCEPT_TOO_LONG)
|
||||
assert res.value.body == "a very very long concept"
|
||||
assert context.sheerka.isinstance(res.value, BuiltinConcepts.NOT_FOR_ME)
|
||||
assert context.sheerka.isinstance(res.value.reason, BuiltinConcepts.CONCEPT_TOO_LONG)
|
||||
assert res.value.reason.body == source
|
||||
assert res.value.body == source
|
||||
|
||||
def test_i_can_detect_concept_from_tokens(self):
|
||||
context = self.get_context(self.get_sheerka(singleton=True))
|
||||
|
||||
@@ -776,7 +776,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
("(one infix two) (three prefixed)", ["one", "two", "infix", "three", "prefixed"]),
|
||||
])
|
||||
def test_i_can_post_fix_sequences(self, expression, expected):
|
||||
sheerka, context, parser = self.init_parser(cmap, None)
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
res = parser.infix_to_postfix(context, expression)
|
||||
expected_array = compute_expected_array(cmap, expression, expected)
|
||||
@@ -784,6 +784,24 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert len(res) == 1
|
||||
assert res[0].out == expected_array
|
||||
|
||||
@pytest.mark.parametrize("expression", [
|
||||
"one ? two : three",
|
||||
"one?two:three",
|
||||
"one ?two:three",
|
||||
"one? two:three",
|
||||
"one ? two :three",
|
||||
"one ? two: three",
|
||||
])
|
||||
def test_whitespaces_may_be_omitted_in_some_circumstances(self, expression):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
expected = ["one", "two", "three", "?"]
|
||||
res = parser.infix_to_postfix(context, expression)
|
||||
expected_array = compute_expected_array(cmap, expression, expected)
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].out == expected_array
|
||||
|
||||
def test_the_more_concepts_the_more_results(self):
|
||||
concepts_map = {
|
||||
"plus": Concept("a plus b").def_var("a").def_var("b"),
|
||||
|
||||
Reference in New Issue
Block a user