Skip to content

Commit

Permalink
#18 file name visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 4, 2014
1 parent 2e37e92 commit 698a0d9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
18 changes: 18 additions & 0 deletions lib/pdd/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,22 @@ def tail(lines, prefix)
.map { |txt| txt[1, txt.length] }
end
end

# Verbose Source.
class VerboseSource
# Ctor.
# +file+:: Absolute file name with source code
# +source+:: Instance of source
def initialize(file, source)
@file = file
@source = source
end

# Fetch all puzzles.
def puzzles
@source.puzzles
rescue Error => ex
raise Error, "#{ex.message} in #{@file}"
end
end
end
5 changes: 4 additions & 1 deletion lib/pdd/sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def fetch
files
.select { |f| types.index { |re| @magic.file(f) =~ re } }
.map do |file|
Source.new(file, file[@dir.length + 1, file.length])
VerboseSource.new(
file,
Source.new(file, file[@dir.length + 1, file.length])
)
end
end

Expand Down
19 changes: 18 additions & 1 deletion test/test_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,29 @@ def test_parsing
~~ and it also has to work
'
)
list = PDD::Source.new(file, 'hey').puzzles
list = PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
assert_equal 2, list.size
puzzle = list.first
assert_equal '2-3', puzzle.props[:lines]
assert_equal 'hello, how are you doing?', puzzle.props[:body]
assert_equal '44', puzzle.props[:ticket]
end
end

def test_failing_on_invalid_puzzle
Dir.mktmpdir 'test' do |dir|
file = File.join(dir, 'a.txt')
File.write(
file,
'
* @todo #44 this is an incorrectly formatted puzzle,
* with a second line without a leading space
'
)
error = assert_raises PDD::Error do
PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
end
assert !error.message.index('Space expected').nil?
end
end
end

0 comments on commit 698a0d9

Please sign in to comment.