-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhitespace_rule_test.py
121 lines (114 loc) · 3.63 KB
/
whitespace_rule_test.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
import test_support
class WhitespaceRuleTest(test_support.TestBase):
def setUp(self):
self.set_default_rules_selection(['WhitespaceRule'])
self.set_default_error_id('whitespace')
self.set_default_error_severity('style')
def test_correct_whitespace(self):
self.assert_colobot_lint_result(
source_file_lines = [
'void Foo()',
'{',
' int x = 0;',
'}',
''
],
expected_errors = [])
def test_whitespace_at_end_of_line(self):
self.assert_colobot_lint_result(
source_file_lines = [
'void Foo()',
'{',
' int x = 0; ',
'}',
''
],
expected_errors = [
{
'msg': 'Whitespace at end of line',
'line': '3'
}
])
def test_tab_character(self):
self.assert_colobot_lint_result(
source_file_lines = [
'void Foo()',
'{',
'\tint x = 0;',
'\t\tint y = 0;',
'}',
''
],
expected_errors = [
{
'msg': 'Tab character is not allowed as whitespace',
'line': '3'
},
{
'msg': 'Tab character is not allowed as whitespace',
'line': '4'
}
])
def test_dos_style_line_endings(self):
self.assert_colobot_lint_result(
source_file_lines = [
'void Foo()\r',
'{\r',
' int x = 0;\r',
'}',
''
],
expected_errors = [
{
'msg': 'File seems to have DOS style line endings',
'line': '1'
}
])
def test_no_newline_at_end_of_file(self):
self.assert_colobot_lint_result(
source_file_lines = [
'void Foo()',
'{',
' int x = 0;',
'}'
],
expected_errors = [
{
'msg': 'File should end with newline',
'line': '3'
}
])
def test_whitespace_error_in_fake_header_mode(self):
self.assert_colobot_lint_result_with_custom_files(
source_files_data = {
# report violations in this file:
'bar.h' : [
'void deleteMe(int* x)',
'{',
' delete x; ',
'}',
''
],
# but not this one:
'baz.h' : [
'int* createMe() ',
'{',
' return new int;',
'}'
],
# and not main file:
'fake_header_sources/bar.cpp': [
'#include "bar.h"',
'#include "baz.h" '
]
},
compilation_database_files = ['fake_header_sources/bar.cpp'],
target_files = ['fake_header_sources/bar.cpp'],
additional_compile_flags = ['-I$TEMP_DIR'],
additional_options = ['-project-local-include-path', '$TEMP_DIR'],
expected_errors = [
{
'msg': "Whitespace at end of line",
'line': '3'
}
])