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,255 +8,255 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_WithCause < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
class SomeExceptionWithCause < ::Exception
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
include ::Xqsr3::Diagnostics::Exceptions::WithCause
|
14
|
+
end
|
15
15
|
|
16
|
-
|
16
|
+
def test_no_ctor_args
|
17
17
|
|
18
|
-
|
18
|
+
x = SomeExceptionWithCause.new
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
assert_nil x.cause
|
21
|
+
assert_equal SomeExceptionWithCause.to_s, x.message
|
22
|
+
assert_equal SomeExceptionWithCause.to_s, x.chained_message
|
23
|
+
assert_empty x.chainees
|
24
|
+
assert_equal [ x ], x.exceptions
|
25
|
+
assert_nil x.backtrace
|
26
|
+
assert_empty x.options
|
27
|
+
end
|
28
28
|
|
29
|
-
|
29
|
+
def test_1_ctor_arg_that_is_a_message
|
30
30
|
|
31
|
-
|
31
|
+
msg = 'stuff'
|
32
32
|
|
33
|
-
|
33
|
+
x = SomeExceptionWithCause.new msg
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
assert_nil x.cause
|
36
|
+
assert_equal msg, x.message
|
37
|
+
assert_equal msg, x.chained_message
|
38
|
+
assert_empty x.chainees
|
39
|
+
assert_equal [ x ], x.exceptions
|
40
|
+
assert_nil x.backtrace
|
41
|
+
assert_empty x.options
|
42
|
+
end
|
43
43
|
|
44
|
-
|
44
|
+
def test_1_ctor_arg_that_is_a_cause_and_has_no_message
|
45
45
|
|
46
|
-
|
46
|
+
c = RuntimeError.new
|
47
47
|
|
48
|
-
|
48
|
+
x = SomeExceptionWithCause.new c
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
assert_not_nil x.cause
|
51
|
+
assert_equal SomeExceptionWithCause.to_s, x.message
|
52
|
+
assert_equal "#{SomeExceptionWithCause.to_s}: #{RuntimeError.to_s}", x.chained_message
|
53
|
+
assert_not_empty x.chainees
|
54
|
+
assert_equal [ c ], x.chainees
|
55
|
+
assert_equal [ x, c ], x.exceptions
|
56
|
+
assert_nil x.backtrace
|
57
|
+
assert_empty x.options
|
58
|
+
end
|
59
59
|
|
60
|
-
|
60
|
+
def test_1_ctor_arg_that_is_a_cause_and_has_a_message
|
61
61
|
|
62
|
-
|
62
|
+
c = RuntimeError.new 'blah'
|
63
63
|
|
64
|
-
|
64
|
+
x = SomeExceptionWithCause.new c
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
assert_not_nil x.cause
|
67
|
+
assert_equal 'blah', x.message
|
68
|
+
assert_equal 'blah', x.chained_message
|
69
|
+
assert_not_empty x.chainees
|
70
|
+
assert_equal [ c ], x.chainees
|
71
|
+
assert_equal [ x, c ], x.exceptions
|
72
|
+
assert_nil x.backtrace
|
73
|
+
assert_empty x.options
|
74
|
+
end
|
75
75
|
|
76
|
-
|
76
|
+
def test_2_ctor_args_that_are_message_and_cause
|
77
77
|
|
78
|
-
|
78
|
+
msg = 'stuff'
|
79
79
|
|
80
|
-
|
80
|
+
c = RuntimeError.new
|
81
81
|
|
82
|
-
|
82
|
+
x = SomeExceptionWithCause.new msg, c
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
assert_not_nil x.cause
|
85
|
+
assert_equal msg, x.message
|
86
|
+
assert_equal "#{msg}: #{RuntimeError.to_s}", x.chained_message
|
87
|
+
assert_not_empty x.chainees
|
88
|
+
assert_equal [ c ], x.chainees
|
89
|
+
assert_equal [ x, c ], x.exceptions
|
90
|
+
assert_nil x.backtrace
|
91
|
+
assert_empty x.options
|
92
|
+
end
|
93
93
|
|
94
|
-
|
94
|
+
def test_2_ctor_args_that_are_message_and_cause_that_has_a_message
|
95
95
|
|
96
|
-
|
96
|
+
msg = 'stuff'
|
97
97
|
|
98
|
-
|
98
|
+
c = RuntimeError.new 'blah'
|
99
99
|
|
100
|
-
|
100
|
+
x = SomeExceptionWithCause.new msg, c
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
assert_not_nil x.cause
|
103
|
+
assert_equal msg, x.message
|
104
|
+
assert_equal 'stuff: blah', x.chained_message
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
assert_not_empty x.chainees
|
107
|
+
assert_equal [ c ], x.chainees
|
108
|
+
assert_equal [ x, c ], x.exceptions
|
109
|
+
assert_nil x.backtrace
|
110
|
+
assert_empty x.options
|
111
|
+
end
|
112
112
|
|
113
|
-
|
113
|
+
def test_cause_in_options
|
114
114
|
|
115
|
-
|
115
|
+
c = RuntimeError.new 'inner'
|
116
116
|
|
117
|
-
|
117
|
+
x = SomeExceptionWithCause.new 'outer', cause: c
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
assert_not_nil x.cause
|
120
|
+
assert_equal 'outer', x.message
|
121
|
+
assert_equal 'outer: inner', x.chained_message
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
123
|
+
assert_not_empty x.chainees
|
124
|
+
assert_equal [ c ], x.chainees
|
125
|
+
assert_equal [ x, c ], x.exceptions
|
126
|
+
assert_nil x.backtrace
|
127
|
+
assert_empty x.options
|
128
|
+
end
|
129
129
|
|
130
130
|
|
131
131
|
|
132
|
-
|
132
|
+
class GrandchildException < Exception
|
133
133
|
|
134
|
-
|
135
|
-
|
134
|
+
include ::Xqsr3::Diagnostics::Exceptions::WithCause
|
135
|
+
end
|
136
136
|
|
137
|
-
|
137
|
+
class ChildException < Exception
|
138
138
|
|
139
|
-
|
139
|
+
def initialize(*args, **options)
|
140
140
|
|
141
|
-
|
142
|
-
|
141
|
+
super *args, **options
|
142
|
+
end
|
143
143
|
|
144
|
-
|
145
|
-
|
144
|
+
include ::Xqsr3::Diagnostics::Exceptions::WithCause
|
145
|
+
end
|
146
146
|
|
147
|
-
|
147
|
+
class ParentException < Exception
|
148
148
|
|
149
|
-
|
149
|
+
include ::Xqsr3::Diagnostics::Exceptions::WithCause
|
150
150
|
|
151
|
-
|
151
|
+
def initialize(*args, **options)
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
153
|
+
super *args, **options
|
154
|
+
end
|
155
|
+
end
|
156
156
|
|
157
|
-
|
157
|
+
class GrandparentException < Exception
|
158
158
|
|
159
|
-
|
160
|
-
|
159
|
+
include ::Xqsr3::Diagnostics::Exceptions::WithCause
|
160
|
+
end
|
161
161
|
|
162
162
|
|
163
|
-
|
163
|
+
def test_four_levels
|
164
164
|
|
165
|
-
|
165
|
+
gc = GrandchildException.new 'gc'
|
166
166
|
|
167
|
-
|
167
|
+
c = ChildException.new 'c', gc
|
168
168
|
|
169
|
-
|
169
|
+
p = ParentException.new c, 'p'
|
170
170
|
|
171
|
-
|
171
|
+
gp = GrandparentException.new 'gp', cause: p
|
172
172
|
|
173
|
-
|
174
|
-
|
175
|
-
|
173
|
+
assert_equal 'gp: p: c: gc', gp.chained_message
|
174
|
+
assert_equal 'gp-p-c-gc', gp.chained_message(separator: '-')
|
175
|
+
end
|
176
176
|
end
|
177
177
|
|
178
178
|
class Test_WithCause_throwing < Test::Unit::TestCase
|
179
179
|
|
180
|
-
|
180
|
+
class SomeExceptionWithCause < ::Exception
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
include ::Xqsr3::Diagnostics::Exceptions::WithCause
|
183
|
+
end
|
184
184
|
|
185
|
-
|
185
|
+
def f m
|
186
186
|
|
187
|
-
|
188
|
-
|
187
|
+
raise SomeExceptionWithCause, m
|
188
|
+
end
|
189
189
|
|
190
|
-
|
190
|
+
def g m, n
|
191
191
|
|
192
|
-
|
192
|
+
begin
|
193
193
|
|
194
|
-
|
195
|
-
|
194
|
+
f n
|
195
|
+
rescue Exception => x
|
196
196
|
|
197
|
-
|
198
|
-
|
199
|
-
|
197
|
+
raise SomeExceptionWithCause.new m, x
|
198
|
+
end
|
199
|
+
end
|
200
200
|
|
201
|
-
|
201
|
+
def h m, n, o
|
202
202
|
|
203
|
-
|
203
|
+
begin
|
204
204
|
|
205
|
-
|
206
|
-
|
205
|
+
g n, 0
|
206
|
+
rescue Exception => x
|
207
207
|
|
208
|
-
|
209
|
-
|
210
|
-
|
208
|
+
raise SomeExceptionWithCause.new m, x
|
209
|
+
end
|
210
|
+
end
|
211
211
|
|
212
|
-
|
212
|
+
def test_one_level
|
213
213
|
|
214
|
-
|
214
|
+
begin
|
215
215
|
|
216
|
-
|
216
|
+
f 'one-level'
|
217
217
|
|
218
|
-
|
219
|
-
|
218
|
+
assert false, 'should not get here!'
|
219
|
+
rescue Exception => x
|
220
220
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
221
|
+
assert_nil x.cause
|
222
|
+
assert_equal 'one-level', x.message
|
223
|
+
assert_equal 'one-level', x.chained_message
|
224
|
+
assert_empty x.chainees
|
225
|
+
assert_not_empty x.backtrace
|
226
226
|
|
227
|
-
|
227
|
+
x_bt0 = x.backtrace[0]
|
228
228
|
|
229
|
-
|
230
|
-
|
231
|
-
|
229
|
+
assert /:in\s+\`f\'\s*$/ =~ x_bt0, 'not receieved from f()'
|
230
|
+
end
|
231
|
+
end
|
232
232
|
|
233
|
-
|
233
|
+
def test_two_levels
|
234
234
|
|
235
|
-
|
235
|
+
begin
|
236
236
|
|
237
|
-
|
237
|
+
g 'two-levels', 'one-level'
|
238
238
|
|
239
|
-
|
240
|
-
|
239
|
+
assert false, 'should not get here!'
|
240
|
+
rescue Exception => x
|
241
241
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
242
|
+
assert_not_nil x.cause
|
243
|
+
assert_equal 'two-levels', x.message
|
244
|
+
assert_equal 'two-levels: one-level', x.chained_message
|
245
|
+
assert_not_empty x.chainees
|
246
|
+
assert_kind_of SomeExceptionWithCause, x.chainees[0]
|
247
|
+
assert_not_empty x.backtrace
|
248
|
+
assert_not_empty x.cause.backtrace
|
249
249
|
|
250
|
-
|
250
|
+
x_bt0 = x.backtrace[0]
|
251
251
|
|
252
|
-
|
252
|
+
assert /:in\s+\`rescue in g\'\s*$/ =~ x_bt0, 'not receieved from g()'
|
253
253
|
|
254
|
-
|
254
|
+
c_bt0 = x.cause.backtrace[0]
|
255
255
|
|
256
|
-
|
256
|
+
assert /:in\s+\`f\'\s*$/ =~ c_bt0, 'not receieved from f()'
|
257
257
|
|
258
|
-
|
259
|
-
|
260
|
-
|
258
|
+
assert_not_empty x.chained_backtrace
|
259
|
+
end
|
260
|
+
end
|
261
261
|
end
|
262
262
|
|