diff --git a/lib/watson/parser.rb b/lib/watson/parser.rb index 8c5f81a..2de15c6 100755 --- a/lib/watson/parser.rb +++ b/lib/watson/parser.rb @@ -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 @@ -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 diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 7a6bd98..e28764f 100755 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -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 @@ -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