Exemplo n.º 1
0
 def testParseComparisonExpr(self):
     self.assertEqual(
         ParseExprFromStr('5比6大')[0],
         ComparisonExpr(LiteralExpr(Token(TK_INTEGER_LITERAL, 5)),
                        Keyword('大'),
                        LiteralExpr(Token(TK_INTEGER_LITERAL, 6))))
     self.assertEqual(
         ParseExprFromStr('老王加5比6小')[0],
         ComparisonExpr(
             ArithmeticExpr(VariableExpr(Token(TK_IDENTIFIER, '老王')),
                            Keyword('加'),
                            LiteralExpr(Token(TK_INTEGER_LITERAL, 5))),
             Keyword('小'), LiteralExpr(Token(TK_INTEGER_LITERAL, 6))))
     self.assertEqual(
         ParseExprFromStr('老王跟老刘一样一样的')[0],
         ComparisonExpr(VariableExpr(Token(TK_IDENTIFIER, '老王')),
                        Keyword('一样一样的'),
                        VariableExpr(Token(TK_IDENTIFIER, '老刘'))))
     self.assertEqual(
         ParseExprFromStr('老王加5跟6不是一样一样的')[0],
         ComparisonExpr(
             ArithmeticExpr(VariableExpr(Token(TK_IDENTIFIER, '老王')),
                            Keyword('加'),
                            LiteralExpr(Token(TK_INTEGER_LITERAL, 5))),
             Keyword('不是一样一样的'), LiteralExpr(Token(TK_INTEGER_LITERAL, 6))))
Exemplo n.º 2
0
 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)
                    ))
Exemplo n.º 3
0
 def testParsingComparison(self):
     self.assertEquals(ParseToAst('唠唠:2比5大。'), [
         Statement(
             STMT_SAY,
             ComparisonExpr(IntegerLiteralExpr(2), Keyword('大'),
                            IntegerLiteralExpr(5)))
     ])
Exemplo n.º 4
0
 def DisabledTestParsingComparison(self):
   self.assertEquals(
       ParseToAst(u'唠唠:2比5大。'),
       [Statement(
           STMT_SAY,
           ComparisonExpr(2, 'GT', 5)
       )])
Exemplo n.º 5
0
 def testParsingComparison(self):
     self.assertEquals(ParseToAst('唠唠:2比5大。'), [
         Statement(
             STMT_SAY,
             ComparisonExpr(LiteralExpr(Token(TK_INTEGER_LITERAL, 2)),
                            Keyword('大'),
                            LiteralExpr(Token(TK_INTEGER_LITERAL, 5))))
     ])
Exemplo n.º 6
0
 def testParseConditional(self):
     self.assertEqual(
         ParseStmtFromStr('寻思:老王比五大?要行咧就唠唠:老王。')[0],
         Statement(
             STMT_CONDITIONAL,
             (
                 ComparisonExpr(VariableExpr('老王'), Keyword('大'),
                                IntegerLiteralExpr(5)),
                 # then-branch
                 Statement(STMT_SAY, VariableExpr('老王')),
                 # else-branch
                 None)))
Exemplo n.º 7
0
 def testParseConditional(self):
     self.assertEqual(
         ParseStmtFromStr('寻思:老王比五大?要行咧就唠唠:老王。')[0],
         Statement(
             STMT_CONDITIONAL,
             (
                 ComparisonExpr(VariableExpr(Token(TK_IDENTIFIER, '老王')),
                                Keyword('大'),
                                LiteralExpr(Token(TK_INTEGER_LITERAL, 5))),
                 # then-branch
                 Statement(STMT_SAY, VariableExpr(Token(
                     TK_IDENTIFIER, '老王'))),
                 # else-branch
                 None)))