Permalink
Browse files

SourceParser should only sort file list on globs

Closes #572
  • Loading branch information...
1 parent 09c9596 commit c6f52536a0eedfe97ed8a2417f3b408d56c2ff5d @lsegal committed Jul 14, 2012
Showing with 16 additions and 5 deletions.
  1. +1 −2 lib/yard/parser/source_parser.rb
  2. +15 −3 spec/parser/source_parser_spec.rb
View
3 lib/yard/parser/source_parser.rb
@@ -100,7 +100,7 @@ def parse(paths = ["{lib,app}/**/*.rb", "ext/**/*.c"], excluded = [], level = lo
end
files = [paths].flatten.
map {|p| File.directory?(p) ? "#{p}/**/*.{rb,c}" : p }.
- map {|p| p.include?("*") ? Dir[p] : p }.flatten.
+ map {|p| p.include?("*") ? Dir[p].sort_by {|f| f.length } : p }.flatten.
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }
log.enter_level(level) do
@@ -360,7 +360,6 @@ def after_parse_file_callbacks
# @return [void]
def parse_in_order(*files)
global_state = OpenStruct.new
- files = files.sort_by {|x| x.length if x }
before_parse_list_callbacks.each do |cb|
return if cb.call(files, global_state) == false
View
18 spec/parser/source_parser_spec.rb
@@ -606,12 +606,24 @@ def in_order_parse(*files)
end
end
- it "should attempt to order files by length (process toplevel files first)" do
- %w(a a/b a/b/c).each do |file|
+ it "should attempt to order files by length for globs (process toplevel files first)" do
+ files = %w(a a/b a/b/c)
+ files.each do |file|
File.should_receive(:file?).with(file).and_return(true)
File.should_receive(:read_binary).with(file).ordered.and_return('')
end
- YARD.parse %w(a/b/c a/b a)
+ Dir.should_receive(:[]).with('a/**/*').and_return(files.reverse)
+ YARD.parse 'a/**/*'
+ end
+
+ it "should allow overriding of length sorting when single file is presented" do
+ files = %w(a/b/c a a/b)
+ files.each do |file|
+ File.should_receive(:file?).with(file).at_least(1).times.and_return(true)
+ File.should_receive(:read_binary).with(file).ordered.and_return('')
+ end
+ Dir.should_receive(:[]).with('a/**/*').and_return(files.reverse)
+ YARD.parse ['a/b/c', 'a/**/*']
end
end

1 comment on commit c6f5253

@koraktor

👍

Please sign in to comment.