Example #1
0
 def test_infinite_range(self):
     inputData = "[1..]"
     expected = HApplication(
         HExpression(
             HValue(
                 HRange(HApplication(HExpression(HValue(HNumber("1"))), []),
                        None, None))), [])
     result = parse(inputData)
     self.assertEqual(expected, result)
Example #2
0
 def test_list_enumeration(self):
     inputData = "[1, 2, 3, 4]"
     expected = HApplication(
         HExpression(
             HValue(
                 HListEnumeration([
                     HApplication(HExpression(HValue(HNumber("1"))), []),
                     HApplication(HExpression(HValue(HNumber("2"))), []),
                     HApplication(HExpression(HValue(HNumber("3"))), []),
                     HApplication(HExpression(HValue(HNumber("4"))), [])
                 ]))), [])
     result = parse(inputData)
     self.assertEqual(expected, result)
Example #3
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)
Example #4
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)
Example #5
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)
Example #6
0
 def test_numerical_value(self):
     inputData = "6"
     expected = HApplication(HExpression(HValue(HNumber("6"))), [])
     result = parse(inputData)
     self.assertEqual(expected, result)