Exemplo n.º 1
0
 def testDoubleEscape(self):
     lines = ['"\\\\" /* test(); */\n']
     cf = CommentFilter()
     self.assertEquals(['"\\\\"'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertFalse(cf.in_comment())
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 2
0
 def testQuoteCharLiteral(self):
     lines = ["if (*qexeanf == '\"') /* test(); */\n"]
     cf = CommentFilter()
     self.assertEquals(["if (*qexeanf == '\"')"],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertFalse(cf.in_comment())
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 3
0
 def testLineCommentInStringLineContinuation(self):
     lines = ["\"xxx\\\n", "// no comment\";\n"]
     cf = CommentFilter()
     self.assertEquals(["\"xxx\\", "// no comment\";"],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertFalse(cf.in_comment())
     self.assertEquals(0, cf.lines_with_comment())
Exemplo n.º 4
0
 def testBlockCommentAfterContent(self):
     lines = ["test(); /* ...", "... */ test();\n"]
     cf = CommentFilter()
     self.assertEquals(["test();", "test();"],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertFalse(cf.in_comment())
     self.assertEquals(2, cf.lines_with_comment())
Exemplo n.º 5
0
 def testUnclosedString(self):
     lines = ["\"", "/* ...", "... */ test();\n"]
     cf = CommentFilter()
     self.assertEquals(["\"", "", "test();"],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertFalse(cf.in_comment())
     self.assertEquals(2, cf.lines_with_comment())
Exemplo n.º 6
0
 def testLineCommentInBlockComment(self):
     lines = [
         '/*//cPD->prot("______")->prot(C_EingabeKnoten::toString(&ele))->endl();;*/',
         'test();'
     ]
     cf = CommentFilter()
     self.assertEquals(['', 'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 7
0
 def testSomeBug1(self):
     lines = [
         "/******************************************************** WBLEIF.H ***/\n",
         'test();'
     ]
     cf = CommentFilter()
     self.assertEquals(['', 'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertFalse(cf.in_comment())
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 8
0
    def testSomeBug(self):
        lines = [
            "#define ORACLE_8i   /////// NUR ZUM TEST! MUSS UEBER STUDIO EINGESCHLEUST WERDEN\n",
            "#define OCI_BTC_ERROR                  (100000)\n"
        ]

        cf = CommentFilter()
        self.assertEquals([
            "#define ORACLE_8i",
            "#define OCI_BTC_ERROR                  (100000)"
        ], map(string.strip, list(cf.filter(iter(lines)))))
        self.assertFalse(cf.in_comment())
        self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 9
0
 def _process_normalizing(self, repair_path, intermediate_result, input_file, output_file):
     normalizer = IncludeDirectiveNormalizer(DefaultProjectFile(path_rel_to_root_unix=repair_path, 
             local_repository_root=self._local_source_resource_resolver.get_base_paths()[0]), 
                                             self._include_canonicalizer_factory,
                                             filemap_factory_func=self._filemap_factory.get_filemap)
     comment_filter = CommentFilter()
     if self.__skip_comments:
         filtered_input_file = comment_filter.filter(input_file)
     else:
         filtered_input_file = input_file
     for line in filtered_input_file:
         include_spec = normalizer.get_include_specification(line)
         if include_spec:
             (_include_spec_type, included_resource) = include_spec
             # TODO output rel_to_root if under root
             print >>self.__output_file, "%s,%s" % (repair_path, included_resource.name())
     return (normalizer.get_included_files(), normalizer.get_statistics_dict())
Exemplo n.º 10
0
 def _process_normalizing(self, repair_path, intermediate_result, input_file, output_file):
     normalizer = IncludeDirectiveNormalizer(DefaultProjectFile(path_rel_to_root_unix=repair_path, 
             local_repository_root=self._local_source_resource_resolver.get_base_paths()[0]), 
                                             self._include_canonicalizer_factory,
                                             filemap_factory_func=self._filemap_factory.get_filemap)
     # TODO or only create the iterator here? But this would not allow to return the statistics...
     if self.__skip_comments:
         comment_filter = CommentFilter()
         filtered_input_file = comment_filter.filter(input_file)
     else:
         filtered_input_file = input_file
     self.__include_map[repair_path] = tuple(ifilter(None, imap(normalizer.get_include_specification, filtered_input_file)))
     
     statistics_dict = normalizer.get_statistics_dict()
     if self.__skip_comments:
         DictTools.merge_dict(statistics_dict, comment_filter.get_statistics_dict(), value_merge_func=None)
     self.__logger.debug("%s includes files %s" % (repair_path, tuple(normalizer.get_included_files())))
     return (normalizer.get_included_files(), statistics_dict)
Exemplo n.º 11
0
 def test8(self):
     lines = ['/* ... */ /* */', 'test();']
     cf = CommentFilter()
     self.assertEquals(['', 'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 12
0
 def test4(self):
     lines = ['//#include <test> // lalala']
     cf = CommentFilter()
     self.assertEquals([''], map(string.strip,
                                 list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 13
0
 def testIllegalNestedComment(self):
     lines = ['/*', '/* #include <test> */', '*/', 'test();']
     cf = CommentFilter()
     self.assertEquals(['', '', '*/', 'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(2, cf.lines_with_comment())
Exemplo n.º 14
0
 def testBlockCommentInStringQuoted(self):
     lines = ['printf("\\"/*");', 'test();']
     cf = CommentFilter()
     self.assertEquals(['printf("\\"/*");', 'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(0, cf.lines_with_comment())
Exemplo n.º 15
0
 def testStringInBlockComment(self):
     lines = ['/* " */ test();']
     cf = CommentFilter()
     self.assertEquals(['test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 16
0
 def test9(self):
     lines = ['#include /* ... */ <test>']
     cf = CommentFilter()
     self.assertEquals(['#include  <test>'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 17
0
 def test11(self):
     lines = ['/*', '#include <test>', '*/', 'test();']
     cf = CommentFilter()
     self.assertEquals(['', '', '', 'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(3, cf.lines_with_comment())
Exemplo n.º 18
0
 def testUnicode(self):
     lines = [u'/* ... */', u'test();']
     cf = CommentFilter()
     self.assertEquals([u'', u'test();'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 19
0
 def testBlockCommentStartInBlockComment(self):
     lines = ['/* /* */', '#include <test>']
     cf = CommentFilter()
     self.assertEquals(['', '#include <test>'],
                       map(string.strip, list(cf.filter(iter(lines)))))
     self.assertEquals(1, cf.lines_with_comment())
Exemplo n.º 20
0
'''
Created on 18.02.2012

@author: SIGIESEC
'''
from cpp.cpp_util import CommentFilter
import logging
import sys

if __name__ == '__main__':
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
    cf = CommentFilter()
    for x in cf.filter(sys.stdin):
        print x,