Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require 'troll/semi_colon_troll' | ||
require 'troll/collector' | ||
require 'troll/troller' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Troll | ||
class SemiColonTroll | ||
def troll_string(str) | ||
result = "" | ||
str.each_line { |line| result += troll_line(line) } | ||
result | ||
end | ||
|
||
private | ||
def troll_line(line) | ||
case line | ||
when /^\s+$/ | ||
line | ||
when /^.*;\s*$/ | ||
line | ||
when /^.*\n$/ | ||
"#{line.chomp};\n" | ||
else | ||
"#{line};" | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
require 'troll' | ||
|
||
describe Troll::SemiColonTroll do | ||
describe "#troll_string" do | ||
it "appends a semicolon to a single-line string" do | ||
Troll::SemiColonTroll.new.troll_string("foo").should eql("foo;") | ||
end | ||
|
||
it "does not append a semicolon to a single-line string ending in a semi-colon" do | ||
Troll::SemiColonTroll.new.troll_string("foo;").should eql("foo;") | ||
end | ||
|
||
it "appends a semicolon to each line of a multi-line string" do | ||
multi_line_string = <<-EOS | ||
class Xzibit | ||
def yo_dawg_i_heard_you_like(&procs) | ||
Proc.new { procs.call } | ||
end | ||
end | ||
EOS | ||
semi_coloned_multi_line_string = <<-EOS | ||
class Xzibit; | ||
def yo_dawg_i_heard_you_like(&procs); | ||
Proc.new { procs.call }; | ||
end; | ||
end; | ||
EOS | ||
Troll::SemiColonTroll.new.troll_string(multi_line_string).should eql(semi_coloned_multi_line_string) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters