def should_fail(tester, string_source, expected_error_code=None, expected_token_type=None, expected_description=None): parser = Parser(StringSource(string_source)) with tester.assertRaises(ParserError) as e: parser.parse_program() if expected_error_code is not None: tester.assertEqual(expected_error_code, e.exception.error_code) if expected_token_type is not None: tester.assertEqual(expected_token_type, e.exception.expected_token_type) if expected_description: tester.assertEqual(expected_description, e.exception.description)
def test_something(self): string_source = 'i = 100;\n' \ 'while (a>1){\n' \ ' print(a-1);};' parser = Parser(StringSource(string_source)) program = parser.parse_program() ast_dumper = AstDumper() ast_dumper.add_child(lambda: ast_dumper.visit(program), str(program))
def test_something(self): string_source = ' fun partition(arr, low, high)' \ ' {' \ ' i = (low -1);' \ ' pivot = arr[high];' \ ' for (j in range)' \ ' if (arr[j] < pivot)' \ ' {' \ ' i = i+1;' \ ' temp = arr[i];' \ ' arr[i] = arr[j];' \ ' arr[j] = temp;' \ ' }' \ ' temp = arr[i+1];' \ ' arr[i+1] = arr[high];' \ ' arr[high] = temp;' \ ' ret (i+1);' \ ' }' \ ' fun quickSort(arr, low, high)' \ ' if (low < high)' \ ' {' \ ' pi = partition(arr, low, high);' \ ' quickSort(arr, low, pi-1);' \ ' quickSort(arr, pi+1, high);' \ ' }' s = 'x[2];\n' \ 'a[1, 2];\n' \ 'b[a];\n' \ 'c[:];\n' \ 'd[:, 1];\n' \ 'e[1, :];\n' \ 'f[:, :];' parser = Parser(StringSource(string_source)) program = parser.parse_program() ast_dumper = AstDumper() ast_dumper.add_child(lambda: ast_dumper.visit(program), str(program))
def dumpAST(source: Source): parser = Parser(source) program = parser.parse_program() ast_dumper = AstDumper() ast_dumper.add_child(lambda: ast_dumper.visit(program), str(program))
def test_fix_dump(self): s = 'a = 0;' parser = Parser(StringSource(s)) program = parser.parse_program() ast_dumper = AstDumper() ast_dumper.add_child(lambda: ast_dumper.visit(program), str(program))
def test_filesource(self): filesource = FileSource('test.txt') parser = Parser(filesource) program = parser.parse_program() ast_dumper = AstDumper() ast_dumper.add_child(lambda: ast_dumper.visit(program), str(program))