示例#1
0
    def test_MultiLineCommentInsideLineComment_Complex(self):
        file = "// /* */ /* \n #if test // /* \n //*/ */"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("// /* */ /* \n", FragmentType.Body),
                              (" #if test ", FragmentType.IfStatement),
                              ("// /* \n //*/ */", FragmentType.Body)])
示例#2
0
    def test_IfConditionComplex(self):
        file = "#if !test1 && (!test2 || test3) \n"
        m = FlatModelBuilder.build(file)

        self._check_Model(
            m,
            [("#if !test1 && (!test2 || test3) \n", FragmentType.IfStatement)])
示例#3
0
    def test_Constants(self):
        file = 'string if = "#if", else = "#else", elif = "#elif", endif = "#endif";'
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [(
            'string if = "#if", else = "#else", elif = "#elif", endif = "#endif";',
            FragmentType.Body)])
示例#4
0
    def test_LineCommentInIfLine(self):
        file = "#if x // comment\n body \n #endif\n"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("#if x ", FragmentType.IfStatement),
                              ("// comment\n body \n", FragmentType.Body),
                              (" #endif\n", FragmentType.EndIfStatement)])
示例#5
0
    def test_IfInsideMultilineComment(self):
        file = "/* \n // #if test\n */ #endif\n*/"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("/* \n // #if test\n */", FragmentType.Body),
                              (" #endif\n", FragmentType.EndIfStatement),
                              ("*/", FragmentType.Body)])
示例#6
0
    def test_IfCondition(self):
        file = "#if test1 && test2 || test3\nend"
        m = FlatModelBuilder.build(file)

        self._check_Model(
            m, [("#if test1 && test2 || test3\n", FragmentType.IfStatement),
                ("end", FragmentType.Body)])
示例#7
0
    def test_ElIfConditionSpaces(self):
        file = "    #       elif test1 && test2\n"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [
            ("    #       elif test1 && test2\n", FragmentType.ElIfStatement)
        ])
示例#8
0
    def test_singleBody(self):
        file = "a\n#if DebugTest\nbb\nccc\n#endif\neeee"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("a\n", FragmentType.Body),
                              ("#if DebugTest\n", FragmentType.IfStatement),
                              ("bb\nccc\n", FragmentType.Body),
                              ("#endif\n", FragmentType.EndIfStatement),
                              ("eeee", FragmentType.Body)])
示例#9
0
    def test_IfElseCondition(self):
        file = "#if cond \nifBody\n#else\nelseBody\n#endif"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [
            ("#if cond \n", FragmentType.IfStatement),
            ("ifBody\n", FragmentType.Body),
            ("#else\n", FragmentType.ElseStatement),
            ("elseBody\n", FragmentType.Body),
            ("#endif", FragmentType.EndIfStatement),
        ])
示例#10
0
    def test_embeddedConditions(self):
        file = "#if dt\n line1\n #if sl\n line 2\n #else\n line 3\n #endif\n line 4\n #endif"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("#if dt\n", FragmentType.IfStatement),
                              (" line1\n", FragmentType.Body),
                              (" #if sl\n", FragmentType.IfStatement),
                              (" line 2\n", FragmentType.Body),
                              (" #else\n", FragmentType.ElseStatement),
                              (" line 3\n", FragmentType.Body),
                              (" #endif\n", FragmentType.EndIfStatement),
                              (" line 4\n", FragmentType.Body),
                              (" #endif", FragmentType.EndIfStatement)])
示例#11
0
 def clean_file(self, file, apply_changes=True):
     encoding = self._read_encoding(file)
     with open(file, 'r', encoding=encoding) as fr:
         data = fr.read()
     model = FlatModelBuilder.build(data)
     result = self._clean(model)
     if result is not None:
         result.file = file
         if result.error is None:
             result.total_lines = LineCounter.count_text(
                 data) - LineCounter.count_text(result.text)
     if apply_changes and (result is not None and result.error is None):
         with open(file, 'w', encoding=encoding) as fw:
             fw.write(result.text)
     return result
示例#12
0
    def test_Comment2(self):
        file = "// #if test\n"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("// #if test\n", FragmentType.Body)])
示例#13
0
    def test_singleLineFile(self):
        file = "abc\n"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("abc\n", FragmentType.Body)])
示例#14
0
    def test_emptyFile(self):
        file = ""
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [])
示例#15
0
    def test_LineCommentEndIfEOF(self):
        file = "//#if x\n//body\n//#endif"
        m = FlatModelBuilder.build(file)

        self._check_Model(m,
                          [("//#if x\n//body\n//#endif", FragmentType.Body)])
示例#16
0
    def test_IfNotCondition(self):
        file = "#if!test1 && test2\n"
        m = FlatModelBuilder.build(file)

        self._check_Model(m,
                          [("#if!test1 && test2\n", FragmentType.IfStatement)])
示例#17
0
    def test_MultilineComment(self):
        file = "/* test*/\n"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("/* test*/\n", FragmentType.Body)])
示例#18
0
    def test_LineCommentInsideMultilineComment(self):
        file = "/* \n // test \n */end"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [("/* \n // test \n */end", FragmentType.Body)])
示例#19
0
    def test_IfConditionSimple(self):
        file = " #if   test1 \nendif"
        m = FlatModelBuilder.build(file)

        self._check_Model(m, [(" #if   test1 \n", FragmentType.IfStatement),
                              ("endif", FragmentType.Body)])