Ejemplo n.º 1
0
 def test_parenthesized_expression_application(self):
     inputData = "(a) b c"
     expected = HApplication(
         HExpression(HApplication(HExpression(HVariable("a")), [])),
         [HExpression(HVariable("b")),
          HExpression(HVariable("c"))])
     result = parse(inputData)
     self.assertEqual(expected, result)
Ejemplo n.º 2
0
 def test_simple_expression_application(self):
     inputData = "a b c"
     expected = HApplication(
         HExpression(HVariable("a")),
         [HExpression(HVariable("b")),
          HExpression(HVariable("c"))])
     result = parse(inputData)
     self.assertEqual(expected, result)
Ejemplo n.º 3
0
 def test_simple_module(self):
     inputData = """
     f = map succ
     """
     expected = HModule(None, None, None, [
         HDeclaration(
             'f',
             HApplication(HExpression(HVariable('map')),
                          [HExpression(HVariable('succ'))]))
     ])
     result = parse(inputData, start='module')
     self.assertEqual(expected, result)
Ejemplo n.º 4
0
 def test_deeply_parenthesized_parameter_application(self):
     inputData = "a (b (c d)) e"
     expected = HApplication(HExpression(HVariable("a")), [
         HExpression(
             HApplication(HExpression(HVariable("b")), [
                 HExpression(
                     HApplication(HExpression(HVariable("c")),
                                  [HExpression(HVariable("d"))]))
             ])),
         HExpression(HVariable("e"))
     ])
     result = parse(inputData)
     self.assertEqual(expected, result)
Ejemplo n.º 5
0
 def test_infix_operator(self):
     inputData = "a > 15"
     expected = HApplication(
         HOperator(">"),
         [HExpression(HVariable("a")),
          HExpression(HValue(HNumber("15")))])
     result = parse(inputData)
     self.assertEqual(expected, result)
Ejemplo n.º 6
0
 def test_comprehension_with_two_productions_and_one_condition(self):
     inputData = "[x | x <- [1..], y <- [1, 3..11], x == 3]"
     expected = HApplication(
         HExpression(
             HValue(
                 HListComprehension(
                     HApplication(HExpression(HVariable("x")), []), [
                         HListComprehensionProduction(
                             HPattern("x"),
                             HApplication(
                                 HExpression(
                                     HValue(
                                         HRange(
                                             HApplication(
                                                 HExpression(
                                                     HValue(HNumber("1"))),
                                                 []), None, None))), [])),
                         HListComprehensionProduction(
                             HPattern("y"),
                             HApplication(
                                 HExpression(
                                     HValue(
                                         HRange(
                                             HApplication(
                                                 HExpression(
                                                     HValue(HNumber("1"))),
                                                 []),
                                             HApplication(
                                                 HExpression(
                                                     HValue(HNumber("11"))),
                                                 []),
                                             HApplication(
                                                 HExpression(
                                                     HValue(HNumber("3"))),
                                                 [])))), [])),
                         HListComprehensionCondition(
                             HApplication(HOperator("=="), [
                                 HExpression(HVariable("x")),
                                 HExpression(HValue(HNumber("3")))
                             ]))
                     ]))), [])
     result = parse(inputData)
     self.assertEqual(expected, result)
     result = parse(inputData)
     self.assertEqual(expected, result)
Ejemplo n.º 7
0
 def test_simple_comprehension(self):
     inputData = """[x | x <- [1..]]"""
     expected = HApplication(
         HExpression(
             HValue(
                 HListComprehension(
                     HApplication(HExpression(HVariable("x")), []), [
                         HListComprehensionProduction(
                             HPattern("x"),
                             HApplication(
                                 HExpression(
                                     HValue(
                                         HRange(
                                             HApplication(
                                                 HExpression(
                                                     HValue(HNumber("1"))),
                                                 []), None, None))), []))
                     ]))), [])
     result = parse(inputData)
     self.assertEqual(expected, result)