def test_outputFormat(self): self.syntax_start = "/*" self.syntax_end ='*/' expected = css.cssExtractor(self.testfile) comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end) file = self.testfile.split("/") output = { "metadata": [{ "filename": file[-1], "lang": "CSS", "total_lines": comment_multiline[4], "total_lines_of_comments": comment_multiline[3], "blank_lines": comment_multiline[5], "sloc": comment_multiline[4]-(comment_multiline[3]+comment_multiline[5]) }], "single_line_comment": [], "multi_line_comment": [] } if comment_multiline: try: for idx,i in enumerate(comment_multiline[0]): output['multi_line_comment'].append({"start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx]}) except: pass self.assertEqual(output,expected)
def test_outputFormat(self): """ Check for the output format correctness. """ regex = r"""(?<!["'`])#+\s*(.*)""" syntax_start = "=begin" syntax_end = "=cut" expected = perl.perlExtractor(self.testfile).get_dict() comment_single = readSingleLine(self.testfile, regex) comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) comment_contSingleline = contSingleLines(comment_single) file = self.testfile.split("/") output = { "metadata": { "filename": file[-1], "lang": "Perl", "total_lines": comment_single[1], "total_lines_of_comments": comment_single[3] + comment_multiline[3], "blank_lines": comment_single[2], "sloc": comment_single[1] - (comment_single[3] + comment_multiline[3] + comment_single[2]), }, "single_line_comment": [], "cont_single_line_comment": [], "multi_line_comment": [], } if comment_contSingleline: comment_single = comment_contSingleline[0] if comment_single: for i in comment_single[0]: output["single_line_comment"].append( {"line_number": i[0], "comment": i[1]} ) if comment_contSingleline: for idx, _ in enumerate(comment_contSingleline[1]): output["cont_single_line_comment"].append( { "start_line": comment_contSingleline[1][idx], "end_line": comment_contSingleline[2][idx], "comment": comment_contSingleline[3][idx], } ) if comment_multiline: for idx, _ in enumerate(comment_multiline[0]): output["multi_line_comment"].append( { "start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx], } ) self.assertEqual(output, expected)
def test_output(self): """ Check for the scan correctness. """ syntax_start = "/*" syntax_end = "*/" comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) self.assertTrue(comment_multiline)
def test_output(self): """ Check for the scan correctness. """ regex = r"""(?<!["'`])#+\s*(.*)""" syntax_start = "=begin" syntax_end = "=cut" comment_single = readSingleLine(self.testfile, regex) comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) comment_contSingleline = contSingleLines(comment_single) self.assertTrue(comment_single) self.assertTrue(comment_multiline) self.assertTrue(comment_contSingleline)
def test_output(self): """ Check for the scan correctness. """ regex = r"""(?<![pst'"`]:)\/\/\s*(.*)""" syntax_start = "/*" syntax_end = "*/" comment_single = readSingleLine(self.testfile, regex) comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) comment_contSinglelines = contSingleLines(comment_single) self.assertTrue(comment_single) self.assertTrue(comment_multiline) self.assertTrue(comment_contSinglelines)
def test_outputFormat(self): regex = r'''(\/\/\s*[\w #\.()@+-_*\d]*)''' self.syntax_start = "/*" self.syntax_end ='*/' sign = '//' expected = cpp.cppExtractor(self.testfile) comment_single = readSingleLine(self.testfile,regex,sign) comment_multiline = readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end) comment_contSingleline = contSingleLines(comment_single) file = self.testfile.split("/") output = { "metadata": [{ "filename": file[-1], "lang": "C++", "total_lines": comment_single[1], "total_lines_of_comments": comment_single[3]+comment_multiline[3], "blank_lines": comment_single[2], "sloc": comment_single[1]-(comment_single[3]+comment_multiline[3]+comment_single[2]) }], "single_line_comment": [], "cont_single_line_comment": [], "multi_line_comment": [] } if comment_contSingleline: comment_single = comment_contSingleline[0] if comment_single: for i in comment_single[0]: output['single_line_comment'].append({"line_number" :i[0],"comment": i[1]}) if comment_contSingleline: for idx,i in enumerate(comment_contSingleline[1]): output['cont_single_line_comment'].append({"start_line": comment_contSingleline[1][idx], "end_line": comment_contSingleline[2][idx], "comment": comment_contSingleline[3][idx]}) if comment_multiline: try: for idx,i in enumerate(comment_multiline[0]): output['multi_line_comment'].append({"start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx]}) except: pass self.assertEqual(output,expected)
def test_outputFormat(self): """ Check for the output format correctness. """ syntax_start = "/*" syntax_end = "*/" expected = css.cssExtractor(self.testfile).get_dict() comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) file = self.testfile.split("/") output = { "metadata": { "filename": file[-1], "lang": "CSS", "total_lines": comment_multiline[4], "total_lines_of_comments": comment_multiline[3], "blank_lines": comment_multiline[5], "sloc": comment_multiline[4] - (comment_multiline[3] + comment_multiline[5]), }, "single_line_comment": [], "cont_single_line_comment": [], "multi_line_comment": [], } if comment_multiline: for idx, _ in enumerate(comment_multiline[0]): output["multi_line_comment"].append({ "start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx], }) self.assertEqual(output, expected)
def test_output(self): """ Check for the scan correctness. """ regex = r"""(?<!["'`])#+\s*(.*)""" syntax_single = "'''" syntax_double = '"""' syntax_start = "#=" syntax_end = "=#" comment_multi_single = readMultiLineSame(self.testfile, syntax_single) comment_single = readSingleLine(self.testfile, regex) comment_multi_double = readMultiLineSame(self.testfile, syntax_double) comment_multi_hashEqual = readMultiLineDiff(self.testfile, syntax_start, syntax_end) comment_contSingleline = contSingleLines(comment_single) self.assertTrue(comment_single) self.assertTrue(comment_multi_single) self.assertTrue(comment_multi_double) self.assertTrue(comment_multi_hashEqual) self.assertTrue(comment_contSingleline)
def test_output(self): """ Check for the scan correctness. """ regex1 = r"""(?<!\/)\/\/(?!\/)\s*(.*)""" regex2 = r"""\/\/\/\s*(.*)""" syntax_start = "/*" syntax_end = "*/" comment_single_doubleSlash = readSingleLine(self.testfile, regex1) comment_single_tripleSlash = readSingleLine(self.testfile, regex2) comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) comment_contSingleline1 = dart.contSingleLines( comment_single_doubleSlash) comment_contSingleline2 = dart.contSingleLines( comment_single_tripleSlash) self.assertTrue(comment_single_doubleSlash) self.assertTrue(comment_single_tripleSlash) self.assertTrue(comment_multiline) self.assertTrue(comment_contSingleline1) self.assertTrue(comment_contSingleline2)
def test_outputFormat(self): """ Check for the output format correctness. """ regex1 = r"""(?<!\/)\/\/(?!\/)\s*(.*)""" regex2 = r"""\/\/\/\s*(.*)""" syntax_start = "/*" syntax_end = "*/" expected = dart.dartExtractor(self.testfile).get_dict() comment_single_doubleSlash = readSingleLine(self.testfile, regex1) comment_single_tripleSlash = readSingleLine(self.testfile, regex2) comment_multiline = readMultiLineDiff(self.testfile, syntax_start, syntax_end) comment_contSingleline1 = dart.contSingleLines( comment_single_doubleSlash) comment_contSingleline2 = dart.contSingleLines( comment_single_tripleSlash) file = self.testfile.split("/") output = { "metadata": { "filename": file[-1], "lang": "Dart", "total_lines": comment_single_doubleSlash[1], "total_lines_of_comments": comment_single_doubleSlash[3] + comment_single_tripleSlash[3] + comment_multiline[3], "blank_lines": comment_single_doubleSlash[2], "sloc": comment_single_doubleSlash[1] - (comment_single_doubleSlash[3] + comment_single_tripleSlash[3] + comment_multiline[3] + comment_single_doubleSlash[2]), }, "single_line_comment": [], "cont_single_line_comment": [], "multi_line_comment": [], } if comment_contSingleline1: comment_single_doubleSlash = comment_contSingleline1[0] if comment_contSingleline2: comment_single_tripleSlash = comment_contSingleline2[0] if comment_single_doubleSlash: for i in comment_single_doubleSlash[0]: output["single_line_comment"].append({ "line_number": i[0], "comment": i[1] }) if comment_single_tripleSlash: for i in comment_single_tripleSlash[0]: output["single_line_comment"].append({ "line_number": i[0], "comment": i[1] }) if comment_contSingleline1: for idx, _ in enumerate(comment_contSingleline1[1]): output["cont_single_line_comment"].append({ "start_line": comment_contSingleline1[1][idx], "end_line": comment_contSingleline1[2][idx], "comment": comment_contSingleline1[3][idx], }) if comment_contSingleline2: for idx, _ in enumerate(comment_contSingleline2[1]): output["cont_single_line_comment"].append({ "start_line": comment_contSingleline2[1][idx], "end_line": comment_contSingleline2[2][idx], "comment": comment_contSingleline2[3][idx], }) if comment_multiline: for idx, _ in enumerate(comment_multiline[0]): output["multi_line_comment"].append({ "start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx], }) self.assertEqual(output, expected)