aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_comment.py
blob: e1e94c6df0fcc5222f978128dd85e2d1542342cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import unittest

from pykss import comment


class CommentMethodTestCase(unittest.TestCase):

    def test_detects_single_line_comment_syntax(self):
        self.assertTrue(comment.is_single_line_comment('// yuuuuup'))
        self.assertFalse(comment.is_single_line_comment('nooooope'))

    def test_detects_start_of_multi_line_comment_syntax(self):
        self.assertTrue(comment.is_multi_line_comment_start('/* yuuuuup'))
        self.assertFalse(comment.is_multi_line_comment_start('nooooope'))

    def test_detects_end_of_multi_line_comment_syntax(self):
        self.assertTrue(comment.is_multi_line_comment_end(" yuuuuup */"))
        self.assertFalse(comment.is_multi_line_comment_end("nooooope"))

    def test_parses_the_single_line_comment_syntax(self):
        self.assertEqual(comment.parse_single_line("// yuuuuup"), ' yuuuuup')

    def test_parses_the_multi_line_comment_syntax(self):
        self.assertEqual(comment.parse_multi_line('/* yuuuup */'), ' yuuuup')


class CommentParserTestCase(unittest.TestCase):

    def setUp(self):
        text = os.path.join(os.path.dirname(__file__), 'fixtures', 'comments.txt')
        self.comments = comment.CommentParser(text).blocks

    def test_finds_single_line_comment_styles(self):
        expected = """
This comment block has comment identifiers on every line.

Fun fact: this is Kyle's favorite comment syntax!
        """
        self.assertTrue(expected.strip() in self.comments)

    def test_finds_block_style_comment_styles(self):
        expected = """
This comment block is a block-style comment syntax.

There's only two identifier across multiple lines.
        """
        self.assertTrue(expected.strip() in self.comments)

        expected = """
This is another common multi-line comment style.

It has stars at the begining of every line.
        """
        self.assertTrue(expected.strip() in self.comments)

    def test_handles_mixed_styles(self):
        expected = "This comment has a /* comment */ identifier inside of it!"
        self.assertTrue(expected.strip() in self.comments)

        expected = 'Look at my //cool// comment art!'
        self.assertTrue(expected.strip() in self.comments)

    def test_handles_indented_comments(self):
        self.assertTrue('Indented single-line comment.' in self.comments)
        self.assertTrue('Indented block comment.' in self.comments)

    def test_handles_indented_example(self):
        expected = """
This comment has a indented example
<div>
    <div></div>
</div>
        """
        self.assertTrue(expected.strip() in self.comments)