-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_analyze_comment_ratio.py
More file actions
58 lines (54 loc) · 1.34 KB
/
test_analyze_comment_ratio.py
File metadata and controls
58 lines (54 loc) · 1.34 KB
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
from spice.analyzers.count_comment_ratio import count_comment_ratio
import os
def test_count_comment_ratio():
# python
py_code = """
# This is a comment
def foo():
pass # Inline comment
"""
with open("temp_test.py", "w") as f:
f.write(py_code)
assert count_comment_ratio("temp_test.py") == "66.67%"
os.remove("temp_test.py")
# javascript
js_code = """
// This is a comment
function foo() {
return 42; // Inline comment
}
/*
Multi-line
comment
*/
"""
with open("temp_test.js", "w") as f:
f.write(js_code)
assert count_comment_ratio("temp_test.js") == "75.00%"
os.remove("temp_test.js")
# go
go_code = """
// This is a comment
func foo() int {
return 42 // Inline comment
}
/*
Multi-line
comment
*/
"""
with open("temp_test.go", "w") as f:
f.write(go_code)
assert count_comment_ratio("temp_test.go") == "75.00%"
os.remove("temp_test.go")
# ruby
rb_code = """
# This is a comment
def foo
42 # Inline comment
end
"""
with open("temp_test.rb", "w") as f:
f.write(rb_code)
assert count_comment_ratio("temp_test.rb") == "50.00%"
os.remove("temp_test.rb")