Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## master (unreleased)

- Fixes struct formatting [@randyjap] - [#361]

## 1.9.2
- Tests work with Ruby 2.6.6, 2.7.2 and 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion awesome_print.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec', '>= 3.0.0'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'fakefs', '>= 0.2.1'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'sqlite3', '~> 1.3.6'
s.add_development_dependency 'nokogiri', '>= 1.11.0'
# s.add_development_dependency 'simplecov'
# s.add_development_dependency 'codeclimate-test-reporter'
Expand Down
2 changes: 1 addition & 1 deletion lib/awesome_print/formatters/struct_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(struct, inspector)

def format
vars = variables.map do |var|
property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
property = var.to_s.to_sym # to_s because of some monkey patching done by Puppet.
accessor = if struct.respond_to?(:"#{property}=")
struct.respond_to?(property) ? :accessor : :writer
else
Expand Down
30 changes: 15 additions & 15 deletions spec/formats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,44 +604,44 @@

it 'plain multiline' do
s1 = <<-EOS.strip
address = \"1313 Mockingbird Lane\",
name = \"Herman Munster\"
attr_accessor :address = \"1313 Mockingbird Lane\",
attr_accessor :name = \"Herman Munster\"
EOS
s2 = <<-EOS.strip
name = \"Herman Munster\",
address = \"1313 Mockingbird Lane\"
attr_accessor :name = \"Herman Munster\",
attr_accessor :address = \"1313 Mockingbird Lane\"
EOS
expect(@struct.ai(plain: true)).to satisfy { |out| out.match(s1) || out.match(s2) }
end

it 'plain multiline indented' do
s1 = <<-EOS.strip
address = "1313 Mockingbird Lane",
name = "Herman Munster"
attr_accessor :address = "1313 Mockingbird Lane",
attr_accessor :name = "Herman Munster"
EOS
s2 = <<-EOS.strip
name = "Herman Munster",
address = "1313 Mockingbird Lane"
attr_accessor :name = "Herman Munster",
attr_accessor :address = "1313 Mockingbird Lane"
EOS
expect(@struct.ai(plain: true, indent: 1)).to satisfy { |out| out.match(s1) || out.match(s2) }
end

it 'plain single line' do
s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"'
s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"'
s1 = 'attr_accessor :ddress = "1313 Mockingbird Lane", attr_accessor :name = "Herman Munster"'
s2 = 'attr_accessor :name = "Herman Munster", attr_accessor :address = "1313 Mockingbird Lane"'
expect(@struct.ai(plain: true, multiline: false)).to satisfy { |out| out.match(s1) || out.match(s2) }
end

it 'colored multiline (default)' do
s1 = <<-EOS.strip
address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m,
name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m
\e[1;36mattr_accessor\e[0m \e[0;35m:address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m,
\e[1;36mattr_accessor\e[0m \e[0;35m:name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m
EOS
s2 = <<-EOS.strip
name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m,
address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m
\e[1;36mattr_accessor\e[0m \e[0;35m:name\e[0;37m = \e[0m\e[0;33m\"Herman\e[1;36mattr_accessor\e[0m \e[0;35m: Munster\"\e[0m,
\e[1;36mattr_accessor\e[0m \e[0;35m:address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m
EOS
expect(@struct.ai).to satisfy { |out| out.include?(s1) || out.include?(s2) }
expect(@struct.ai).to satisfy { |out| out.include?(s1) && out.include?(s2) }
end
end

Expand Down