Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions lib/watson/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,17 @@ def run
# Identify method entry
debug_print "#{ self } : #{ __method__ }\n"

# Go through all files added from CL (sort them first)
# If empty, sort and each will do nothing, no errors
_completed_dirs = Array.new()
_completed_files = Array.new()
if @config.cl_entry_set
@config.file_list.sort.each do |_file|
_completed_files.push(parse_file(_file))
end
end

# Then go through all the specified directories
# Initial parse depth to parse_dir is 0 (unlimited)
@config.dir_list.sort.each do |_dir|
_completed_dirs.push(parse_dir(_dir, 0))
end

# Create overall hash for parsed files
_structure = Hash.new()
_structure[:files] = _completed_files
_structure[:subdirs] = _completed_dirs
structure = {
files: get_completed_files,
dirs: get_completed_dirs
}

debug_print "_structure dump\n\n"
debug_print PP.pp(_structure, '')
debug_print "structure dump\n\n"
debug_print PP.pp(structure, '')
debug_print "\n\n"

_structure
structure
end


Expand Down Expand Up @@ -432,6 +417,32 @@ def get_comment_type(filename)

end

private


# Private
# Used by #run to parse and return an array of completed files
def get_completed_files
# Go through all files added from CL (sort them first)
# If empty, sort and reduce will do nothing, no error
return [] unless @config.cl_entry_set
sorted_files = @config.file_list.sort
sorted_files.reduce([]) do |completed, file|
completed << parse_file(file)
end
end


# Private
# Used by #run to parse and return an array of completed dirs
def get_completed_dirs
# Go through all the specified directories
# Initial parse depth to parse_dir is 0 (unlimited)
sorted_dirs = @config.dir_list.sort
sorted_dirs.reduce([]) do |completed, dir|
completed << parse_dir(dir, 0)
end
end

end
end
30 changes: 28 additions & 2 deletions spec/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Watson
enable_output
end


describe '#get_comment_type' do
context 'known extension' do
it 'return correct extension for c++' do
Expand Down Expand Up @@ -190,7 +190,33 @@ module Watson
end

end
end

end
describe "#get_completed_files" do
before(:each) do
config_msgs = {
cl_entry_set: true,
file_list: ["file1.rb"]
}
@parser = Parser.new(double(:config, config_msgs))
allow(@parser).to receive(:parse_file) { "file" }
end
it "returns only completed files" do
@parser.send(:get_completed_files).should eql ["file"]
end
end

describe "#get_completed_dirs" do
before(:each) do
config_msgs = {
dir_list: ["dir"]
}
@parser = Parser.new(double(:config, config_msgs))
allow(@parser).to receive(:parse_dir) { "dir" }
end
it "returns only completed dirs" do
@parser.send(:get_completed_dirs).should eql ["dir"]
end
end

end