Fixed some bugs
This commit is contained in:
@@ -5,7 +5,7 @@ from core.sheerka.services.SheerkaComparisonManager import SheerkaComparisonMana
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import Tokenizer
|
||||
from parsers.BaseNodeParser import utnode, ConceptNode, cnode, short_cnode, UnrecognizedTokensNode, \
|
||||
SCWC, CNC, UTN
|
||||
SCWC, CNC, UTN, SourceCodeWithConceptNode
|
||||
from parsers.PythonParser import PythonNode
|
||||
from parsers.SyaNodeParser import SyaNodeParser, SyaConceptParserHelper, SyaAssociativity, \
|
||||
NoneAssociativeSequenceErrorNode, TooManyParametersFound
|
||||
@@ -56,10 +56,12 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
cmap["minus"].set_prop(BuiltinConcepts.ASSOCIATIVITY, "right")
|
||||
TestSyaNodeParser.sheerka.services[SheerkaComparisonManager.NAME].set_is_greater_than(context,
|
||||
BuiltinConcepts.PRECEDENCE,
|
||||
cmap["mult"], cmap["plus"])
|
||||
cmap["mult"],
|
||||
cmap["plus"])
|
||||
TestSyaNodeParser.sheerka.services[SheerkaComparisonManager.NAME].set_is_greater_than(context,
|
||||
BuiltinConcepts.PRECEDENCE,
|
||||
cmap["mult"], cmap["minus"])
|
||||
cmap["mult"],
|
||||
cmap["minus"])
|
||||
|
||||
# TestSyaNodeParser.sheerka.force_sya_def(context, [
|
||||
# (cmap["plus"].id, 5, SyaAssociativity.Right),
|
||||
@@ -716,6 +718,9 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
["one", "two", "three", "if", SCWC(" function(", ")", "x$!#")]]),
|
||||
("one prefixed function(two)", [["one", "prefixed", SCWC(" function(", ")", "two")]]),
|
||||
("suffixed one function(two)", [["one", "suffixed", SCWC(" function(", ")", "two")]]),
|
||||
(
|
||||
"func1(suffixed one func2(two))",
|
||||
[[SCWC("func1(", (")", 1), "one", "suffixed", SCWC(" func2(", ")", "two"))]]),
|
||||
])
|
||||
def test_i_can_post_fix_when_parenthesis_and_unknown(self, expression, expected_sequences):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
@@ -728,19 +733,19 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert res_i.out == expected_array
|
||||
|
||||
@pytest.mark.parametrize("expression, expected", [
|
||||
# ("(", ("(", 0)),
|
||||
# ("one plus ( 1 + ", ("(", 4)),
|
||||
# ("one( 1 + ", ("(", 1)),
|
||||
# ("one ( 1 + ", ("(", 2)),
|
||||
# ("function( 1 + ", ("(", 1)),
|
||||
# ("function ( 1 + ", ("(", 2)),
|
||||
# ("one plus ) 1 + ", (")", 4)),
|
||||
# ("one ) 1 + ", (")", 2)),
|
||||
# ("function ) 1 + ", (")", 2)),
|
||||
# ("one ? ( : two", ("(", 4)),
|
||||
# ("one ? one plus ( : two", ("(", 8)),
|
||||
# ("one ? ) : two", (")", 4)),
|
||||
# ("one ? one plus ) : two", (")", 8)),
|
||||
("(", ("(", 0)),
|
||||
("one plus ( 1 + ", ("(", 4)),
|
||||
("one( 1 + ", ("(", 1)),
|
||||
("one ( 1 + ", ("(", 2)),
|
||||
("function( 1 + ", ("(", 1)),
|
||||
("function ( 1 + ", ("(", 2)),
|
||||
("one plus ) 1 + ", (")", 4)),
|
||||
("one ) 1 + ", (")", 2)),
|
||||
("function ) 1 + ", (")", 2)),
|
||||
("one ? ( : two", ("(", 4)),
|
||||
("one ? one plus ( : two", ("(", 8)),
|
||||
("one ? ) : two", (")", 4)),
|
||||
("one ? one plus ) : two", (")", 8)),
|
||||
("(one plus ( 1 + )", ("(", 0)),
|
||||
])
|
||||
def test_i_can_detect_parenthesis_mismatch_error_when_post_fixing(self, expression, expected):
|
||||
@@ -797,6 +802,29 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert len(res) == 1
|
||||
assert res[0].out == expected_array
|
||||
|
||||
def test_i_cannot_post_fix_using_concept_short_name(self):
|
||||
concepts_map = {
|
||||
"infixed": self.from_def_concept("infixed", "a infixed b", ["a", "b"]),
|
||||
"suffixed": self.from_def_concept("suffixed", "suffixed a", ["a"]),
|
||||
"prefixed": self.from_def_concept("prefixed", "a prefixed", ["a"]),
|
||||
}
|
||||
sheerka, context, parser = self.init_parser(concepts_map)
|
||||
|
||||
res = parser.infix_to_postfix(context, ParserInput("desc(infixed)"))
|
||||
assert len(res) == 1
|
||||
assert isinstance(res[0].out[0], SourceCodeWithConceptNode)
|
||||
assert res[0].out[0].nodes[0].error == 'Not enough prefix parameters'
|
||||
|
||||
res = parser.infix_to_postfix(context, ParserInput("desc(suffixed)"))
|
||||
assert len(res) == 1
|
||||
assert isinstance(res[0].out[0], SourceCodeWithConceptNode)
|
||||
assert res[0].out[0].nodes[0].error == 'Not enough suffix parameters'
|
||||
|
||||
res = parser.infix_to_postfix(context, ParserInput("desc(prefixed)"))
|
||||
assert len(res) == 1
|
||||
assert isinstance(res[0].out[0], SourceCodeWithConceptNode)
|
||||
assert res[0].out[0].nodes[0].error == 'Not enough prefix parameters'
|
||||
|
||||
@pytest.mark.parametrize("expression", [
|
||||
"one ? two : three",
|
||||
"one?two:three",
|
||||
@@ -1117,6 +1145,26 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
assert context.sheerka.isinstance(wrapper, BuiltinConcepts.PARSER_RESULT)
|
||||
assert lexer_nodes == expected
|
||||
|
||||
def test_i_cannot_parse_function_using_short_name(self):
|
||||
concepts_map = {
|
||||
"infixed": self.from_def_concept("infixed", "a infixed b", ["a", "b"]),
|
||||
"suffixed": self.from_def_concept("suffixed", "suffixed a", ["a"]),
|
||||
"prefixed": self.from_def_concept("prefixed", "a prefixed", ["a"]),
|
||||
}
|
||||
sheerka, context, parser = self.init_parser(concepts_map)
|
||||
|
||||
res = parser.parse(context, ParserInput("desc(infixed)"))
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NOT_FOR_ME)
|
||||
|
||||
res = parser.parse(context, ParserInput("desc(suffixed)"))
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NOT_FOR_ME)
|
||||
|
||||
res = parser.parse(context, ParserInput("desc(prefixed)"))
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NOT_FOR_ME)
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"one",
|
||||
"1 + 1",
|
||||
@@ -1146,4 +1194,3 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.IS_EMPTY)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user