def test_invalid_syntax(): sc = scanner.Scanner("q1 := !!") lex = lexer.Lexer(sc) lex.next_token() # ok lex.next_token() # ok with pytest.raises(exceptions.InvalidSyntaxError): lex.next_token()
def parse(query): sc = scanner.Scanner(query) lex = lexer.Lexer(sc) parser = Parser(lex) interpreter = Interpreter(parser) interpreter.clear() interpreter.to_python() return interpreter.SCOPE
def test_line_number_position(self): sc = scanner.Scanner("hola\nsoy\n\nga\nbo") self.assertEqual(sc.lineno, 1) for i in range(5): sc.next() self.assertEqual(sc.lineno, 2) for i in range(5): sc.next() self.assertEqual(sc.lineno, 4)
def test_position(self): sc = scanner.Scanner("hola\n\n\na todos!") self.assertEqual(sc.lineno, 1) self.assertEqual(sc.index, 0) self.assertEqual(sc.colno, 1) for i in range(7): sc.next() self.assertEqual(sc.lineno, 4) self.assertEqual(sc.index, 7) self.assertEqual(sc.colno, 1)
def test_column_number_position(self): sc = scanner.Scanner("hola soy gabo") self.assertEqual(sc.colno, 1) for i in range(5): sc.next() self.assertEqual(sc.colno, 6) self.assertEqual(sc.char, 's') for i in range(4): sc.next() self.assertEqual(sc.colno, 10) self.assertEqual(sc.char, 'g')
def test_with_comment2(): text = ("% this is a comment\n" "q1 := select nombre='Gabriel (personas);\n" "% oasdlaskdalksjdlaksd\n" "% sdksjdksjdkjskdjskdj") sc = scanner.Scanner(text) lex = lexer.Lexer(sc) t = lex.next_token() t = lex.next_token() t = lex.next_token() t = lex.next_token() t = lex.next_token() assert t.value == "=" with pytest.raises(exceptions.MissingQuoteError): lex.next_token()
def test_with_comment(): sc = scanner.Scanner(("% this is a comment\n" "q1 := select nombre='Gabriel' (personas);\n" "% otro comentario\n" "% lalala\n" "%dddd\n" "% dddd\n\n\n" "q2 := select nombre='Gabriel (personas);")) lex = lexer.Lexer(sc) for i in range(12): token = lex.next_token() assert token.value == ":=" assert lex.sc.lineno == 9 for i in range(3): token = lex.next_token() assert token.value == "=" with pytest.raises(exceptions.MissingQuoteError): lex.next_token() assert lex.sc.lineno == 9 assert lex.sc.colno == 41
def lexer_bot(): sc = scanner.Scanner("q1_ := select nombre='Gabriel' (personas);") lex = lexer.Lexer(sc) return lex
def lexer_tokens(): sc = scanner.Scanner("> < <= >= = <> , ; ( )") return lexer.Lexer(sc)
def test_next_char(self): sc = scanner.Scanner("hola\na todos!") self.assertEqual(sc.char, 'h') chars = ['o', 'l', 'a', '\n', 'a'] for char in chars: self.assertEqual(sc.next_char(), char)
def make_lexer(self, text): sc = scanner.Scanner(text) lex = lexer.Lexer(sc) return lex
def select_bot(): sc = scanner.Scanner("q1 := select id=2 (ages);") lex = lexer.Lexer(sc) par = parser.Parser(lex) return par
def scanner_bot(): text = "hola gabo\ncomo estas?\n\n!" sc = scanner.Scanner(text) return text, sc
def test_5(): sc = scanner.Scanner("\n\n\n\n\nasdasd\n\n \n \n\n\n \n % asdasd") while sc.char: sc.next() assert sc.lineno == 13
def setUp(self): sc = scanner.Scanner("q1 := select id=2 (p);") lex = lexer.Lexer(sc) self.parser = parser.Parser(lex)