def exprCheck(expr, output=None): class Config: c_id_attributes = ["id_attr"] c_paren_attributes = ["paren_attr"] parser = DefinitionParser(expr, location=None, config=Config()) parser.allowFallbackExpressionParsing = False ast = parser.parse_expression() parser.assert_end() # first a simple check of the AST if output is None: output = expr res = str(ast) if res != output: print("") print("Input: ", input) print("Result: ", res) print("Expected: ", output) raise DefinitionError("") displayString = ast.get_display_string() if res != displayString: # note: if the expression contains an anon name then this will trigger a falsely print("") print("Input: ", expr) print("Result: ", res) print("Display: ", displayString) raise DefinitionError("")
def check(name, input, idDict, output=None): # first a simple check of the AST if output is None: output = input ast = parse(name, input) res = str(ast) if res != output: print("") print("Input: ", input) print("Result: ", res) print("Expected: ", output) raise DefinitionError("") rootSymbol = Symbol(None, None, None, None) symbol = rootSymbol.add_declaration(ast, docname="TestDoc") parentNode = addnodes.desc() signode = addnodes.desc_signature(input, '') parentNode += signode ast.describe_signature(signode, 'lastIsName', symbol, options={}) idExpected = [None] for i in range(1, _max_id + 1): if i in idDict: idExpected.append(idDict[i]) else: idExpected.append(idExpected[i - 1]) idActual = [None] for i in range(1, _max_id + 1): #try: id = ast.get_id(version=i) assert id is not None idActual.append(id[len(_id_prefix[i]):]) #except NoOldIdError: # idActual.append(None) res = [True] for i in range(1, _max_id + 1): res.append(idExpected[i] == idActual[i]) if not all(res): print("input: %s" % input.rjust(20)) for i in range(1, _max_id + 1): if res[i]: continue print("Error in id version %d." % i) print("result: %s" % idActual[i]) print("expected: %s" % idExpected[i]) #print(rootSymbol.dump(0)) raise DefinitionError("")
def exprCheck(expr, output=None): parser = DefinitionParser(expr, location=None) parser.allowFallbackExpressionParsing = False ast = parser.parse_expression() parser.assert_end() # first a simple check of the AST if output is None: output = expr res = str(ast) if res != output: print("") print("Input: ", input) print("Result: ", res) print("Expected: ", output) raise DefinitionError("")
def exprCheck(expr, output=None): class Config: c_id_attributes = ["id_attr"] c_paren_attributes = ["paren_attr"] parser = DefinitionParser(expr, location=None, config=Config()) parser.allowFallbackExpressionParsing = False ast = parser.parse_expression() parser.assert_end() # first a simple check of the AST if output is None: output = expr res = str(ast) if res != output: print("") print("Input: ", input) print("Result: ", res) print("Expected: ", output) raise DefinitionError("")
def _check(name, input, idDict, output, key, asTextOutput): if key is None: key = name key += ' ' if name in ('function', 'member'): inputActual = input outputAst = output outputAsText = output else: inputActual = input.format(key='') outputAst = output.format(key='') outputAsText = output.format(key=key) if asTextOutput is not None: outputAsText = asTextOutput # first a simple check of the AST ast = parse(name, inputActual) res = str(ast) if res != outputAst: print("") print("Input: ", input) print("Result: ", res) print("Expected: ", outputAst) raise DefinitionError("") rootSymbol = Symbol(None, None, None, None, None) symbol = rootSymbol.add_declaration(ast, docname="TestDoc", line=42) parentNode = addnodes.desc() signode = addnodes.desc_signature(input, '') parentNode += signode ast.describe_signature(signode, 'lastIsName', symbol, options={}) resAsText = parentNode.astext() if resAsText != outputAsText: print("") print("Input: ", input) print("astext(): ", resAsText) print("Expected: ", outputAsText) raise DefinitionError("") idExpected = [None] for i in range(1, _max_id + 1): if i in idDict: idExpected.append(idDict[i]) else: idExpected.append(idExpected[i - 1]) idActual = [None] for i in range(1, _max_id + 1): # try: id = ast.get_id(version=i) assert id is not None idActual.append(id[len(_id_prefix[i]):]) # except NoOldIdError: # idActual.append(None) res = [True] for i in range(1, _max_id + 1): res.append(idExpected[i] == idActual[i]) if not all(res): print("input: %s" % input.rjust(20)) for i in range(1, _max_id + 1): if res[i]: continue print("Error in id version %d." % i) print("result: %s" % idActual[i]) print("expected: %s" % idExpected[i]) # print(rootSymbol.dump(0)) raise DefinitionError("")