def testParseParens(self):
     # Wide parens.
     self.assertEqual(
         ParseExprFromStr('(阿庆)')[0], ParenExpr(VariableExpr('阿庆')))
     # Narrow parens.
     self.assertEqual(
         ParseExprFromStr('(阿庆)')[0], ParenExpr(VariableExpr('阿庆')))
 def testParseTermExpr(self):
     self.assertEqual(
         ParseExprFromStr('阿庆乘五')[0],
         ArithmeticExpr(VariableExpr('阿庆'), Keyword('乘'),
                        IntegerLiteralExpr(5)))
     self.assertEqual(
         ParseExprFromStr('五除以阿庆')[0],
         ArithmeticExpr(IntegerLiteralExpr(5), Keyword('除以'),
                        VariableExpr('阿庆')))
     self.assertEqual(
         ParseExprFromStr('五除以阿庆乘阿德')[0],
         ArithmeticExpr(
             ArithmeticExpr(IntegerLiteralExpr(5), Keyword('除以'),
                            VariableExpr('阿庆')), Keyword('乘'),
             VariableExpr('阿德')))
 def testParseArithmeticExpr(self):
     self.assertEqual(
         ParseExprFromStr('5加六')[0],
         ArithmeticExpr(IntegerLiteralExpr(5), Keyword('加'),
                        IntegerLiteralExpr(6)))
     self.assertEqual(
         ParseExprFromStr('5加六乘3')[0],
         ArithmeticExpr(
             IntegerLiteralExpr(5), Keyword('加'),
             ArithmeticExpr(IntegerLiteralExpr(6), Keyword('乘'),
                            IntegerLiteralExpr(3))))
     self.assertEqual(
         ParseExprFromStr('5减六减阿庆')[0],
         ArithmeticExpr(
             ArithmeticExpr(IntegerLiteralExpr(5), Keyword('减'),
                            IntegerLiteralExpr(6)), Keyword('减'),
             VariableExpr('阿庆')))
 def testParseConcatExpr(self):
     self.assertEqual(
         ParseExprFromStr('阿庆加油、2、“哈”')[0],
         ConcatExpr([
             ArithmeticExpr(VariableExpr('阿庆'), Keyword('加'),
                            VariableExpr('油')),
             IntegerLiteralExpr(2),
             StringLiteralExpr('哈')
         ]))
 def testParseComparisonExpr(self):
     self.assertEqual(
         ParseExprFromStr('5比6老卵')[0],
         ComparisonExpr(IntegerLiteralExpr(5), Keyword('老卵'),
                        IntegerLiteralExpr(6)))
     self.assertEqual(
         ParseExprFromStr('阿庆加5比6推板')[0],
         ComparisonExpr(
             ArithmeticExpr(VariableExpr('阿庆'), Keyword('加'),
                            IntegerLiteralExpr(5)), Keyword('推板'),
             IntegerLiteralExpr(6)))
     self.assertEqual(
         ParseExprFromStr('阿庆帮阿德一色一样')[0],
         ComparisonExpr(VariableExpr('阿庆'), Keyword('一色一样'),
                        VariableExpr('阿德')))
     self.assertEqual(
         ParseExprFromStr('阿庆加5帮6伐大一样')[0],
         ComparisonExpr(
             ArithmeticExpr(VariableExpr('阿庆'), Keyword('加'),
                            IntegerLiteralExpr(5)), Keyword('伐大一样'),
             IntegerLiteralExpr(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 testParseIdentifier(self):
     self.assertEqual(ParseExprFromStr('阿庆')[0], VariableExpr('阿庆'))
 def testParseStringLiteral(self):
     self.assertEqual(
         ParseExprFromStr('“ 哈  哈   ”')[0], StringLiteralExpr(' 哈  哈   '))
 def testParseInteger(self):
     self.assertEqual(ParseExprFromStr('5')[0], IntegerLiteralExpr(5))
     self.assertEqual(ParseExprFromStr('九')[0], IntegerLiteralExpr(9))
 def testParseConcatExpr(self):
     self.assertEqual(
         ParseExprFromStr('阿庆、2')[0],
         ConcatExpr([VariableExpr('阿庆'),
                     IntegerLiteralExpr(2)]))