awesome_print 1.9.2 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/Appraisals +2 -33
- data/CHANGELOG.md +6 -15
- data/CONTRIBUTING.md +0 -1
- data/README.md +7 -49
- data/lib/ap.rb +1 -5
- data/lib/awesome_print.rb +7 -29
- data/lib/awesome_print/colorize.rb +2 -0
- data/lib/awesome_print/core_ext/active_support.rb +7 -0
- data/lib/awesome_print/core_ext/awesome_method_array.rb +0 -6
- data/lib/awesome_print/core_ext/class.rb +0 -5
- data/lib/awesome_print/core_ext/kernel.rb +0 -5
- data/lib/awesome_print/core_ext/logger.rb +0 -5
- data/lib/awesome_print/core_ext/object.rb +0 -5
- data/lib/awesome_print/core_ext/string.rb +0 -5
- data/lib/awesome_print/custom_defaults.rb +1 -1
- data/lib/awesome_print/formatter.rb +38 -106
- data/lib/awesome_print/formatters/array_formatter.rb +11 -8
- data/lib/awesome_print/formatters/base_formatter.rb +20 -53
- data/lib/awesome_print/formatters/bigdecimal_formatter.rb +20 -0
- data/lib/awesome_print/formatters/class_formatter.rb +5 -6
- data/lib/awesome_print/formatters/dir_formatter.rb +4 -6
- data/lib/awesome_print/formatters/ext/active_model_error_formatter.rb +44 -0
- data/lib/awesome_print/formatters/ext/active_record_attributeset_formatter.rb +27 -0
- data/lib/awesome_print/formatters/ext/active_record_class_formatter.rb +43 -0
- data/lib/awesome_print/formatters/ext/active_record_instance_formatter.rb +48 -0
- data/lib/awesome_print/formatters/ext/active_record_relation_formatter.rb +19 -0
- data/lib/awesome_print/formatters/ext/bson_objectid_formatter.rb +20 -0
- data/lib/awesome_print/formatters/ext/hash_with_indifferent_access_formatter.rb +20 -0
- data/lib/awesome_print/formatters/ext/mongoid_document_formatter.rb +59 -0
- data/lib/awesome_print/formatters/ext/nokogiri_document_formatter.rb +30 -0
- data/lib/awesome_print/formatters/ext/nokogiri_node_formatter.rb +29 -0
- data/lib/awesome_print/formatters/ext/nokogiri_nodeset_formatter.rb +32 -0
- data/lib/awesome_print/formatters/ext/sequel_dataset_formatter.rb +20 -0
- data/lib/awesome_print/formatters/ext/sequel_model_class_formatter.rb +25 -0
- data/lib/awesome_print/formatters/ext/sequel_model_formatter.rb +26 -0
- data/lib/awesome_print/formatters/ext/time_with_zone_formatter.rb +24 -0
- data/lib/awesome_print/formatters/fallback_formatter.rb +55 -0
- data/lib/awesome_print/formatters/false_class_formatter.rb +15 -0
- data/lib/awesome_print/formatters/file_formatter.rb +4 -6
- data/lib/awesome_print/formatters/hash_formatter.rb +12 -7
- data/lib/awesome_print/formatters/integer_formatter.rb +11 -0
- data/lib/awesome_print/formatters/method_formatter.rb +8 -6
- data/lib/awesome_print/formatters/module_formatter.rb +18 -0
- data/lib/awesome_print/formatters/nil_class_formatter.rb +19 -0
- data/lib/awesome_print/formatters/object_formatter.rb +19 -9
- data/lib/awesome_print/formatters/open_struct.rb +19 -0
- data/lib/awesome_print/formatters/range_formatter.rb +11 -0
- data/lib/awesome_print/formatters/rational_formatter.rb +15 -0
- data/lib/awesome_print/formatters/set_formatter.rb +19 -0
- data/lib/awesome_print/formatters/simple_formatter.rb +10 -8
- data/lib/awesome_print/formatters/string_formatter.rb +14 -0
- data/lib/awesome_print/formatters/struct_formatter.rb +8 -6
- data/lib/awesome_print/formatters/symbol_formatter.rb +18 -0
- data/lib/awesome_print/formatters/true_class_formatter.rb +15 -0
- data/lib/awesome_print/formatters/unbound_method_formatter.rb +15 -0
- data/lib/awesome_print/inspector.rb +18 -17
- data/lib/awesome_print/limiter.rb +63 -0
- data/lib/awesome_print/registrar.rb +20 -0
- data/lib/awesome_print/version.rb +6 -6
- data/spec/formatters/array_spec.rb +251 -0
- data/spec/formatters/big_decimal_spec.rb +28 -0
- data/spec/formatters/class_spec.rb +91 -0
- data/spec/formatters/dir_file_spec.rb +43 -0
- data/spec/{ext → formatters/ext}/active_record_spec.rb +14 -58
- data/spec/{ext → formatters/ext}/active_support_spec.rb +7 -11
- data/spec/{ext → formatters/ext}/mongoid_spec.rb +2 -2
- data/spec/{ext → formatters/ext}/nokogiri_spec.rb +0 -0
- data/spec/formatters/hash_spec.rb +284 -0
- data/spec/{methods_spec.rb → formatters/methods_spec.rb} +3 -5
- data/spec/{objects_spec.rb → formatters/objects_spec.rb} +0 -0
- data/spec/{ext → formatters}/ostruct_spec.rb +1 -0
- data/spec/formatters/set_spec.rb +49 -0
- data/spec/formatters/struct_spec.rb +61 -0
- data/spec/merge_options_spec.rb +13 -0
- data/spec/misc_spec.rb +3 -10
- data/spec/spec_helper.rb +2 -9
- data/spec/support/ext_verifier.rb +0 -15
- data/spec/support/mongoid_versions.rb +4 -8
- data/spec/support/rails_versions.rb +2 -32
- metadata +100 -78
- data/awesome_print.gemspec +0 -33
- data/init.rb +0 -1
- data/lib/awesome_print/core_ext/method.rb +0 -21
- data/lib/awesome_print/ext/action_view.rb +0 -22
- data/lib/awesome_print/ext/active_record.rb +0 -103
- data/lib/awesome_print/ext/active_support.rb +0 -47
- data/lib/awesome_print/ext/mongo_mapper.rb +0 -124
- data/lib/awesome_print/ext/mongoid.rb +0 -67
- data/lib/awesome_print/ext/nobrainer.rb +0 -52
- data/lib/awesome_print/ext/nokogiri.rb +0 -45
- data/lib/awesome_print/ext/ostruct.rb +0 -27
- data/lib/awesome_print/ext/ripple.rb +0 -71
- data/lib/awesome_print/ext/sequel.rb +0 -58
- data/spec/ext/action_view_spec.rb +0 -21
- data/spec/ext/mongo_mapper_spec.rb +0 -261
- data/spec/ext/nobrainer_spec.rb +0 -59
- data/spec/ext/ripple_spec.rb +0 -48
- data/spec/formats_spec.rb +0 -779
- data/spec/support/active_record_data/3_2_diana.txt +0 -24
- data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
- data/spec/support/active_record_data/3_2_multi.txt +0 -50
- data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
- data/spec/support/active_record_data/4_0_diana.txt +0 -98
- data/spec/support/active_record_data/4_0_multi.txt +0 -198
- data/spec/support/active_record_data/4_1_diana.txt +0 -97
- data/spec/support/active_record_data/4_1_multi.txt +0 -196
- data/spec/support/active_record_data/4_2_diana.txt +0 -109
- data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
- data/spec/support/active_record_data/4_2_multi.txt +0 -220
- data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
- data/spec/support/active_record_data/6_0_diana.txt +0 -104
- data/spec/support/active_record_data/6_0_multi.txt +0 -210
- data/spec/support/active_record_data/6_1_diana.txt +0 -109
- data/spec/support/active_record_data/6_1_multi.txt +0 -220
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'base_formatter'
|
2
|
+
|
3
|
+
module AwesomePrint
|
4
|
+
module Formatters
|
5
|
+
class OpenStruct < BaseFormatter
|
6
|
+
|
7
|
+
formatter_for :openstruct
|
8
|
+
|
9
|
+
def self.formattable?(object)
|
10
|
+
defined?(::OpenStruct) && object.is_a?(::OpenStruct)
|
11
|
+
end
|
12
|
+
|
13
|
+
def format(object)
|
14
|
+
"#{object.class} #{HashFormatter.new(inspector).format(object.marshal_dump)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'base_formatter'
|
2
|
+
|
3
|
+
module AwesomePrint
|
4
|
+
module Formatters
|
5
|
+
class SetFormatter < BaseFormatter
|
6
|
+
|
7
|
+
formatter_for :set
|
8
|
+
|
9
|
+
def self.formattable?(object)
|
10
|
+
object.kind_of?(Set)
|
11
|
+
end
|
12
|
+
|
13
|
+
def format(object)
|
14
|
+
Formatters::ArrayFormatter.new(@inspector).format(object.to_a)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,18 +4,20 @@ module AwesomePrint
|
|
4
4
|
module Formatters
|
5
5
|
class SimpleFormatter < BaseFormatter
|
6
6
|
|
7
|
-
|
7
|
+
formatter_for :simple
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
@type = type
|
12
|
-
@inspector = inspector
|
13
|
-
@options = inspector.options
|
9
|
+
def self.core?
|
10
|
+
true
|
14
11
|
end
|
15
12
|
|
16
|
-
def
|
17
|
-
|
13
|
+
def self.formattable?(object)
|
14
|
+
object.respond_to?(:to_s)
|
18
15
|
end
|
16
|
+
|
17
|
+
def format(object)
|
18
|
+
colorize(object.to_s, self.class.formatted_object_type)
|
19
|
+
end
|
20
|
+
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'simple_formatter'
|
2
|
+
|
3
|
+
module AwesomePrint
|
4
|
+
module Formatters
|
5
|
+
class StringFormatter < SimpleFormatter
|
6
|
+
|
7
|
+
formatter_for :string
|
8
|
+
|
9
|
+
def format(object)
|
10
|
+
colorize("\"#{object.to_s}\"", self.class.formatted_object_type)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -4,16 +4,18 @@ module AwesomePrint
|
|
4
4
|
module Formatters
|
5
5
|
class StructFormatter < BaseFormatter
|
6
6
|
|
7
|
-
|
7
|
+
formatter_for :struct
|
8
8
|
|
9
|
-
def
|
9
|
+
def self.formattable?(object)
|
10
|
+
object.is_a?(Struct)
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :struct, :variables
|
14
|
+
|
15
|
+
def format(struct)
|
10
16
|
@struct = struct
|
11
17
|
@variables = struct.members
|
12
|
-
@inspector = inspector
|
13
|
-
@options = inspector.options
|
14
|
-
end
|
15
18
|
|
16
|
-
def format
|
17
19
|
vars = variables.map do |var|
|
18
20
|
property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
|
19
21
|
accessor = if struct.respond_to?(:"#{property}=")
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'simple_formatter'
|
2
|
+
|
3
|
+
module AwesomePrint
|
4
|
+
module Formatters
|
5
|
+
class SymbolFormatter < SimpleFormatter
|
6
|
+
|
7
|
+
formatter_for :symbol
|
8
|
+
|
9
|
+
def self.formattable?(object)
|
10
|
+
object.respond_to?(:to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def format(object)
|
14
|
+
colorize(":#{object.to_s}", self.class.formatted_object_type)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'method_formatter'
|
2
|
+
|
3
|
+
module AwesomePrint
|
4
|
+
module Formatters
|
5
|
+
class UnboundMethodFormatter < MethodFormatter
|
6
|
+
|
7
|
+
formatter_for :unboundmethod
|
8
|
+
|
9
|
+
def self.formattable?(object)
|
10
|
+
object.is_a?(UnboundMethod)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
|
-
#
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
5
|
-
#------------------------------------------------------------------------------
|
6
1
|
require_relative 'indentator'
|
7
2
|
|
8
3
|
module AwesomePrint
|
@@ -30,10 +25,13 @@ module AwesomePrint
|
|
30
25
|
array: :white,
|
31
26
|
bigdecimal: :blue,
|
32
27
|
class: :yellow,
|
28
|
+
module: :green,
|
33
29
|
date: :greenish,
|
34
30
|
falseclass: :red,
|
31
|
+
simple: :blue,
|
35
32
|
fixnum: :blue,
|
36
33
|
integer: :blue,
|
34
|
+
range: :blue,
|
37
35
|
float: :blue,
|
38
36
|
hash: :pale,
|
39
37
|
keyword: :cyan,
|
@@ -42,6 +40,7 @@ module AwesomePrint
|
|
42
40
|
rational: :blue,
|
43
41
|
string: :yellowish,
|
44
42
|
struct: :pale,
|
43
|
+
openstruct: :pale,
|
45
44
|
symbol: :cyanish,
|
46
45
|
time: :greenish,
|
47
46
|
trueclass: :green,
|
@@ -62,8 +61,8 @@ module AwesomePrint
|
|
62
61
|
indentator.indentation
|
63
62
|
end
|
64
63
|
|
65
|
-
def increase_indentation
|
66
|
-
indentator.indent(&
|
64
|
+
def increase_indentation
|
65
|
+
indentator.indent(&Proc.new)
|
67
66
|
end
|
68
67
|
|
69
68
|
# Dispatcher that detects data nesting and invokes object-aware formatter.
|
@@ -106,9 +105,10 @@ module AwesomePrint
|
|
106
105
|
#---------------------------------------------------------------------------
|
107
106
|
def nested(object)
|
108
107
|
case printable(object)
|
109
|
-
when :array
|
110
|
-
when :hash
|
111
|
-
when :struct
|
108
|
+
when :array then @formatter.colorize('[...]', :array)
|
109
|
+
when :hash then @formatter.colorize('{...}', :hash)
|
110
|
+
when :struct then @formatter.colorize('{...}', :struct)
|
111
|
+
when :openstruct then @formatter.colorize('{...}', :openstruct)
|
112
112
|
else @formatter.colorize("...#{object.class}...", :class)
|
113
113
|
end
|
114
114
|
end
|
@@ -123,13 +123,14 @@ module AwesomePrint
|
|
123
123
|
# base class.
|
124
124
|
#---------------------------------------------------------------------------
|
125
125
|
def printable(object)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
else
|
126
|
+
# FIXME: rails specific hack. this needs to be extracted into a
|
127
|
+
# awesome_print-rails binding lib or something.
|
128
|
+
if defined?(::ActiveRecord) && object.respond_to?(:ancestors) && object.ancestors.to_a.include?(::ActiveRecord::Base)
|
129
|
+
:activerecord_base_class
|
130
|
+
elsif defined?(::Mongoid) && object.respond_to?(:ancestors) && object.ancestors.to_a.include?(::Mongoid::Document)
|
131
|
+
:mongoid_document
|
132
|
+
else
|
133
|
+
object.class.to_s.gsub(/:+/, '_').downcase.to_sym
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module AwesomePrint
|
2
|
+
module Limiter
|
3
|
+
|
4
|
+
DEFAULT_LIMIT_SIZE = 7
|
5
|
+
|
6
|
+
# To support limited output, for example:
|
7
|
+
#
|
8
|
+
# ap ('a'..'z').to_a, :limit => 3
|
9
|
+
# [
|
10
|
+
# [ 0] "a",
|
11
|
+
# [ 1] .. [24],
|
12
|
+
# [25] "z"
|
13
|
+
# ]
|
14
|
+
#
|
15
|
+
# ap (1..100).to_a, :limit => true # Default limit is 7.
|
16
|
+
# [
|
17
|
+
# [ 0] 1,
|
18
|
+
# [ 1] 2,
|
19
|
+
# [ 2] 3,
|
20
|
+
# [ 3] .. [96],
|
21
|
+
# [97] 98,
|
22
|
+
# [98] 99,
|
23
|
+
# [99] 100
|
24
|
+
# ]
|
25
|
+
#------------------------------------------------------------------------------
|
26
|
+
def should_be_limited?
|
27
|
+
options[:limit] or (options[:limit].is_a?(Integer) and options[:limit] > 0)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_limit_size
|
31
|
+
case options[:limit]
|
32
|
+
when true
|
33
|
+
DEFAULT_LIMIT_SIZE
|
34
|
+
else
|
35
|
+
options[:limit]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def limited(data, width, is_hash = false)
|
40
|
+
limit = get_limit_size
|
41
|
+
if data.length <= limit
|
42
|
+
data
|
43
|
+
else
|
44
|
+
# Calculate how many elements to be displayed above and below the separator.
|
45
|
+
head = limit / 2
|
46
|
+
tail = head - (limit - 1) % 2
|
47
|
+
|
48
|
+
# Add the proper elements to the temp array and format the separator.
|
49
|
+
temp = data[0, head] + [nil] + data[-tail, tail]
|
50
|
+
|
51
|
+
temp[head] = if is_hash
|
52
|
+
"#{indent}#{data[head].strip} .. #{data[data.length - tail - 1].strip}"
|
53
|
+
else
|
54
|
+
"#{indent}[#{head.to_s.rjust(width)}] .. [#{data.length - tail - 1}]"
|
55
|
+
end
|
56
|
+
|
57
|
+
temp
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AwesomePrint
|
2
|
+
module Registrar
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:extend, ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
attr_accessor :formatted_object_type
|
11
|
+
|
12
|
+
def formatter_for(type)
|
13
|
+
self.formatted_object_type = type
|
14
|
+
|
15
|
+
AwesomePrint::Formatter.register(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
|
-
#
|
3
|
-
# Awesome Print is freely distributable under the terms of MIT license.
|
4
|
-
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
5
|
-
#------------------------------------------------------------------------------
|
6
1
|
module AwesomePrint
|
2
|
+
|
3
|
+
def self.debug
|
4
|
+
false #true
|
5
|
+
end
|
6
|
+
|
7
7
|
def self.version
|
8
|
-
'
|
8
|
+
'2.0.0.pre'
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'AwesomePrint' do
|
4
|
+
describe 'Array' do
|
5
|
+
before do
|
6
|
+
@arr = [1, :two, 'three', [nil, [true, false]]]
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'empty array' do
|
10
|
+
expect([].ai).to eq('[]')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'plain multiline' do
|
14
|
+
expect(@arr.ai(plain: true)).to eq <<-EOS.strip
|
15
|
+
[
|
16
|
+
[0] 1,
|
17
|
+
[1] :two,
|
18
|
+
[2] "three",
|
19
|
+
[3] [
|
20
|
+
[0] nil,
|
21
|
+
[1] [
|
22
|
+
[0] true,
|
23
|
+
[1] false
|
24
|
+
]
|
25
|
+
]
|
26
|
+
]
|
27
|
+
EOS
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'plain multiline without index' do
|
31
|
+
expect(@arr.ai(plain: true, index: false)).to eq <<-EOS.strip
|
32
|
+
[
|
33
|
+
1,
|
34
|
+
:two,
|
35
|
+
"three",
|
36
|
+
[
|
37
|
+
nil,
|
38
|
+
[
|
39
|
+
true,
|
40
|
+
false
|
41
|
+
]
|
42
|
+
]
|
43
|
+
]
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'plain multiline indented' do
|
48
|
+
expect(@arr.ai(plain: true, indent: 2)).to eq <<-EOS.strip
|
49
|
+
[
|
50
|
+
[0] 1,
|
51
|
+
[1] :two,
|
52
|
+
[2] "three",
|
53
|
+
[3] [
|
54
|
+
[0] nil,
|
55
|
+
[1] [
|
56
|
+
[0] true,
|
57
|
+
[1] false
|
58
|
+
]
|
59
|
+
]
|
60
|
+
]
|
61
|
+
EOS
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'plain multiline indented without index' do
|
65
|
+
expect(@arr.ai(plain: true, indent: 2, index: false)).to eq <<-EOS.strip
|
66
|
+
[
|
67
|
+
1,
|
68
|
+
:two,
|
69
|
+
"three",
|
70
|
+
[
|
71
|
+
nil,
|
72
|
+
[
|
73
|
+
true,
|
74
|
+
false
|
75
|
+
]
|
76
|
+
]
|
77
|
+
]
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'plain single line' do
|
82
|
+
expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, :two, "three", [ nil, [ true, false ] ] ]')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'colored multiline (default)' do
|
86
|
+
expect(@arr.ai).to eq <<-EOS.strip
|
87
|
+
[
|
88
|
+
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
89
|
+
\e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
|
90
|
+
\e[1;37m[2] \e[0m\e[0;33m\"three\"\e[0m,
|
91
|
+
\e[1;37m[3] \e[0m[
|
92
|
+
\e[1;37m[0] \e[0m\e[1;31mnil\e[0m,
|
93
|
+
\e[1;37m[1] \e[0m[
|
94
|
+
\e[1;37m[0] \e[0m\e[1;32mtrue\e[0m,
|
95
|
+
\e[1;37m[1] \e[0m\e[1;31mfalse\e[0m
|
96
|
+
]
|
97
|
+
]
|
98
|
+
]
|
99
|
+
EOS
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'colored multiline indented' do
|
103
|
+
expect(@arr.ai(indent: 8)).to eq <<-EOS.strip
|
104
|
+
[
|
105
|
+
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
106
|
+
\e[1;37m[1] \e[0m\e[0;36m:two\e[0m,
|
107
|
+
\e[1;37m[2] \e[0m\e[0;33m\"three\"\e[0m,
|
108
|
+
\e[1;37m[3] \e[0m[
|
109
|
+
\e[1;37m[0] \e[0m\e[1;31mnil\e[0m,
|
110
|
+
\e[1;37m[1] \e[0m[
|
111
|
+
\e[1;37m[0] \e[0m\e[1;32mtrue\e[0m,
|
112
|
+
\e[1;37m[1] \e[0m\e[1;31mfalse\e[0m
|
113
|
+
]
|
114
|
+
]
|
115
|
+
]
|
116
|
+
EOS
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'colored single line' do
|
120
|
+
expect(@arr.ai(multiline: false)).to eq("[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#------------------------------------------------------------------------------
|
125
|
+
describe 'Nested Array' do
|
126
|
+
before do
|
127
|
+
@arr = [1, 2]
|
128
|
+
@arr << @arr
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'plain multiline' do
|
132
|
+
expect(@arr.ai(plain: true)).to eq <<-EOS.strip
|
133
|
+
[
|
134
|
+
[0] 1,
|
135
|
+
[1] 2,
|
136
|
+
[2] [...]
|
137
|
+
]
|
138
|
+
EOS
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'plain multiline without index' do
|
142
|
+
expect(@arr.ai(plain: true, index: false)).to eq <<-EOS.strip
|
143
|
+
[
|
144
|
+
1,
|
145
|
+
2,
|
146
|
+
[...]
|
147
|
+
]
|
148
|
+
EOS
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'plain single line' do
|
152
|
+
expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, 2, [...] ]')
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
#------------------------------------------------------------------------------
|
157
|
+
describe 'Limited Output Array' do
|
158
|
+
before(:each) do
|
159
|
+
@arr = (1..1000).to_a
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'plain limited output large' do
|
163
|
+
expect(@arr.ai(plain: true, limit: true)).to eq <<-EOS.strip
|
164
|
+
[
|
165
|
+
[ 0] 1,
|
166
|
+
[ 1] 2,
|
167
|
+
[ 2] 3,
|
168
|
+
[ 3] .. [996],
|
169
|
+
[997] 998,
|
170
|
+
[998] 999,
|
171
|
+
[999] 1000
|
172
|
+
]
|
173
|
+
EOS
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'plain limited output small' do
|
177
|
+
@arr = @arr[0..3]
|
178
|
+
expect(@arr.ai(plain: true, limit: true)).to eq <<-EOS.strip
|
179
|
+
[
|
180
|
+
[0] 1,
|
181
|
+
[1] 2,
|
182
|
+
[2] 3,
|
183
|
+
[3] 4
|
184
|
+
]
|
185
|
+
EOS
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'plain limited output with 10 lines' do
|
189
|
+
expect(@arr.ai(plain: true, limit: 10)).to eq <<-EOS.strip
|
190
|
+
[
|
191
|
+
[ 0] 1,
|
192
|
+
[ 1] 2,
|
193
|
+
[ 2] 3,
|
194
|
+
[ 3] 4,
|
195
|
+
[ 4] 5,
|
196
|
+
[ 5] .. [995],
|
197
|
+
[996] 997,
|
198
|
+
[997] 998,
|
199
|
+
[998] 999,
|
200
|
+
[999] 1000
|
201
|
+
]
|
202
|
+
EOS
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'plain limited output with 11 lines' do
|
206
|
+
expect(@arr.ai(plain: true, limit: 11)).to eq <<-EOS.strip
|
207
|
+
[
|
208
|
+
[ 0] 1,
|
209
|
+
[ 1] 2,
|
210
|
+
[ 2] 3,
|
211
|
+
[ 3] 4,
|
212
|
+
[ 4] 5,
|
213
|
+
[ 5] .. [994],
|
214
|
+
[995] 996,
|
215
|
+
[996] 997,
|
216
|
+
[997] 998,
|
217
|
+
[998] 999,
|
218
|
+
[999] 1000
|
219
|
+
]
|
220
|
+
EOS
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
#------------------------------------------------------------------------------
|
225
|
+
describe 'Inherited from standard Ruby classes' do
|
226
|
+
after do
|
227
|
+
Object.instance_eval { remove_const :My } if defined?(My)
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'inherited from Array should be displayed as Array' do
|
231
|
+
class My < Array; end
|
232
|
+
|
233
|
+
my = My.new([1, :two, 'three', [nil, [true, false]]])
|
234
|
+
expect(my.ai(plain: true)).to eq <<-EOS.strip
|
235
|
+
[
|
236
|
+
[0] 1,
|
237
|
+
[1] :two,
|
238
|
+
[2] "three",
|
239
|
+
[3] [
|
240
|
+
[0] nil,
|
241
|
+
[1] [
|
242
|
+
[0] true,
|
243
|
+
[1] false
|
244
|
+
]
|
245
|
+
]
|
246
|
+
]
|
247
|
+
EOS
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
end
|