Skip to content

Commit

Permalink
Fix YAML dump/load cycle inside SexpFormatter.format.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Mar 20, 2012
1 parent 30b0647 commit ee87dd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reek/source/sexp_formatter.rb
Expand Up @@ -9,7 +9,7 @@ module Source
class SexpFormatter
def self.format(sexp)
return sexp.to_s unless Array === sexp
sexp = YAML::load(YAML::dump(sexp))
sexp = Sexp.from_array(YAML::load(YAML::dump(sexp)))
Ruby2Ruby.new.process(sexp)
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/reek/source/sexp_formatter_spec.rb
@@ -0,0 +1,19 @@
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'source', 'sexp_formatter')

include Reek::Source

describe SexpFormatter do
describe "::format" do
it 'formats a simple s-expression' do
result = SexpFormatter.format s(:lvar, :foo)
result.should == "foo"
end

it 'formats a more complex s-expression' do
result = SexpFormatter.format s(:call, nil, :foo, s(:arglist, s(:lvar, :bar)))
result.should == "foo(bar)"
end
end
end

0 comments on commit ee87dd4

Please sign in to comment.