Пример #1
0
    def test_conditionalIf(self):
        if_expr = AST.VarNode("var")
        if_block_question = AST.QuestionNode("q?", "var", AST.BoolTypeNode())
        if_block = AST.BlockNode([if_block_question])
        if_cond = AST.IfNode(if_expr, if_block)

        cond_str = 'if (var) { "q?" var : boolean }'
        self.validate_node(self.cond_parser, cond_str, if_cond)

        self.check_parse_exception(self.cond_parser, 'if (var) {',
                                   pp.ParseException)
Пример #2
0
    def test_parse_form(self):
        form1 = """
                form TestForm {
                    "question1?" var1 : money
                    if (var1 > 200) {
                        "question2?" var2 : string
                    }
                }
                """

        q1 = AST.QuestionNode("question1?", "var1", AST.MoneyTypeNode())
        q2 = AST.QuestionNode("question2?", "var2", AST.StringTypeNode())
        expr = AST.GTNode(AST.VarNode("var1"), AST.IntNode(int("200")))
        if_block = AST.IfNode(expr, AST.BlockNode([q2]))
        form_block = AST.BlockNode([q1, if_block])
        form_node = AST.FormNode("TestForm", form_block)
        form_node = AST.QuestionnaireAST(form_node)
        self.validate_node(self.parser.grammar, form1, form_node)

        form2 = """
                form TestForm {
                    "question1?" var1 : money
                    if (var1 > 200) {
                        "question2?" var2 : string
                    }
                    else {
                        "question1?" var1 : money
                    }
                    "question2?" var2 : string
                }
                """

        if_else_block = AST.IfElseNode(expr, AST.BlockNode([q2]),
                                       AST.BlockNode([q1]))
        form_block2 = AST.BlockNode([q1, if_else_block, q2])
        form_node = AST.FormNode("TestForm", form_block2)
        form_node = AST.QuestionnaireAST(form_node)
        self.validate_node(self.parser.grammar, form2, form_node)