mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Added formatting for Ruby set objects (patch by Richard Hall)
This commit is contained in:
parent
514faad651
commit
7ccf4907ae
2 changed files with 36 additions and 1 deletions
|
@ -9,7 +9,7 @@ require "shellwords"
|
||||||
module AwesomePrint
|
module AwesomePrint
|
||||||
class Formatter
|
class Formatter
|
||||||
|
|
||||||
CORE = [ :array, :hash, :class, :file, :dir, :bigdecimal, :rational, :struct, :method, :unboundmethod ]
|
CORE = [ :array, :bigdecimal, :class, :dir, :file, :hash, :method, :rational, :set, :struct, :unboundmethod ]
|
||||||
DEFAULT_LIMIT_SIZE = 7
|
DEFAULT_LIMIT_SIZE = 7
|
||||||
|
|
||||||
def initialize(inspector)
|
def initialize(inspector)
|
||||||
|
@ -162,6 +162,12 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Format a set.
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
def awesome_set(s)
|
||||||
|
awesome_array(s.to_a)
|
||||||
|
end
|
||||||
|
|
||||||
# Format a Struct.
|
# Format a Struct.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_struct(s)
|
def awesome_struct(s)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||||
require "bigdecimal"
|
require "bigdecimal"
|
||||||
require "rational"
|
require "rational"
|
||||||
|
require "set"
|
||||||
|
|
||||||
describe "AwesomePrint" do
|
describe "AwesomePrint" do
|
||||||
before do
|
before do
|
||||||
|
@ -511,6 +512,34 @@ EOS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
describe "Set" do
|
||||||
|
before do
|
||||||
|
@arr = [1, :two, "three" ]
|
||||||
|
@set = Set.new(@arr)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "empty set" do
|
||||||
|
Set.new.ai.should == [].ai
|
||||||
|
end
|
||||||
|
|
||||||
|
it "plain multiline" do
|
||||||
|
@set.ai(:plain => true).should == @arr.ai(:plain => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "plain multiline indented" do
|
||||||
|
@set.ai(:plain => true, :indent => 1).should == @arr.ai(:plain => true, :indent => 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "plain single line" do
|
||||||
|
@set.ai(:plain => true, :multiline => false).should == @arr.ai(:plain => true, :multiline => false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "colored multiline (default)" do
|
||||||
|
@set.ai.should == @arr.ai
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Struct" do
|
describe "Struct" do
|
||||||
before do
|
before do
|
||||||
|
|
Loading…
Add table
Reference in a new issue