pdd 0.7 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/features/catches_broken_puzzles.feature +16 -0
- data/lib/pdd/source.rb +18 -0
- data/lib/pdd/sources.rb +4 -1
- data/lib/pdd/version.rb +1 -1
- data/test/test_source.rb +18 -1
- metadata +1 -1
@@ -33,3 +33,19 @@ Feature: Catches Broken Puzzles
|
|
33
33
|
}
|
34
34
|
"""
|
35
35
|
When I run pdd it fails with "Too many spaces"
|
36
|
+
|
37
|
+
Scenario: Throwing exception on yet another broken puzzle
|
38
|
+
Given I have a "Sample.java" file with content:
|
39
|
+
"""
|
40
|
+
public class Main {
|
41
|
+
//
|
42
|
+
// @todo #13 This puzzle has an incorrect format
|
43
|
+
// because there is no space character in the
|
44
|
+
// second and third lines
|
45
|
+
//
|
46
|
+
public void main(String[] args) {
|
47
|
+
// later
|
48
|
+
}
|
49
|
+
}
|
50
|
+
"""
|
51
|
+
When I run pdd it fails with "Space expected"
|
data/lib/pdd/source.rb
CHANGED
@@ -92,4 +92,22 @@ module PDD
|
|
92
92
|
.map { |txt| txt[1, txt.length] }
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
# Verbose Source.
|
97
|
+
class VerboseSource
|
98
|
+
# Ctor.
|
99
|
+
# +file+:: Absolute file name with source code
|
100
|
+
# +source+:: Instance of source
|
101
|
+
def initialize(file, source)
|
102
|
+
@file = file
|
103
|
+
@source = source
|
104
|
+
end
|
105
|
+
|
106
|
+
# Fetch all puzzles.
|
107
|
+
def puzzles
|
108
|
+
@source.puzzles
|
109
|
+
rescue Error => ex
|
110
|
+
raise Error, "#{ex.message} in #{@file}"
|
111
|
+
end
|
112
|
+
end
|
95
113
|
end
|
data/lib/pdd/sources.rb
CHANGED
@@ -50,7 +50,10 @@ module PDD
|
|
50
50
|
files
|
51
51
|
.select { |f| types.index { |re| @magic.file(f) =~ re } }
|
52
52
|
.map do |file|
|
53
|
-
|
53
|
+
VerboseSource.new(
|
54
|
+
file,
|
55
|
+
Source.new(file, file[@dir.length + 1, file.length])
|
56
|
+
)
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
data/lib/pdd/version.rb
CHANGED
data/test/test_source.rb
CHANGED
@@ -43,7 +43,7 @@ class TestSources < Minitest::Test
|
|
43
43
|
~~ and it also has to work
|
44
44
|
'
|
45
45
|
)
|
46
|
-
list = PDD::Source.new(file, 'hey').puzzles
|
46
|
+
list = PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
|
47
47
|
assert_equal 2, list.size
|
48
48
|
puzzle = list.first
|
49
49
|
assert_equal '2-3', puzzle.props[:lines]
|
@@ -51,4 +51,21 @@ class TestSources < Minitest::Test
|
|
51
51
|
assert_equal '44', puzzle.props[:ticket]
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_failing_on_invalid_puzzle
|
56
|
+
Dir.mktmpdir 'test' do |dir|
|
57
|
+
file = File.join(dir, 'a.txt')
|
58
|
+
File.write(
|
59
|
+
file,
|
60
|
+
'
|
61
|
+
* @todo #44 this is an incorrectly formatted puzzle,
|
62
|
+
* with a second line without a leading space
|
63
|
+
'
|
64
|
+
)
|
65
|
+
error = assert_raises PDD::Error do
|
66
|
+
PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
|
67
|
+
end
|
68
|
+
assert !error.message.index('Space expected').nil?
|
69
|
+
end
|
70
|
+
end
|
54
71
|
end
|