countloc 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +9 -0
- data/lib/countloc.rb +128 -40
- data/test/tc_cpp.rb +122 -0
- data/test/tc_python.rb +112 -0
- data/test/tc_ruby.rb +26 -24
- data/test/ts_countloc.rb +2 -0
- metadata +4 -2
data/README
CHANGED
@@ -60,6 +60,15 @@ To export the results to a csv file:
|
|
60
60
|
|
61
61
|
|
62
62
|
== Release Notes
|
63
|
+
=== Release 0.3.0:
|
64
|
+
Features
|
65
|
+
* Added support for generating LOC metrics for languages other than Ruby.
|
66
|
+
Supported languages: Ruby, Python, C, C++, C#, Java and any language that
|
67
|
+
shares the same commenting style as either of these languages.
|
68
|
+
|
69
|
+
Bugfixes:
|
70
|
+
* Added documentation on supported options for CountLOC.countloc()
|
71
|
+
|
63
72
|
=== Release 0.2.1:
|
64
73
|
Features
|
65
74
|
* None
|
data/lib/countloc.rb
CHANGED
@@ -31,7 +31,7 @@ require 'time'
|
|
31
31
|
#
|
32
32
|
module CountLOC
|
33
33
|
|
34
|
-
VERSION = '0.
|
34
|
+
VERSION = '0.3.0'
|
35
35
|
|
36
36
|
# Class that gathers the metrics.
|
37
37
|
#
|
@@ -42,11 +42,33 @@ module CountLOC
|
|
42
42
|
attr_reader :name
|
43
43
|
attr_accessor :code, :comments, :blank, :lines
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
COMMENT_PATTERNS = {
|
46
|
+
:ruby => {
|
47
|
+
:single_line_full => /^\s*#/,
|
48
|
+
:single_line_mixed => /#/,
|
49
|
+
:multiline_begin => /=begin(\s|$)/,
|
50
|
+
:multiline_end => /=end(\s|$)/,
|
51
|
+
:blank_line => /^\s*$/
|
52
|
+
},
|
53
|
+
|
54
|
+
:python => {
|
55
|
+
:single_line_full => /^\s*#/,
|
56
|
+
:single_line_mixed => /#/,
|
57
|
+
:multiline_begin => /^\s*"""/,
|
58
|
+
:multiline_end => /"""/,
|
59
|
+
:blank_line => /^\s*$/
|
60
|
+
},
|
61
|
+
|
62
|
+
:cplusplus => {
|
63
|
+
:single_line_full => /^\s*\/\//,
|
64
|
+
:single_line_mixed => /\/\//,
|
65
|
+
:multiline_begin => /\/\*/,
|
66
|
+
:multiline_end => /\*\/\s*$/,
|
67
|
+
:multiline_begin_mixed => /^[^\s]+.*\/\*/,
|
68
|
+
:multiline_end_mixed => /\*\/\s*[^\s]+$/,
|
69
|
+
:blank_line => /^\s*$/
|
70
|
+
}
|
71
|
+
}
|
50
72
|
|
51
73
|
LINE_FORMAT = '%8s %8s %8s %8s %12s %s'
|
52
74
|
|
@@ -64,7 +86,24 @@ module CountLOC
|
|
64
86
|
def self.columnNames
|
65
87
|
self.headline.split(' ', 6)
|
66
88
|
end
|
67
|
-
|
89
|
+
|
90
|
+
#
|
91
|
+
# Retrieve the commenting style that should be used for the given
|
92
|
+
# file type.
|
93
|
+
#
|
94
|
+
def self.commentStyle(ext)
|
95
|
+
{ ".rb" => :ruby,
|
96
|
+
".py" => :python,
|
97
|
+
".c" => :cplusplus,
|
98
|
+
".cpp" => :cplusplus,
|
99
|
+
".cc" => :cplusplus,
|
100
|
+
".cs" => :cplusplus,
|
101
|
+
".h" => :cplusplus,
|
102
|
+
".hpp" => :cplusplus,
|
103
|
+
".java" => :cplusplus
|
104
|
+
}[ext]
|
105
|
+
end
|
106
|
+
|
68
107
|
def initialize(name)
|
69
108
|
@name = name
|
70
109
|
@code = 0
|
@@ -77,7 +116,7 @@ module CountLOC
|
|
77
116
|
# Iterates over all the lines in io (io might be a file or a string),
|
78
117
|
# analyzes them and appropriately increases the counter attributes.
|
79
118
|
#
|
80
|
-
def read(io)
|
119
|
+
def read(io, style)
|
81
120
|
in_multiline_comment = false
|
82
121
|
io.each do |line|
|
83
122
|
@lines += 1
|
@@ -85,23 +124,53 @@ module CountLOC
|
|
85
124
|
# Process the line to avoid matching comment characters within quoted
|
86
125
|
# strings or regular expressions.
|
87
126
|
line.gsub!(/\'.*?\'/, "X") # Single quoted string
|
88
|
-
line.gsub!(
|
89
|
-
|
127
|
+
line.gsub!(/[^\"]\"[^\"]+\"/, "X") # Double quoted string
|
128
|
+
if style == :ruby:
|
129
|
+
line.gsub!(/\/.*?\//, "X") # Regular expression
|
130
|
+
end
|
90
131
|
|
132
|
+
patterns = COMMENT_PATTERNS[style]
|
133
|
+
|
134
|
+
# In the event where the multiline_end pattern is the same as the
|
135
|
+
# multiline_begin pattern, it is necessary to check for the ending
|
136
|
+
# pattern first - otherwise we will never detect the ending pattern.
|
137
|
+
if in_multiline_comment
|
138
|
+
if patterns.include?(:multiline_end_mixed) and
|
139
|
+
line =~ patterns[:multiline_end_mixed]
|
140
|
+
@comments += 1
|
141
|
+
@code += 1
|
142
|
+
in_multiline_comment = false
|
143
|
+
next
|
144
|
+
elsif line =~ patterns[:multiline_end]
|
145
|
+
@comments += 1
|
146
|
+
in_multiline_comment = false
|
147
|
+
next
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
91
151
|
case line
|
92
|
-
when
|
93
|
-
in_multiline_comment = true
|
94
|
-
|
95
|
-
|
96
|
-
|
152
|
+
when patterns[:multiline_begin]
|
153
|
+
in_multiline_comment = true
|
154
|
+
if patterns.include?(:multiline_begin_mixed) and
|
155
|
+
line =~ patterns[:multiline_begin_mixed]
|
156
|
+
@code += 1
|
157
|
+
end
|
158
|
+
|
159
|
+
if line.sub(patterns[:multiline_begin], "X") =~ patterns[:multiline_end]
|
160
|
+
in_multiline_comment = false
|
161
|
+
end
|
97
162
|
@comments += 1
|
98
|
-
|
163
|
+
|
164
|
+
when patterns[:blank_line]
|
99
165
|
@blank += 1
|
100
|
-
|
166
|
+
|
167
|
+
when patterns[:single_line_full]
|
101
168
|
@comments += 1
|
102
|
-
|
169
|
+
|
170
|
+
when patterns[:single_line_mixed]
|
103
171
|
@comments += 1
|
104
172
|
@code += 1
|
173
|
+
|
105
174
|
else
|
106
175
|
if in_multiline_comment
|
107
176
|
@comments += 1
|
@@ -240,20 +309,36 @@ module CountLOC
|
|
240
309
|
|
241
310
|
#
|
242
311
|
# Generates LOC metrics for the specified files and sends the results to the console.
|
243
|
-
#
|
244
|
-
|
312
|
+
# Supported options:
|
313
|
+
# * :recurse - recurse into sub-directories. Default = false.
|
314
|
+
# * :csv - write the results to a csv file. Default = false.
|
315
|
+
# * :csvFilename - name of csv file to generate. Used with :csv option. Default = countloc.csv
|
316
|
+
# * :html - write the results to a html file. Default = false.
|
317
|
+
# * :htmlFilename - name of html file to generate. Used with :html option. Default = countloc.html
|
318
|
+
# * :quiet - do not output results to stdout
|
319
|
+
# * :fileTypes - Types of file to include in the LOC analysis. Used for filtering files
|
320
|
+
# in recursive analysis and to specify languages other than Ruby. Default = *.rb
|
321
|
+
def countloc(files, options = {})
|
322
|
+
|
323
|
+
# Setup defaults for filenames
|
324
|
+
options[:fileTypes] = ["*.rb"] if not options.include?(:fileTypes)
|
325
|
+
options[:csvFilename] = "countloc.csv" if not options.include?(:csvFilename)
|
326
|
+
options[:htmlFilename] = "countloc.html" if not options.include?(:htmlFilename)
|
245
327
|
|
246
328
|
# Setup the output writers based on the options
|
247
|
-
writers = [
|
248
|
-
writers <<
|
249
|
-
writers <<
|
329
|
+
writers = []
|
330
|
+
writers << ConsoleWriter.new if not options[:quiet]
|
331
|
+
writers << CsvFileWriter.new(options[:csvFilename]) if options[:csv]
|
332
|
+
writers << HtmlFileWriter.new(options[:htmlFilename]) if options[:html]
|
250
333
|
|
251
334
|
# Expand directories into the appropriate file lists
|
252
335
|
dirs = files.select { |filename| File.directory?(filename) }
|
253
336
|
if dirs.size > 0
|
254
|
-
recursePattern = ("**" if options
|
337
|
+
recursePattern = ("**" if options[:recurse]) || ""
|
255
338
|
files -= dirs
|
256
|
-
|
339
|
+
options[:fileTypes].each do |fileType|
|
340
|
+
files += dirs.collect { |dirname| Dir.glob(File.join(dirname, recursePattern, fileType))}.flatten
|
341
|
+
end
|
257
342
|
end
|
258
343
|
|
259
344
|
# Sum will keep the running total
|
@@ -267,7 +352,7 @@ module CountLOC
|
|
267
352
|
begin
|
268
353
|
File.open(filename) do |file|
|
269
354
|
counter = LineCounter.new(filename)
|
270
|
-
counter.read(file)
|
355
|
+
counter.read(file, LineCounter.commentStyle(File.extname(filename)))
|
271
356
|
sum += counter
|
272
357
|
results << counter
|
273
358
|
end
|
@@ -294,8 +379,6 @@ end # module
|
|
294
379
|
#
|
295
380
|
if $0 == __FILE__:
|
296
381
|
|
297
|
-
require 'ostruct'
|
298
|
-
|
299
382
|
class CmdLineOptParser
|
300
383
|
|
301
384
|
def self.usage
|
@@ -308,19 +391,14 @@ if $0 == __FILE__:
|
|
308
391
|
def self.parse(args)
|
309
392
|
# The options set on the command line will be collected in "options"
|
310
393
|
# Setup the defaults here
|
311
|
-
options =
|
312
|
-
|
313
|
-
options.csv = false
|
314
|
-
options.csvFilename = ""
|
315
|
-
options.html = false
|
316
|
-
options.htmlFilename = ""
|
317
|
-
|
394
|
+
options = {}
|
395
|
+
|
318
396
|
begin
|
319
397
|
OptionParser.new do |opts|
|
320
398
|
opts.banner = usage
|
321
399
|
|
322
400
|
opts.on('-r', '--recurse', 'Recurse into subdirectories') do
|
323
|
-
options
|
401
|
+
options[:recurse] = true
|
324
402
|
end
|
325
403
|
|
326
404
|
opts.on('-v', '--version', 'Display version number') do
|
@@ -328,14 +406,24 @@ if $0 == __FILE__:
|
|
328
406
|
exit
|
329
407
|
end
|
330
408
|
|
409
|
+
opts.on('-q', '--quiet', "Don't write results to stdout") do
|
410
|
+
options[:quiet] = true
|
411
|
+
end
|
412
|
+
|
331
413
|
opts.on('--csv csvFilename', 'Generate csv file') do |csvFilename|
|
332
|
-
options
|
333
|
-
options
|
414
|
+
options[:csvFilename] = csvFilename
|
415
|
+
options[:csv] = true
|
334
416
|
end
|
335
417
|
|
336
418
|
opts.on('--html htmlFilename', 'Generate html file') do |htmlFilename|
|
337
|
-
options
|
338
|
-
options
|
419
|
+
options[:htmlFilename] = htmlFilename
|
420
|
+
options[:html] = true
|
421
|
+
end
|
422
|
+
|
423
|
+
opts.on('--file-types fileTypes',
|
424
|
+
"File types to be included.",
|
425
|
+
"Default = *.rb") do |fileTypes|
|
426
|
+
options[:fileTypes] = fileTypes.split()
|
339
427
|
end
|
340
428
|
|
341
429
|
opts.on_tail('-h', '--help', 'Display this help and exit') do
|
data/test/tc_cpp.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
# Copyright (C) 2009 Stephen Doyle
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'countloc'
|
7
|
+
|
8
|
+
class CppTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
include CountLOC
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@counter = LineCounter.new('Test')
|
14
|
+
@style = :cplusplus
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_single_line_comment
|
18
|
+
@counter.read("// This is a comment", @style)
|
19
|
+
assert_equal(0, @counter.code)
|
20
|
+
assert_equal(1, @counter.comments)
|
21
|
+
assert_equal(0, @counter.blank)
|
22
|
+
assert_equal(1, @counter.lines)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_single_line_comment_with_whitespace
|
26
|
+
@counter.read(" // This is a comment", @style)
|
27
|
+
assert_equal(0, @counter.code)
|
28
|
+
assert_equal(1, @counter.comments)
|
29
|
+
assert_equal(0, @counter.blank)
|
30
|
+
assert_equal(1, @counter.lines)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_multi_line_comment
|
34
|
+
@counter.read(%{/*\nThis is a comment\n*/}, @style)
|
35
|
+
assert_equal(0, @counter.code)
|
36
|
+
assert_equal(3, @counter.comments)
|
37
|
+
assert_equal(0, @counter.blank)
|
38
|
+
assert_equal(3, @counter.lines)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_multi_line_comment_on_a_single_line
|
42
|
+
@counter.read(%{/*This is a comment*/}, @style)
|
43
|
+
assert_equal(0, @counter.code)
|
44
|
+
assert_equal(1, @counter.comments)
|
45
|
+
assert_equal(0, @counter.blank)
|
46
|
+
assert_equal(1, @counter.lines)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_multi_line_comment_with_blank_lines
|
50
|
+
@counter.read(%{/* This is a comment\n\n*/}, @style)
|
51
|
+
assert_equal(0, @counter.code)
|
52
|
+
assert_equal(2, @counter.comments)
|
53
|
+
assert_equal(1, @counter.blank)
|
54
|
+
assert_equal(3, @counter.lines)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_mixed_with_single_line_comments
|
58
|
+
@counter.read("print 'hello' // This is a mixed comment", @style)
|
59
|
+
assert_equal(1, @counter.code)
|
60
|
+
assert_equal(1, @counter.comments)
|
61
|
+
assert_equal(0, @counter.blank)
|
62
|
+
assert_equal(1, @counter.lines)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_mixed_with_multi_line_comments
|
66
|
+
@counter.read(%{printf("hello"); /* This is a mixed comment */}, @style)
|
67
|
+
assert_equal(1, @counter.code)
|
68
|
+
assert_equal(1, @counter.comments)
|
69
|
+
assert_equal(0, @counter.blank)
|
70
|
+
assert_equal(1, @counter.lines)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_single_line_comment_char_in_double_quote_string
|
74
|
+
@counter.read(%{printf("//comment");}, @style)
|
75
|
+
assert_equal(1, @counter.code)
|
76
|
+
assert_equal(0, @counter.comments)
|
77
|
+
assert_equal(0, @counter.blank)
|
78
|
+
assert_equal(1, @counter.lines)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_multi_line_comment_char_in_double_quote_string
|
82
|
+
@counter.read(%{printf("/* comment */");}, @style)
|
83
|
+
assert_equal(1, @counter.code)
|
84
|
+
assert_equal(0, @counter.comments)
|
85
|
+
assert_equal(0, @counter.blank)
|
86
|
+
assert_equal(1, @counter.lines)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_blank_lines_with_newline
|
90
|
+
@counter.read("\n", @style)
|
91
|
+
assert_equal(0, @counter.code)
|
92
|
+
assert_equal(0, @counter.comments)
|
93
|
+
assert_equal(1, @counter.blank)
|
94
|
+
assert_equal(1, @counter.lines)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_blank_lines_with_whitespace
|
98
|
+
@counter.read(" \t", @style)
|
99
|
+
assert_equal(0, @counter.code)
|
100
|
+
assert_equal(0, @counter.comments)
|
101
|
+
assert_equal(1, @counter.blank)
|
102
|
+
assert_equal(1, @counter.lines)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_mixed_code_and_comments
|
106
|
+
@counter.read(
|
107
|
+
%{/*\n} +
|
108
|
+
%{ * Sample foo function\n} +
|
109
|
+
%{ */\n} +
|
110
|
+
"void foo() {\n" +
|
111
|
+
%{ // say hello\n} +
|
112
|
+
%{ printf("Hello World");\n} +
|
113
|
+
"}\n\n" +
|
114
|
+
%{// The End}, @style)
|
115
|
+
assert_equal(3, @counter.code)
|
116
|
+
assert_equal(5, @counter.comments)
|
117
|
+
assert_equal(1, @counter.blank)
|
118
|
+
assert_equal(9, @counter.lines)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
data/test/tc_python.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
# Copyright (C) 2009 Stephen Doyle
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'countloc'
|
7
|
+
|
8
|
+
class PythonTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
include CountLOC
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@counter = LineCounter.new('Test')
|
14
|
+
@style = :python
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_single_line_comment
|
18
|
+
@counter.read("# This is a comment", @style)
|
19
|
+
assert_equal(0, @counter.code)
|
20
|
+
assert_equal(1, @counter.comments)
|
21
|
+
assert_equal(0, @counter.blank)
|
22
|
+
assert_equal(1, @counter.lines)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_single_line_comment_with_whitespace
|
26
|
+
@counter.read(" # This is a comment", @style)
|
27
|
+
assert_equal(0, @counter.code)
|
28
|
+
assert_equal(1, @counter.comments)
|
29
|
+
assert_equal(0, @counter.blank)
|
30
|
+
assert_equal(1, @counter.lines)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_multi_line_comment
|
34
|
+
@counter.read(%{"""\n# This is a comment\n"""}, @style)
|
35
|
+
assert_equal(0, @counter.code)
|
36
|
+
assert_equal(3, @counter.comments)
|
37
|
+
assert_equal(0, @counter.blank)
|
38
|
+
assert_equal(3, @counter.lines)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_multi_line_comment_on_a_single_line
|
42
|
+
@counter.read(%{"""This is a comment"""}, @style)
|
43
|
+
assert_equal(0, @counter.code)
|
44
|
+
assert_equal(1, @counter.comments)
|
45
|
+
assert_equal(0, @counter.blank)
|
46
|
+
assert_equal(1, @counter.lines)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_multi_line_comment_with_blank_lines
|
50
|
+
@counter.read(%{"""# This is a comment\n\n"""}, @style)
|
51
|
+
assert_equal(0, @counter.code)
|
52
|
+
assert_equal(2, @counter.comments)
|
53
|
+
assert_equal(1, @counter.blank)
|
54
|
+
assert_equal(3, @counter.lines)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_mixed
|
58
|
+
@counter.read("print 'hello' # This is a mixed comment", @style)
|
59
|
+
assert_equal(1, @counter.code)
|
60
|
+
assert_equal(1, @counter.comments)
|
61
|
+
assert_equal(0, @counter.blank)
|
62
|
+
assert_equal(1, @counter.lines)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_comment_char_in_double_quote_string
|
66
|
+
@counter.read('print "hello #"', @style)
|
67
|
+
assert_equal(1, @counter.code)
|
68
|
+
assert_equal(0, @counter.comments)
|
69
|
+
assert_equal(0, @counter.blank)
|
70
|
+
assert_equal(1, @counter.lines)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_comment_char_in_single_quote_string
|
74
|
+
@counter.read("print 'hello #'", @style)
|
75
|
+
assert_equal(1, @counter.code)
|
76
|
+
assert_equal(0, @counter.comments)
|
77
|
+
assert_equal(0, @counter.blank)
|
78
|
+
assert_equal(1, @counter.lines)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_blank_lines_with_newline
|
82
|
+
@counter.read("\n", @style)
|
83
|
+
assert_equal(0, @counter.code)
|
84
|
+
assert_equal(0, @counter.comments)
|
85
|
+
assert_equal(1, @counter.blank)
|
86
|
+
assert_equal(1, @counter.lines)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_blank_lines_with_whitespace
|
90
|
+
@counter.read(" \t", @style)
|
91
|
+
assert_equal(0, @counter.code)
|
92
|
+
assert_equal(0, @counter.comments)
|
93
|
+
assert_equal(1, @counter.blank)
|
94
|
+
assert_equal(1, @counter.lines)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_mixed_code_and_comments
|
98
|
+
@counter.read("# This is a comment\n" +
|
99
|
+
"print 'hello'\n" +
|
100
|
+
%{"""\n} +
|
101
|
+
%{ multiline comment\n} +
|
102
|
+
%{"""\n} +
|
103
|
+
%{print 'blah'}, @style)
|
104
|
+
assert_equal(2, @counter.code)
|
105
|
+
assert_equal(4, @counter.comments)
|
106
|
+
assert_equal(0, @counter.blank)
|
107
|
+
assert_equal(6, @counter.lines)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
|
data/test/tc_ruby.rb
CHANGED
@@ -11,98 +11,100 @@ class RubyTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def setup
|
13
13
|
@counter = LineCounter.new('Test')
|
14
|
+
@style = :ruby
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
@counter.read("# This is a comment")
|
17
|
+
def test_single_line_comment
|
18
|
+
@counter.read("# This is a comment", @style)
|
18
19
|
assert_equal(0, @counter.code)
|
19
20
|
assert_equal(1, @counter.comments)
|
20
21
|
assert_equal(0, @counter.blank)
|
21
22
|
assert_equal(1, @counter.lines)
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
@counter.read(" # This is a comment")
|
25
|
+
def test_single_line_comment_with_whitespace
|
26
|
+
@counter.read(" # This is a comment", @style)
|
26
27
|
assert_equal(0, @counter.code)
|
27
28
|
assert_equal(1, @counter.comments)
|
28
29
|
assert_equal(0, @counter.blank)
|
29
30
|
assert_equal(1, @counter.lines)
|
30
31
|
end
|
31
32
|
|
32
|
-
def
|
33
|
-
@counter.read("=begin\n# This is a comment\n=end")
|
33
|
+
def test_multi_line_comment
|
34
|
+
@counter.read("=begin\n# This is a comment\n=end", @style)
|
34
35
|
assert_equal(0, @counter.code)
|
35
36
|
assert_equal(3, @counter.comments)
|
36
37
|
assert_equal(0, @counter.blank)
|
37
38
|
assert_equal(3, @counter.lines)
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
@counter.read("=begin\n# This is a comment\n\n=end")
|
41
|
+
def test_multi_line_comment_with_blank_lines
|
42
|
+
@counter.read("=begin\n# This is a comment\n\n=end", @style)
|
42
43
|
assert_equal(0, @counter.code)
|
43
44
|
assert_equal(3, @counter.comments)
|
44
45
|
assert_equal(1, @counter.blank)
|
45
46
|
assert_equal(4, @counter.lines)
|
46
47
|
end
|
47
48
|
|
48
|
-
def
|
49
|
-
@counter.read("puts 'hello' # This is a mixed comment")
|
49
|
+
def test_mixed
|
50
|
+
@counter.read("puts 'hello' # This is a mixed comment", @style)
|
50
51
|
assert_equal(1, @counter.code)
|
51
52
|
assert_equal(1, @counter.comments)
|
52
53
|
assert_equal(0, @counter.blank)
|
53
54
|
assert_equal(1, @counter.lines)
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
-
@counter.read('puts "hello #"')
|
57
|
+
def test_comment_char_in_double_quote_string
|
58
|
+
@counter.read('puts "hello #"', @style)
|
58
59
|
assert_equal(1, @counter.code)
|
59
60
|
assert_equal(0, @counter.comments)
|
60
61
|
assert_equal(0, @counter.blank)
|
61
62
|
assert_equal(1, @counter.lines)
|
62
63
|
end
|
63
64
|
|
64
|
-
def
|
65
|
-
@counter.read("puts 'hello #'")
|
65
|
+
def test_comment_char_in_single_quote_string
|
66
|
+
@counter.read("puts 'hello #'", @style)
|
66
67
|
assert_equal(1, @counter.code)
|
67
68
|
assert_equal(0, @counter.comments)
|
68
69
|
assert_equal(0, @counter.blank)
|
69
70
|
assert_equal(1, @counter.lines)
|
70
71
|
end
|
71
72
|
|
72
|
-
def
|
73
|
-
@counter.read("puts /#/")
|
73
|
+
def test_comment_char_in_regexp
|
74
|
+
@counter.read("puts /#/", @style)
|
74
75
|
assert_equal(1, @counter.code)
|
75
76
|
assert_equal(0, @counter.comments)
|
76
77
|
assert_equal(0, @counter.blank)
|
77
78
|
assert_equal(1, @counter.lines)
|
78
79
|
end
|
79
80
|
|
80
|
-
def
|
81
|
-
@counter.read("\n")
|
81
|
+
def test_blank_lines_with_newline
|
82
|
+
@counter.read("\n", @style)
|
82
83
|
assert_equal(0, @counter.code)
|
83
84
|
assert_equal(0, @counter.comments)
|
84
85
|
assert_equal(1, @counter.blank)
|
85
86
|
assert_equal(1, @counter.lines)
|
86
87
|
end
|
87
88
|
|
88
|
-
def
|
89
|
-
@counter.read(" \t")
|
89
|
+
def test_blank_lines_with_whitespace
|
90
|
+
@counter.read(" \t", @style)
|
90
91
|
assert_equal(0, @counter.code)
|
91
92
|
assert_equal(0, @counter.comments)
|
92
93
|
assert_equal(1, @counter.blank)
|
93
94
|
assert_equal(1, @counter.lines)
|
94
95
|
end
|
95
96
|
|
96
|
-
def
|
97
|
+
def test_mixed_code_and_comments
|
97
98
|
@counter.read("# This is a comment\n" +
|
98
99
|
"1.upto(5).each {|x| puts x}\n" +
|
99
100
|
"=begin\n" +
|
100
101
|
" multiline comment\n" +
|
101
|
-
"=end"
|
102
|
-
|
102
|
+
"=end\n" +
|
103
|
+
"puts 'blah'", @style)
|
104
|
+
assert_equal(2, @counter.code)
|
103
105
|
assert_equal(4, @counter.comments)
|
104
106
|
assert_equal(0, @counter.blank)
|
105
|
-
assert_equal(
|
107
|
+
assert_equal(6, @counter.lines)
|
106
108
|
end
|
107
109
|
|
108
110
|
end
|
data/test/ts_countloc.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Doyle
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-10 22:36:59.574069 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,6 +26,8 @@ files:
|
|
26
26
|
- LICENSE
|
27
27
|
- setup.rb
|
28
28
|
- lib/countloc.rb
|
29
|
+
- test/tc_cpp.rb
|
30
|
+
- test/tc_python.rb
|
29
31
|
- test/tc_ruby.rb
|
30
32
|
- test/ts_countloc.rb
|
31
33
|
has_rdoc: true
|