Exemplo n.º 1
0
 def test_parse_simple_form_no_name(self):
     input_string = """form  {
                         "Did you sell a house in 2010?" hasSoldHouse: boolean
                    }"""
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Form should always have a name')
Exemplo n.º 2
0
 def test_parse_simple_form_missing_right_curly(self):
     input_string = """form example {
                         "Did you sell a house in 2010?" hasSoldHouse: boolean
                    """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Form needs a right curly after its statements')
Exemplo n.º 3
0
 def test_parse_unary_double_positive(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (sellingPrice - ++privateDebt)
     }
     """
     parse(input_string)
Exemplo n.º 4
0
 def test_parse_simple_form_missing_left_curly(self):
     input_string = """form example
                         "Did you sell a house in 2010?" hasSoldHouse: boolean
                    }"""
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Form needs a left curly after the name')
Exemplo n.º 5
0
 def test_parse_simple_form_invalid_name(self):
     input_string = """form $$$$$ {
                         "Did you sell a house in 2010?" hasSoldHouse: boolean
                    }"""
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Form is not allowed to contain $')
Exemplo n.º 6
0
 def test_parse_form_single_assignment_money(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (8 - 4.14)
     }
     """
     parse(input_string)
Exemplo n.º 7
0
 def test_parse_form_empty_if(self):
     input_string = """
     form taxOfficeExample {
         if (hasSoldHouse) { }
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Empty if block should not be possible')
Exemplo n.º 8
0
 def test_parse_form_name_reserved_5(self):
     input_string = """
     form "acbc" {
         "Value residue:" valueResidue: money = 100.00
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('"" not allowed')
Exemplo n.º 9
0
 def test_parse_form_name_reserved_4(self):
     input_string = """
     form else {
         "Value residue:" valueResidue: money = 100.00
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('else is reserved')
Exemplo n.º 10
0
 def test_parse_form_single_assignment_missing_expression(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money =
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Assignment needs an expression')
Exemplo n.º 11
0
 def test_parse_form_single_single_field_unknown_type(self):
     input_string = """
     form taxOfficeExample {
         "Did you sell a house in 2010?" hasSoldHouse: magic
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('This type should not be recognized as valid')
Exemplo n.º 12
0
 def test_parse_switched_order_of_operator(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (sellingPrice =! privateDebt)
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Switched operator order is not allowed')
Exemplo n.º 13
0
 def test_parse_form_single_single_field_incorrect_question(self):
     input_string = """
     form taxOfficeExample {
         Did you sell a house in 2010? hasSoldHouse: string
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Question title needs to have quotes surrounding it')
Exemplo n.º 14
0
 def test_parse_form_single_assignment_missing_identifier(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" : money  = selling - buying
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Assignment needs an identifier')
Exemplo n.º 15
0
 def test_parse_form_single_assignment_missing_title(self):
     input_string = """
     form taxOfficeExample {
          hasSold : money  = selling - buying
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Assignment needs a title')
Exemplo n.º 16
0
 def test_parse_form_single_assignment_missing_type(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue:  = selling - buying
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Assignment needs a type')
Exemplo n.º 17
0
 def test_parse_form_single_assignment_missing_equals(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money  (sellingPrice - privateDebt)
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Assignment needs an assignment literal')
Exemplo n.º 18
0
 def test_parse_form_single_single_field_wrong_type_declaration(self):
     input_string = """
     form taxOfficeExample {
         "Did you sell a house in 2010?" hasSoldHouse boolean
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail(
             'Field should have a colon denoting the type after its name')
Exemplo n.º 19
0
 def test_parse_form_if_invalid_expression_and(self):
     input_string = """
     form taxOfficeExample {
         if (a & a) {
             "Did you sell a house in 2010?" hasSoldHouse: boolean
         }
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('A singular & should not be recognized')
Exemplo n.º 20
0
 def test_parse_form_if_invalid_expression_or(self):
     input_string = """
     form taxOfficeExample {
         if (a | a) {
             "Did you sell a house in 2010?" hasSoldHouse: boolean
         }
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('a | a is an invalid expression')
Exemplo n.º 21
0
 def test_parse_form_if_missing_left_parenthesis(self):
     input_string = """
     form taxOfficeExample {
         if abc) {
             "Did you sell a house in 2010?" hasSoldHouse: boolean
         }
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail(
             'If statement needs to have a parenthesis next to the expression'
         )
Exemplo n.º 22
0
    def test_parse_form_if_missing_right_curly(self):
        input_string = """
        form taxOfficeExample {
            if (abc) {
                "Did you sell a house in 2010?" hasSoldHouse: boolean

        }
        """
        with self.assertRaises(ParseException):
            parse(input_string)
            self.fail(
                'If statement needs to have a curly bracket surrounding the statements'
            )
Exemplo n.º 23
0
 def test_parse_form_if_else_inside(self):
     input_string = """
     form taxOfficeExample {
         if (abc) {
             else {
                 "Did you sell a house in 2010?" hasSoldHouse: boolean
             }
         }
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('An else statements needs to have an if preceding it')
Exemplo n.º 24
0
 def test_parse_form_if_empty_expression(self):
     input_string = """
     form taxOfficeExample {
         if () {
             "Did you sell a house in 2010?" hasSoldHouse: boolean
         }
     }
     """
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail(
             'If statement needs to have an expression inside the parenthesis'
         )
Exemplo n.º 25
0
 def test_parse_unary_positive_and_negative(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (sellingPrice - +-privateDebt)
     }
     """
     self.assertIsNotNone(parse(input_string))
Exemplo n.º 26
0
 def test_parse_money_assign(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = 100.00
     }
     """
     self.assertIsNotNone(parse(input_string))
Exemplo n.º 27
0
 def apply_evaluate(self, input_string):
     form_node = parse(input_string)
     errors = self.acquire_identifiers(form_node)
     self.assertEqual(len(errors), 0,
                      "There are multiple declarations of a field.")
     type_errors = self.check_type(form_node)
     self.assertEqual(len(type_errors), 0,
                      "There were type errors {}".format(type_errors))
     return self.evaluate(form_node)
Exemplo n.º 28
0
 def apply_type_checking(self, input_string):
     form_node = parse(input_string)
     errors = self.acquire_identifiers(form_node)
     self.assertEqual(len(errors), 0,
                      "There are multiple declarations of a field.")
     return self.check_type(form_node)
Exemplo n.º 29
0
 def create_ast(self, ql_str):
     try:
         return parse(ql_str)
     except Exception as e:
         self.add_message("Parsing:\n    {}".format(e))
Exemplo n.º 30
0
 def test_parse_simple_empty_form(self):
     input_string = "form taxOfficeExample {}"
     with self.assertRaises(ParseException):
         parse(input_string)
         self.fail('Empty form block should not be possible')