From ee87dd447744fc3c2f1b084504e30a65135b60d9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Tue, 20 Mar 2012 21:53:46 +0100 Subject: [PATCH] Fix YAML dump/load cycle inside SexpFormatter.format. --- lib/reek/source/sexp_formatter.rb | 2 +- spec/reek/source/sexp_formatter_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 spec/reek/source/sexp_formatter_spec.rb diff --git a/lib/reek/source/sexp_formatter.rb b/lib/reek/source/sexp_formatter.rb index 7604d81bf..6281368fa 100644 --- a/lib/reek/source/sexp_formatter.rb +++ b/lib/reek/source/sexp_formatter.rb @@ -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 diff --git a/spec/reek/source/sexp_formatter_spec.rb b/spec/reek/source/sexp_formatter_spec.rb new file mode 100644 index 000000000..a88382625 --- /dev/null +++ b/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 +