Permalink
Browse files

Greatly simplify formatter using #to_source

  • Loading branch information...
1 parent e657e95 commit 68c503d24c76d781b97d48939b94dfd7a9d363da @txus committed Feb 25, 2012
Showing with 10 additions and 31 deletions.
  1. +7 −29 lib/mutant/formatter.rb
  2. +3 −2 mutant.gemspec
View
@@ -1,3 +1,5 @@
+require 'to_source'
+
module Mutant
class Formatter
attr_reader :item
@@ -7,38 +9,14 @@ def initialize(item)
end
def nested?
- item.is_a?(Rubinius::AST::LocalVariableAssignment)
+ false
+ # item.is_a?(Rubinius::AST::LocalVariableAssignment) ||
+ # item.is_a?(Rubinius::AST::HashLiteral) ||
+ # item.is_a?(Rubinius::AST::If)
end
def to_s
- if item.is_a?(Rubinius::AST::LocalVariableAssignment)
- [item.name.to_s, item_value].join(' = ')
- else
- if item.is_a?(Rubinius::AST::TrueLiteral)
- 'true'
- elsif item.is_a?(Rubinius::AST::FalseLiteral)
- 'false'
- else
- item_value(item)
- end
- end
- end
-
- private
-
- def item_value(value = item.value)
- case value
- when Rubinius::AST::Range
- Range.new(item_value(value.start), item_value(value.finish))
- when Rubinius::AST::RegexLiteral
- Regexp.new(value.source)
- when Rubinius::AST::ArrayLiteral
- value.body
- when Rubinius::AST::HashLiteral
- Hash[*value.array]
- else
- value.respond_to?(:string) ? value.string.inspect : value.value.inspect
- end
+ item.to_source
end
end
end
View
@@ -5,8 +5,8 @@ require "mutant/version"
Gem::Specification.new do |s|
s.name = 'mutant'
s.version = Mutant::VERSION
- s.authors = ["Justin Ko"]
- s.email = ["justin@kospecinc.com"]
+ s.authors = ["Justin Ko", "Josep M. Bach"]
+ s.email = ["justin@kospecinc.com", "josep.m.bach@gmail.com"]
s.homepage = ""
s.summary = %q{Mutation tester}
s.description = %q{Mutation tester}
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+ s.add_runtime_dependency 'to_source'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 2.7'
s.add_development_dependency 'aruba'

0 comments on commit 68c503d

Please sign in to comment.