2013-07-04 10:10:11 +02:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
2015-09-05 10:27:29 +02:00
|
|
|
# Copyright © 2013-2015 Ejwa Software. All rights reserved.
|
2013-07-04 10:10:11 +02:00
|
|
|
#
|
|
|
|
# This file is part of gitinspector.
|
|
|
|
#
|
|
|
|
# gitinspector is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# gitinspector is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import os
|
2021-02-27 16:50:53 +01:00
|
|
|
import unittest
|
2013-07-04 10:10:11 +02:00
|
|
|
import gitinspector.comment
|
|
|
|
|
2021-02-28 04:39:08 +01:00
|
|
|
|
2013-07-04 10:10:11 +02:00
|
|
|
def __test_extension__(commented_file, extension):
|
2021-02-28 04:39:08 +01:00
|
|
|
base = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
tex_file = open(base + commented_file, "r")
|
|
|
|
tex = tex_file.readlines()
|
|
|
|
tex_file.close()
|
|
|
|
|
|
|
|
is_inside_comment = False
|
|
|
|
comment_counter = 0
|
|
|
|
for i in tex:
|
|
|
|
(_, is_inside_comment) = gitinspector.comment.handle_comment_block(is_inside_comment, extension, i)
|
|
|
|
if is_inside_comment or gitinspector.comment.is_comment(extension, i):
|
|
|
|
comment_counter += 1
|
2013-07-04 10:10:11 +02:00
|
|
|
|
2021-02-28 04:39:08 +01:00
|
|
|
return comment_counter
|
2013-07-04 10:10:11 +02:00
|
|
|
|
|
|
|
|
2021-02-27 16:50:53 +01:00
|
|
|
class TexFileTest(unittest.TestCase):
|
2013-07-04 10:10:11 +02:00
|
|
|
def test(self):
|
2021-02-28 04:39:08 +01:00
|
|
|
comment_counter = __test_extension__("/resources/commented_file.tex", "tex")
|
|
|
|
self.assertEqual(comment_counter, 30)
|
|
|
|
|
2013-07-04 10:10:11 +02:00
|
|
|
|
2021-02-27 16:50:53 +01:00
|
|
|
class CppFileTest(unittest.TestCase):
|
2013-07-04 10:10:11 +02:00
|
|
|
def test(self):
|
2021-02-27 16:50:53 +01:00
|
|
|
comment_counter = __test_extension__("/resources/commented_file.cpp", "cpp")
|
|
|
|
self.assertEqual(comment_counter, 25)
|