diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..354686a --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,20 @@ +# coding: utf-8 +# +# Copyright © 2013 Ejwa Software. All rights reserved. +# +# 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 . + +# This file was intentionally left blank. diff --git a/tests/commented_file.cpp b/tests/commented_file.cpp new file mode 100644 index 0000000..76dcd51 --- /dev/null +++ b/tests/commented_file.cpp @@ -0,0 +1,67 @@ +/* + * Copyright © 2013 Ejwa Software. All rights reserved. + * + * 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 . + */ +#include +#include + +struct Dimensions { + double width; + double height; +}; + +/* + * A class for a rectangle + */ +class Rectangle { + private: + Dimensions dimensions; + public: + Rectangle(Dimensions dimensions); + void print(); +}; + +Rectangle::Rectangle(Dimensions dimensions) { + this->dimensions = dimensions; +} + +void Rectangle::print() { + /* + * Print some stuff (testing comments) + */ + std::cout << "\nCharacteristics of this rectangle"; + std::cout << "\nWidth = " << this->dimensions.width; + std::cout << "\nHeight = " << this->dimensions.height; + std::cout << "\nArea = " << this->dimensions.width * this->dimensions.height << "\n"; // ^2 +} + +int main(int argc, char *argv[]) { + Dimensions dimensions; + + std::cout << "Provide the dimensions of a rectangle\n"; + std::cout << "Width: "; + std::cin >> dimensions.width; + std::cout << "Height: "; + std::cin >> dimensions.height; + + // Create rectanlge and wait for user-input. + Rectangle rectangle(dimensions); + rectangle.print(); + getchar(); + + return 0; +} diff --git a/tests/commented_file.tex b/tests/commented_file.tex new file mode 100644 index 0000000..795b006 --- /dev/null +++ b/tests/commented_file.tex @@ -0,0 +1,72 @@ +% Copyright © 2013 Ejwa Software. All rights reserved. +% +% 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 . + +\documentclass{article} +\usepackage{verbatim} + +\begin{document} +\title{A test for gitinspector} +\author{Ejwa Software} +\maketitle + +\begin{abstract} + Lorem ipsum dolor sit amet, qui morbi a nunc purus, turpis netus et, + faucibus amet porttitor commodo luctus convallis sit, non sociosqu ut felis fusce eros, + mi scelerisque vel tincidunt vivamus aliquet. Urna et commodo ut ipsum integer, + eu nostra etiam lacinia odio praesent quis, facilisi odio, donec erat nunc dictumst et. + Inceptos turpis vestibulum volutpat quis nulla elit, eros dictumst, duis rhoncus sem eget eget diam ultrices. + Pharetra sed aliquam in, ultricies suscipit bibendum vivamus, quo amet. + In nisl pellentesque mus suscipit magna, sem interdum dolores in, dolores risus at aliquet nisl, + tincidunt faucibus. +\end{abstract} + +\section{Introduction} +Sit eros et arcu molestie suspendisse elit, suscipit maecenas quisque purus curabitur vitae suspendisse, +vestibulum nunc morbi viverra id aliquam dolor. Nulla leo lacus id sem, iaculis metus faucibus lorem imperdiet a duis, +ullamcorper dis condimentum diam, ullamcorper massa, vel ac venenatis nisl vitae. Sit in mauris. Lacus mollis quam, +nec in, pellentesque integer nulla sit in sit, erat dolor a lectus dui, sed purus. +Conubia ornare ridiculus interdum duis ut nisl, mauris semper rhoncus. Molestie leo diam lectus non dolor, +adipiscing ut potenti aliquam suscipit torquent, vulputate sit vel cum. Felis et wisi et cras id, +amet cum duis quis magnis urna, egestas et dui tortor, diam tellus. Elit auctor in at, urna nulla posuere, +et blandit sodales porta felis, posuere venenatis. Vel hac neque dictum rhoncus. + +\begin{comment} + Pellentesque vestibulum id, tincidunt blandit. Condimentum sed egestas in sit, + a mattis in in purus erat sit. Sed turpis vestibulum aliquet, turpis ornare ultrices mi, + nisl nulla dis luctus, nec quis. Luctus turpis neque arcu ante donec dui, mauris vel duis id proin consequat, + provident duis integer feugiat blandit neque. Donec lectus sollicitudin at, + \begin{comment} + imperdiet nec elit in dolor lectus platea, ultricies pharetra vel etiam in odio, porta nascetur aenean, + imperdiet nunc libero sit. Pellentesque tincidunt molestie, neque vivamus neque nec accumsan porttitor varius, + \end{comment} % Testing nested comment behaviour + vitae lacinia et molestie integer in vitae, elementum dolor vitae tempor sit, nunc justo praesent. + Facilisis metus scelerisque sit pharetra, dictumst dui incididunt donec eu. +\end{comment} + +\section{Conclusion} +Nec proin cursus consequat consequatur ridiculus mauris, ultrices erat lacus tincidunt velit, +laoreet egestas congue odio vestibulum sollicitudin. Dui luctus malesuada ac velit nec, sit ac, sed dolor vitae in. +Aliquam maecenas, amet sem vitae nulla, nisl eros eleifend, commodo facilisi amet faucibus ut. +Lorem urna est consectetuer mattis lorem, ultricies interdum quam urna et amet turpis. +Ac condimentum leo dolor pellentesque, eu velit massa dictumst cubilia praesent curabitur, est varius, +orci fringilla tortor ut non in. Aliquam sed curabitur eleifend, odio varius et eros dictum et, +%pede vestibulum ut vel. Wisi ipsum potenti dictumst in congue. Feugiat nam nunc cras amet tellus eget, +%cursus fringilla quis dui odio elit turpis, eu felis ac nec diam nibh, facilisis risus vel turpis risus. +Ornare vestibulum diam facilisis porttitor nulla. Penatibus in lacus ac tempus in iaculis, +praesent pede nunc pretium sodales, quisque felis, at vehicula sit, tempor vel lectus arcu porta integer cum. + +\end{document} diff --git a/tests/test_comment.py b/tests/test_comment.py new file mode 100644 index 0000000..66c9082 --- /dev/null +++ b/tests/test_comment.py @@ -0,0 +1,50 @@ +# coding: utf-8 +# +# Copyright © 2013 Ejwa Software. All rights reserved. +# +# 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 . + +from __future__ import unicode_literals +import os +import sys +import unittest2 +import gitinspector.comment + +def __test_extension__(commented_file, extension): + 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: + i = i.decode("utf-8", "replace") + (_, 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 + + return comment_counter + +class TexFileTest(unittest2.TestCase): + def test(self): + comment_counter = __test_extension__("/commented_file.tex", "tex") + self.assertEqual(comment_counter, 30) + +class CppFileTest(unittest2.TestCase): + def test(self): + comment_counter = __test_extension__("/commented_file.cpp", "cpp") + self.assertEqual(comment_counter, 25)