def testParsingFuncCallWithParam(self): self.assertEqual(ParseToAst('整【阶乘】(五)。'), [ Statement( STMT_CALL, CallExpr(Token(TK_IDENTIFIER, '阶乘'), [LiteralExpr(Token(TK_INTEGER_LITERAL, 5))])) ])
def testParseCallExpr(self): self.assertEqual( ParseExprFromStr('整老王')[0], CallExpr(Token(TK_IDENTIFIER, '老王'), [])) self.assertEqual( ParseExprFromStr('整老王(5)')[0], CallExpr(Token(TK_IDENTIFIER, '老王'), [LiteralExpr(Token(TK_INTEGER_LITERAL, 5))])) self.assertEqual( ParseExprFromStr('整老王(6)')[0], CallExpr(Token(TK_IDENTIFIER, '老王'), [LiteralExpr(Token(TK_INTEGER_LITERAL, 6))])) self.assertEqual( ParseExprFromStr('整老王(老刘,6)')[0], CallExpr(Token(TK_IDENTIFIER, '老王'), [ VariableExpr(Token(TK_IDENTIFIER, '老刘')), LiteralExpr(Token(TK_INTEGER_LITERAL, 6)) ])) self.assertEqual( ParseExprFromStr('整老王(“你”,老刘,6)')[0], CallExpr(Token(TK_IDENTIFIER, '老王'), [ LiteralExpr(Token(TK_STRING_LITERAL, '你')), VariableExpr(Token(TK_IDENTIFIER, '老刘')), LiteralExpr(Token(TK_INTEGER_LITERAL, 6)) ])) self.assertEqual( ParseExprFromStr('整老王(“你”,老刘,6)')[0], CallExpr(Token(TK_IDENTIFIER, '老王'), [ LiteralExpr(Token(TK_STRING_LITERAL, '你')), VariableExpr(Token(TK_IDENTIFIER, '老刘')), LiteralExpr(Token(TK_INTEGER_LITERAL, 6)) ]))
def testParseCallExpr(self): self.assertEqual(ParseExprFromStr('整老王')[0], CallExpr('老王', [])) self.assertEqual( ParseExprFromStr('整老王(5)')[0], CallExpr('老王', [IntegerLiteralExpr(5)])) self.assertEqual( ParseExprFromStr('整老王(6)')[0], CallExpr('老王', [IntegerLiteralExpr(6)])) self.assertEqual( ParseExprFromStr('整老王(老刘,6)')[0], CallExpr( '老王', [VariableExpr('老刘'), IntegerLiteralExpr(6)])) self.assertEqual( ParseExprFromStr('整老王(“你”,老刘,6)')[0], CallExpr('老王', [ StringLiteralExpr('你'), VariableExpr('老刘'), IntegerLiteralExpr(6) ])) self.assertEqual( ParseExprFromStr('整老王(“你”,老刘,6)')[0], CallExpr('老王', [ StringLiteralExpr('你'), VariableExpr('老刘'), IntegerLiteralExpr(6) ]))
def testParsingFuncCallWithParam(self): self.assertEqual( ParseToAst('整【阶乘】(五)。'), [Statement(STMT_CALL, CallExpr('阶乘', [IntegerLiteralExpr(5)]))])