Implemented some enhancement requests
This commit is contained in:
@@ -2,7 +2,7 @@ import pytest
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import Keywords, Tokenizer, TokenKind
|
||||
from parsers.BaseCustomGrammarParser import BaseCustomGrammarParser, SyntaxErrorNode, KeywordNotFound
|
||||
from parsers.BaseParser import UnexpectedEofNode, UnexpectedTokenErrorNode
|
||||
from parsers.BaseParser import UnexpectedEofParsingError, UnexpectedTokenParsingError
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
@@ -83,9 +83,9 @@ func(a)
|
||||
sheerka, context, parser = self.init_parser("when xxx print yyy")
|
||||
|
||||
assert parser.get_parts(["when", "print"], Keywords.PRINT) is None
|
||||
assert parser.error_sink == [UnexpectedTokenErrorNode(f"'print' keyword not found.",
|
||||
assert parser.error_sink == [UnexpectedTokenParsingError(f"'print' keyword not found.",
|
||||
"when",
|
||||
[Keywords.PRINT])]
|
||||
[Keywords.PRINT])]
|
||||
|
||||
def test_i_can_detect_when_a_keyword_appears_several_times(self):
|
||||
sheerka, context, parser = self.init_parser("print hello when True print True")
|
||||
@@ -106,7 +106,7 @@ func(a)
|
||||
|
||||
assert parser.get_parts(["print", "when"]) is not None
|
||||
assert len(parser.error_sink) == 1
|
||||
assert isinstance(parser.error_sink[0], UnexpectedEofNode)
|
||||
assert isinstance(parser.error_sink[0], UnexpectedEofParsingError)
|
||||
assert parser.error_sink[0].message == "While parsing keyword 'print'."
|
||||
|
||||
def test_i_can_double_quoted_strings_are_expanded(self):
|
||||
@@ -178,7 +178,7 @@ print xxx"""
|
||||
sheerka, context, parser = self.init_parser(text)
|
||||
|
||||
assert parser.get_parts(["when"])
|
||||
assert parser.error_sink == [UnexpectedTokenErrorNode("Indentation not found.", "x", [TokenKind.WHITESPACE])]
|
||||
assert parser.error_sink == [UnexpectedTokenParsingError("Indentation not found.", "x", [TokenKind.WHITESPACE])]
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"",
|
||||
@@ -197,7 +197,7 @@ print xxx"""
|
||||
sheerka, context, parser = self.init_parser("")
|
||||
|
||||
assert parser.get_body(list(Tokenizer("not a newline", yield_eof=False))) is None
|
||||
assert parser.error_sink == [UnexpectedTokenErrorNode("New line not found.", "not", [TokenKind.NEWLINE])]
|
||||
assert parser.error_sink == [UnexpectedTokenParsingError("New line not found.", "not", [TokenKind.NEWLINE])]
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"\nx x",
|
||||
@@ -207,14 +207,14 @@ print xxx"""
|
||||
sheerka, context, parser = self.init_parser("")
|
||||
|
||||
assert parser.get_body(list(Tokenizer(text, yield_eof=False))) is None
|
||||
assert parser.error_sink == [UnexpectedTokenErrorNode("Indentation not found.", "x", [TokenKind.WHITESPACE])]
|
||||
assert parser.error_sink == [UnexpectedTokenParsingError("Indentation not found.", "x", [TokenKind.WHITESPACE])]
|
||||
|
||||
def test_i_can_detect_missing_tab_when_get_body(self):
|
||||
text = "\n\txxx\n\tyyy\nzzz"
|
||||
|
||||
sheerka, context, parser = self.init_parser("")
|
||||
assert parser.get_body(list(Tokenizer(text, yield_eof=False))) is None
|
||||
assert parser.error_sink == [UnexpectedTokenErrorNode("Indentation not found.", "zzz", [TokenKind.WHITESPACE])]
|
||||
assert parser.error_sink == [UnexpectedTokenParsingError("Indentation not found.", "zzz", [TokenKind.WHITESPACE])]
|
||||
|
||||
def test_i_can_detect_invalid_indentation_when_get_body(self):
|
||||
sheerka, context, parser = self.init_parser("")
|
||||
|
||||
Reference in New Issue
Block a user