xqsr3 0.38.1.1 → 0.39.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/examples/count_word_frequencies.md +13 -13
- data/examples/count_word_frequencies.rb +5 -5
- data/lib/xqsr3/array_utilities/join_with_or.rb +53 -54
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -67
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +405 -404
- data/lib/xqsr3/containers/multi_map.rb +454 -453
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +56 -57
- data/lib/xqsr3/conversion/integer_parser.rb +92 -93
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +152 -151
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +99 -95
- data/lib/xqsr3/diagnostics/inspect_builder.rb +86 -86
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +136 -136
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +18 -17
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +41 -41
- data/lib/xqsr3/extensions/enumerable/unique.rb +32 -31
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
- data/lib/xqsr3/extensions/hash/except.rb +16 -16
- data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
- data/lib/xqsr3/extensions/hash/match.rb +10 -10
- data/lib/xqsr3/extensions/hash/slice.rb +11 -11
- data/lib/xqsr3/extensions/hash.rb +1 -1
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
- data/lib/xqsr3/extensions/integer.rb +3 -0
- data/lib/xqsr3/extensions/io/writelines.rb +34 -34
- data/lib/xqsr3/extensions/kernel/integer.rb +26 -26
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +15 -14
- data/lib/xqsr3/extensions/kernel.rb +1 -0
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
- data/lib/xqsr3/extensions/string/map_option_string.rb +4 -5
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -2
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -9
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -2
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -62
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -38
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +71 -71
- data/lib/xqsr3/hash_utilities/key_matching.rb +82 -82
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +130 -88
- data/lib/xqsr3/io/writelines.rb +125 -125
- data/lib/xqsr3/quality/parameter_checking.rb +452 -453
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +64 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +33 -34
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +35 -35
- data/lib/xqsr3/string_utilities/quote_if.rb +55 -56
- data/lib/xqsr3/string_utilities/starts_with.rb +64 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +80 -80
- data/lib/xqsr3/string_utilities/truncate.rb +60 -61
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +19 -20
- data/test/performance/frequency_map.rb +13 -27
- data/test/scratch/test_assert_raise_with_message.rb +12 -13
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -142
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +607 -554
- data/test/unit/containers/tc_multi_map.rb +573 -522
- data/test/unit/conversion/tc_integer_parser.rb +73 -73
- data/test/unit/conversion/tc_to_bool.rb +26 -26
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
- data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
- data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
- data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
- data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
- data/test/unit/extensions/hash/tc_except.rb +28 -28
- data/test/unit/extensions/hash/tc_hash.rb +1 -1
- data/test/unit/extensions/hash/tc_slice.rb +14 -14
- data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
- data/test/unit/extensions/integer/ts_all.rb +12 -0
- data/test/unit/extensions/io/tc_writelines.rb +77 -77
- data/test/unit/extensions/kernel/tc_integer.rb +75 -75
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
- data/test/unit/extensions/object/tc_inspect.rb +51 -51
- data/test/unit/extensions/string/tc_bool.tb +24 -24
- data/test/unit/extensions/string/tc_ends_with.rb +53 -53
- data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
- data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
- data/test/unit/extensions/string/tc_quote_if.rb +18 -18
- data/test/unit/extensions/string/tc_starts_with.rb +53 -53
- data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
- data/test/unit/extensions/string/tc_truncate.rb +18 -18
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
- data/test/unit/hash_utilities/tc_has_match.rb +70 -70
- data/test/unit/hash_utilities/tc_match.rb +83 -83
- data/test/unit/io/tc_writelines.rb +106 -108
- data/test/unit/quality/tc_parameter_checking.rb +390 -390
- data/test/unit/string_utilities/tc_truncate.rb +28 -28
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -8,235 +8,235 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_X_Kernel_raise_with_options < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
OS_IS_WINDOWS = (RUBY_PLATFORM =~ /(mswin|mingw|bccwin|wince)/i) ? true : false
|
12
|
+
LINE_NUM_RE = OS_IS_WINDOWS ? /.+:(\d+):/ : /^[^:]+:(\d+)/
|
13
13
|
|
14
|
-
|
14
|
+
class ArgumentErrorWithOptions < ArgumentError
|
15
15
|
|
16
|
-
|
16
|
+
def initialize(message = nil, **options)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
super(message)
|
19
|
+
options ||= {}
|
20
|
+
@options = options
|
21
|
+
end
|
22
|
+
attr_reader :options
|
23
23
|
|
24
|
-
|
24
|
+
def exception(msg = nil, options = nil)
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
return self if msg.nil?
|
27
|
+
return self if msg.object_id == self.object_id
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
msg ||= self.message
|
30
|
+
options ||= {}
|
31
|
+
r = self.class.new msg, **self.options.merge(options)
|
32
|
+
r
|
33
|
+
end
|
34
|
+
end
|
35
35
|
|
36
|
-
|
36
|
+
def execute(&block)
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
block.call
|
39
|
+
end
|
40
40
|
|
41
|
-
|
41
|
+
def test_0
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
# standard raise: message-only
|
44
|
+
begin
|
45
45
|
|
46
|
-
|
46
|
+
raise "abc"
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
assert false, "should not get here"
|
49
|
+
rescue => x
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
assert_kind_of(RuntimeError, x)
|
52
|
+
assert_equal "abc", x.message
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
# RWO: message-only
|
56
|
+
begin
|
57
57
|
|
58
|
-
|
58
|
+
raise_with_options "abc"
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
assert false, "should not get here"
|
61
|
+
rescue => x
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
assert_kind_of(RuntimeError, x)
|
64
|
+
assert_equal "abc", x.message
|
65
|
+
end
|
66
|
+
end
|
67
67
|
|
68
|
-
|
68
|
+
def test_1
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
# standard raise: class
|
71
|
+
begin
|
72
72
|
|
73
|
-
|
73
|
+
raise ArgumentError
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
assert false, "should not get here"
|
76
|
+
rescue => x
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
assert_kind_of(ArgumentError, x)
|
79
|
+
assert_equal "ArgumentError", x.message
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
# RWO: class + message
|
83
|
+
begin
|
84
84
|
|
85
|
-
|
85
|
+
raise_with_options ArgumentError
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
assert false, "should not get here"
|
88
|
+
rescue => x
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
assert_kind_of(ArgumentError, x)
|
91
|
+
assert_equal "ArgumentError", x.message
|
92
|
+
end
|
93
|
+
end
|
94
94
|
|
95
|
-
|
95
|
+
def test_2
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
# standard raise: class + message
|
98
|
+
begin
|
99
99
|
|
100
|
-
|
100
|
+
raise ArgumentError, "abc"
|
101
101
|
|
102
|
-
|
103
|
-
|
102
|
+
assert false, "should not get here"
|
103
|
+
rescue => x
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
assert_kind_of(ArgumentError, x)
|
106
|
+
assert_equal "abc", x.message
|
107
|
+
end
|
108
108
|
|
109
|
-
|
110
|
-
|
109
|
+
# RWO: class + message
|
110
|
+
begin
|
111
111
|
|
112
|
-
|
112
|
+
raise_with_options ArgumentError, "abc"
|
113
113
|
|
114
|
-
|
115
|
-
|
114
|
+
assert false, "should not get here"
|
115
|
+
rescue => x
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
assert_kind_of(ArgumentError, x)
|
118
|
+
assert_equal "abc", x.message
|
119
|
+
end
|
120
|
+
end
|
121
121
|
|
122
|
-
|
122
|
+
def test_2_b_no_options
|
123
123
|
|
124
|
-
|
125
|
-
|
124
|
+
# standard raise: class + message
|
125
|
+
begin
|
126
126
|
|
127
|
-
|
127
|
+
raise ArgumentErrorWithOptions, "abc"
|
128
128
|
|
129
|
-
|
130
|
-
|
129
|
+
assert false, "should not get here"
|
130
|
+
rescue => x
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
assert_kind_of(ArgumentError, x)
|
133
|
+
assert_equal "abc", x.message
|
134
|
+
end
|
135
135
|
|
136
|
-
|
137
|
-
|
136
|
+
# RWO: class + message
|
137
|
+
begin
|
138
138
|
|
139
|
-
|
139
|
+
raise_with_options ArgumentErrorWithOptions, "abc"
|
140
140
|
|
141
|
-
|
142
|
-
|
141
|
+
assert false, "should not get here"
|
142
|
+
rescue => x
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
assert_kind_of(ArgumentError, x)
|
145
|
+
assert_equal "abc", x.message
|
146
|
+
end
|
147
|
+
end
|
148
148
|
|
149
|
-
|
149
|
+
def test_2_b_with_options
|
150
150
|
|
151
|
-
|
152
|
-
|
151
|
+
# standard raise: class + message + options
|
152
|
+
begin
|
153
153
|
|
154
|
-
|
154
|
+
raise ArgumentErrorWithOptions.new("abc", blah: :blech, id: 23)
|
155
155
|
|
156
|
-
|
157
|
-
|
156
|
+
assert false, "should not get here"
|
157
|
+
rescue => x
|
158
158
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
159
|
+
assert_kind_of(ArgumentError, x)
|
160
|
+
assert_equal "abc", x.message
|
161
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
162
|
+
end
|
163
163
|
|
164
|
-
|
165
|
-
|
164
|
+
# RWO: class + message + options (raise-way)
|
165
|
+
begin
|
166
166
|
|
167
|
-
|
167
|
+
raise_with_options ArgumentErrorWithOptions.new("abc", blah: :blech, id: 23)
|
168
168
|
|
169
|
-
|
170
|
-
|
169
|
+
assert false, "should not get here"
|
170
|
+
rescue => x
|
171
171
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
172
|
+
assert_kind_of(ArgumentError, x)
|
173
|
+
assert_equal "abc", x.message
|
174
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
175
|
+
end
|
176
176
|
|
177
|
-
|
178
|
-
|
177
|
+
# RWO: class + message + options (raise_with_options-way)
|
178
|
+
begin
|
179
179
|
|
180
|
-
|
180
|
+
raise_with_options ArgumentErrorWithOptions, "abc", blah: :blech, id: 23
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
assert false, "should not get here"
|
183
|
+
rescue => x
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
185
|
+
assert_kind_of(ArgumentError, x)
|
186
|
+
assert_equal "abc", x.message
|
187
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
188
|
+
end
|
189
|
+
end
|
190
190
|
|
191
191
|
|
192
|
-
|
192
|
+
def test_with_backtrace
|
193
193
|
|
194
|
-
|
194
|
+
line_number = nil
|
195
195
|
|
196
|
-
|
197
|
-
|
196
|
+
# standard raise: class + message + stack trace
|
197
|
+
begin
|
198
198
|
|
199
|
-
|
199
|
+
begin
|
200
200
|
|
201
|
-
|
202
|
-
|
201
|
+
execute { line_number = __LINE__; raise ArgumentError }
|
202
|
+
rescue => x
|
203
203
|
|
204
|
-
|
205
|
-
|
204
|
+
raise x, "abc", x.backtrace
|
205
|
+
end
|
206
206
|
|
207
|
-
|
208
|
-
|
207
|
+
assert false, "should not get here"
|
208
|
+
rescue => x
|
209
209
|
|
210
|
-
|
211
|
-
|
210
|
+
assert_kind_of(ArgumentError, x)
|
211
|
+
assert_equal "abc", x.message
|
212
212
|
|
213
|
-
|
214
|
-
|
215
|
-
|
213
|
+
assert $@[0] =~ LINE_NUM_RE
|
214
|
+
assert_equal line_number.to_s, $1.to_s
|
215
|
+
end
|
216
216
|
|
217
|
-
|
218
|
-
|
217
|
+
# RWO: class + message + stack trace
|
218
|
+
begin
|
219
219
|
|
220
|
-
|
220
|
+
begin
|
221
221
|
|
222
|
-
|
222
|
+
execute { line_number = __LINE__; raise_with_options ArgumentErrorWithOptions, blah: :blech, id: 23 }
|
223
223
|
|
224
|
-
|
225
|
-
|
224
|
+
assert false, "should not get here"
|
225
|
+
rescue => x
|
226
226
|
|
227
|
-
|
228
|
-
|
227
|
+
raise x, "abc", x.backtrace
|
228
|
+
end
|
229
229
|
|
230
|
-
|
231
|
-
|
230
|
+
assert false, "should not get here"
|
231
|
+
rescue => x
|
232
232
|
|
233
|
-
|
234
|
-
|
235
|
-
|
233
|
+
assert_kind_of(ArgumentError, x)
|
234
|
+
assert_equal "abc", x.message
|
235
|
+
assert_equal ({ :blah => :blech, :id => 23 }), x.options
|
236
236
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
237
|
+
assert $@[0] =~ LINE_NUM_RE
|
238
|
+
assert_equal line_number.to_s, $1.to_s
|
239
|
+
end
|
240
|
+
end
|
241
241
|
end
|
242
242
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
|
4
4
|
|
@@ -9,92 +9,92 @@ require 'test/unit'
|
|
9
9
|
|
10
10
|
class Test_X_Object_inspect < Test::Unit::TestCase
|
11
11
|
|
12
|
-
|
12
|
+
class Example1
|
13
13
|
|
14
|
-
|
14
|
+
include ::Xqsr3::Diagnostics::InspectBuilder
|
15
15
|
|
16
|
-
|
16
|
+
def initialize **inspect_options
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
@alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
19
|
+
@letters = @alphabet.chars.map { |c| c.upcase }
|
20
|
+
@inspect_options = inspect_options
|
21
|
+
end
|
22
22
|
|
23
|
-
|
23
|
+
def inspect
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
make_inspect **@inspect_options
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
|
-
|
29
|
+
class ExampleWithHiddenFields < Example1
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
INSPECT_HIDDEN_FIELDS = [ 'letters' ]
|
32
|
+
end
|
33
33
|
|
34
|
-
|
34
|
+
def test_default_use
|
35
35
|
|
36
|
-
|
36
|
+
ex = Example1.new
|
37
37
|
|
38
|
-
|
38
|
+
assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+>\z/, ex.inspect
|
39
39
|
|
40
|
-
|
40
|
+
ex2 = ExampleWithHiddenFields.new
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+>\z/, ex2.inspect
|
43
|
+
end
|
44
44
|
|
45
|
-
|
45
|
+
def test_no_class
|
46
46
|
|
47
|
-
|
47
|
+
ex = Example1.new(no_class: true)
|
48
48
|
|
49
|
-
|
49
|
+
assert_match /\A#<0x\d+>\z/, ex.inspect
|
50
50
|
|
51
|
-
|
51
|
+
ex2 = ExampleWithHiddenFields.new(no_class: true)
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
assert_match /\A#<0x\d+>\z/, ex2.inspect
|
54
|
+
end
|
55
55
|
|
56
|
-
|
56
|
+
def test_no_object_id
|
57
57
|
|
58
|
-
|
58
|
+
ex = Example1.new(no_object_id: true)
|
59
59
|
|
60
|
-
|
60
|
+
assert_match /\A#<Test_X_Object_inspect::Example1>\z/, ex.inspect
|
61
61
|
|
62
|
-
|
62
|
+
ex2 = ExampleWithHiddenFields.new(no_object_id: true)
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields>\z/, ex2.inspect
|
65
|
+
end
|
66
66
|
|
67
|
-
|
67
|
+
def test_show_fields
|
68
68
|
|
69
|
-
|
69
|
+
ex = Example1.new(show_fields: true)
|
70
70
|
|
71
|
-
|
71
|
+
assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz';\s*@inspect_options.*;\s*@letters.*>\z/, ex.inspect
|
72
72
|
|
73
|
-
|
73
|
+
ex2 = ExampleWithHiddenFields.new(show_fields: true)
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz';\s*@inspect_options\(.+\)=[^;]+>\z/, ex2.inspect
|
76
|
+
end
|
77
77
|
|
78
|
-
|
78
|
+
def test_show_fields_hidden
|
79
79
|
|
80
|
-
|
80
|
+
ex = Example1.new(show_fields: true, hidden_fields: [ 'inspect_options' ])
|
81
81
|
|
82
|
-
|
82
|
+
assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz';\s*@letters.*>\z/, ex.inspect
|
83
83
|
|
84
|
-
|
84
|
+
ex2 = ExampleWithHiddenFields.new(show_fields: true, hidden_fields: [ 'inspect_options' ])
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz'>\z/, ex2.inspect
|
87
|
+
end
|
88
88
|
|
89
|
-
|
89
|
+
def test_show_fields_truncated
|
90
90
|
|
91
|
-
|
91
|
+
ex = Example1.new(show_fields: true, truncate_width: 10)
|
92
92
|
|
93
|
-
|
93
|
+
assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+:\s*@alphabet\(String\)='abcdefg...';\s*@inspect_options.*;\s*@letters.*>\z/, ex.inspect
|
94
94
|
|
95
|
-
|
95
|
+
ex2 = ExampleWithHiddenFields.new(show_fields: true, truncate_width: 10)
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+:\s*@alphabet\(String\)='abcdefg...';\s*@inspect_options.*>\z/, ex2.inspect
|
98
|
+
end
|
99
99
|
end
|
100
100
|
|
@@ -9,36 +9,36 @@ require 'test/unit'
|
|
9
9
|
|
10
10
|
class Test_String_to_bool < Test::Unit::TestCase
|
11
11
|
|
12
|
-
|
12
|
+
def test_parse_normal
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
assert_true 'true'.to_bool
|
15
|
+
assert_false 'false'.to_bool
|
16
|
+
end
|
17
17
|
|
18
|
-
|
18
|
+
def test_parse_custom_true_false
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
true_values = [ 'affirmative', 'yup' ]
|
21
|
+
false_values = [ 'negative', 'nope' ]
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
assert_true 'affirmative'.to_bool true_values: true_values, false_values: false_values
|
24
|
+
assert_true 'yup'.to_bool true_values: true_values, false_values: false_values
|
25
|
+
assert_nil 'true'.to_bool true_values: true_values, false_values: false_values
|
26
|
+
assert_false 'negative'.to_bool true_values: true_values, false_values: false_values
|
27
|
+
assert_false 'nope'.to_bool true_values: true_values, false_values: false_values
|
28
|
+
assert_nil 'false'.to_bool true_values: true_values, false_values: false_values
|
29
|
+
end
|
30
30
|
|
31
|
-
|
31
|
+
def test_parse_custom_true_false_regexes
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
true_values = [ /affirm/, /yup/ ]
|
34
|
+
false_values = [ 'negative', /no/ ]
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
assert_true 'affirmative'.to_bool true_values: true_values, false_values: false_values
|
37
|
+
assert_true 'yup'.to_bool true_values: true_values, false_values: false_values
|
38
|
+
assert_nil 'true'.to_bool true_values: true_values, false_values: false_values
|
39
|
+
assert_false 'negative'.to_bool true_values: true_values, false_values: false_values
|
40
|
+
assert_false 'nope'.to_bool true_values: true_values, false_values: false_values
|
41
|
+
assert_nil 'false'.to_bool true_values: true_values, false_values: false_values
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|