-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
141 lines (113 loc) · 4.49 KB
/
tests.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import unittest
import doctestplusplus as dtpp
class DocTestPlusPlusTests(unittest.TestCase):
def setUp(self): pass
def tearDown(self): pass
def testCommonPrefixLen_AllNonEmpty(self):
"""
Test the common prefixes of a few non-empty strings.
"""
instrings = ["Hello World", "Hell on earth", "Helium Balloons"]
self.assertEqual(3, dtpp.find_common_prefix_len(instrings))
def testCommonPrefixLen_AllNonEmptyWithoutCommonPrefixes(self):
"""
Test the common prefixes of a few non-empty strings without any common prefixes
"""
instrings = ["Hello World", "Good Bye World", "Sayonara World"]
self.assertEqual(0, dtpp.find_common_prefix_len(instrings))
def testCommonPrefixLen_WithSomeCommonPrefixes(self):
"""
Test the common prefixes of a few strings where only some of them
match.
"""
instrings = ["Hello World", "Hell on Earth", "Good Bye World", "Sayonara World"]
self.assertEqual(0, dtpp.find_common_prefix_len(instrings))
def testCommonPrefixLen_WithEmptyFewStrings(self):
"""
Test the common prefixes of a few strings where some of them are
empty.
"""
instrings = ["Hello World", "", "", "Hello World"]
self.assertEqual(0, dtpp.find_common_prefix_len(instrings))
def testCommentsInFile_EmptyFile(self):
contents = """ """
comments = [ g for g in dtpp.comments_in_file(contents)]
self.assertEqual(0, len(comments))
def testCommentsInFile_SingleComment(self):
contents = """ /** Comment 1 */ """
comments = [ g for g in dtpp.comments_in_file(contents)]
# should have 1 comment
self.assertEqual(1, len(comments))
comment_text, comment_span = comments[0]
# beginning at offset 1
self.assertEqual(1, comment_span[0])
# and value "* Comment 1 "
self.assertEquals("/** Comment 1 */", comment_text)
def testCommentsInFile_SingleMultiLineComment(self):
contents = \
"""
/**
* First Line
*
* Another line here
*/
"""
comments = [ g for g in dtpp.comments_in_file(contents)]
# should have 1 comment
self.assertEqual(1, len(comments))
comment_text, comment_span = comments[0]
# beginning at offset 9
self.assertEqual(9, comment_span[0])
# and value
self.assertEquals(contents.strip(), comment_text)
def testCommentsInFile_SingleCommentInQuotes(self):
"""
Comments in quotes are not returned.
"""
contents = """ a = "/* no Comment */" """
comments = [ g for g in dtpp.comments_in_file(contents)]
# should have 0 comments
self.assertEqual(0, len(comments))
def testCommentsInFile_SingleCommentInAndOutOfQuotes(self):
"""
Comments in quotes are not returned.
"""
contents = """ a = "/* not a Comment */" /** A Comment Indeed */ """
comments = [ g for g in dtpp.comments_in_file(contents)]
# should have 0 comments
self.assertEqual(1, len(comments))
self.assertEqual("/** A Comment Indeed */", comments[0][0])
def testEvalLineOffsets(self):
lines = "a\nb\nc\nd"
offsets = dtpp.evaluate_file_line_offsets(lines, False)
self.assertEqual([0, 2, 4, 6, 8], offsets)
def testEvalLineOffsetsWithEmptyLines(self):
lines = "a\nb\n\n\nc\nd"
offsets = dtpp.evaluate_file_line_offsets(lines, False)
self.assertEqual([0, 2, 4, 5, 6, 8, 10], offsets)
def testEvalLineOffsetsWithAllEmptyLines(self):
lines = "\n\n\n\n\n"
offsets = dtpp.evaluate_file_line_offsets(lines, False)
self.assertEqual([0, 1, 2, 3, 4, 5, 6], offsets)
#
# Now the hard stuff - testing for actual test blocks inside a comment
#
def testBlocksInComment_CommentWithoutTests(self):
comment = "/* Boring Text */"
tests = [t for t in dtpp.test_blocks_in_comment(comment)]
self.assertEqual(0, len(tests))
def testBlocksInComment_CommentWithSingleTest(self):
comment = """
/**
* A Boring Text
* More Boring test
*
* @test(Test1)
* @endtest
*/
"""
tests = [t for t in dtpp.test_blocks_in_comment(comment)]
self.assertEqual(1, len(tests))
self.assertEqual("", tests[0].test_body)
if __name__ == '__main__':
unittest.main()