コード例 #1
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #2
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #3
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 def test_parse_unary_double_positive(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (sellingPrice - ++privateDebt)
     }
     """
     parse(input_string)
コード例 #4
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #5
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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 $')
コード例 #6
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 def test_parse_form_single_assignment_money(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (8 - 4.14)
     }
     """
     parse(input_string)
コード例 #7
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #8
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #9
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #10
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #11
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #12
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #13
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #14
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #15
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #16
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #17
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #18
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #19
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #20
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #21
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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'
         )
コード例 #22
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
    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'
            )
コード例 #23
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')
コード例 #24
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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'
         )
コード例 #25
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 def test_parse_unary_positive_and_negative(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = (sellingPrice - +-privateDebt)
     }
     """
     self.assertIsNotNone(parse(input_string))
コード例 #26
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 def test_parse_money_assign(self):
     input_string = """
     form taxOfficeExample {
         "Value residue:" valueResidue: money = 100.00
     }
     """
     self.assertIsNotNone(parse(input_string))
コード例 #27
0
ファイル: shared.py プロジェクト: vdweegen/myriad-ql
 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)
コード例 #28
0
ファイル: shared.py プロジェクト: vdweegen/myriad-ql
 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)
コード例 #29
0
 def create_ast(self, ql_str):
     try:
         return parse(ql_str)
     except Exception as e:
         self.add_message("Parsing:\n    {}".format(e))
コード例 #30
0
ファイル: test_parser.py プロジェクト: vdweegen/myriad-ql
 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')