Skip to content

Commit d729e4c

Browse files
committed
Check for long lines
1 parent ee4db73 commit d729e4c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/oreilly/snippets.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ def self.process_callouts( input, callouts, comment_character = nil )
111111
end
112112
rv = lines.join "\n"
113113
end
114+
115+
if ENV['OREILLY_SNIPPETS_DEBUG_LONG_LINES']
116+
rv.split( /\n/ ).each_with_index do |l,i|
117+
if l.length > 70
118+
raise "Line #{i+1} is too long: #{l.length} characters long"
119+
end
120+
end
121+
end
122+
114123
rv
115124
end
116125

spec/fixtures/really_long_line.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def abc def

spec/process_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
snippet~~~~
1414
END
1515

16+
LONG_LINES = <<END
17+
[filename="../spec/fixtures/really_long_lines.rb"]
18+
snippet~~~~
19+
Put any descriptive text you want here. It will be replaced with the
20+
snippet~~~~
21+
END
22+
1623

1724
WITH_SHA = <<END
1825
[filename="#{ROOT}", language="js", sha="c863f786f5959799d7c:test.js"]
@@ -322,6 +329,15 @@ def download_test_repository
322329
end
323330
end
324331

332+
describe "#warnlonglines" do
333+
it "should warn you if there is a really long line of code" do
334+
ENV['OREILLY_SNIPPETS_DEBUG_LONG_LINES'] = "1"
335+
lambda {
336+
Oreilly::Snippets.process( LONG_LINES )
337+
}.should raise_error
338+
end
339+
end
340+
325341
describe "#flatten" do
326342
before( :each ) do
327343
@with_spaces = File.read( "spec/fixtures/with_spaces.rb" )

0 commit comments

Comments
 (0)