xqsr3 0.38.2 → 0.39.2
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 +12 -12
- data/examples/count_word_frequencies.rb +4 -4
- data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +399 -399
- data/lib/xqsr3/containers/multi_map.rb +448 -448
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +51 -51
- data/lib/xqsr3/conversion/integer_parser.rb +87 -87
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
- data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +130 -130
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
- data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
- 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 +28 -28
- data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
- 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 -4
- 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 -1
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -1
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
- data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
- data/lib/xqsr3/io/writelines.rb +122 -120
- data/lib/xqsr3/quality/parameter_checking.rb +445 -445
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
- data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
- data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
- data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
- data/lib/xqsr3/string_utilities/truncate.rb +55 -55
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +12 -12
- data/test/performance/frequency_map.rb +12 -12
- data/test/scratch/test_assert_raise_with_message.rb +11 -11
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +591 -591
- data/test/unit/containers/tc_multi_map.rb +558 -558
- data/test/unit/conversion/tc_integer_parser.rb +72 -72
- data/test/unit/conversion/tc_to_bool.rb +25 -25
- 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_slice.rb +13 -13
- 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 +149 -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 +50 -50
- 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 +166 -106
- data/test/unit/quality/tc_parameter_checking.rb +389 -389
- data/test/unit/string_utilities/tc_truncate.rb +27 -27
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -10,101 +10,101 @@ require 'test/unit'
|
|
10
10
|
|
11
11
|
class Test_IntegerParser < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
13
|
+
IP = ::Xqsr3::Conversion::IntegerParser
|
14
14
|
|
15
|
-
|
15
|
+
class SomeRandomException < Exception; end
|
16
16
|
|
17
|
-
|
17
|
+
def test_show_base_being_ignored
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
assert_equal(-100, IP.to_integer(-100))
|
20
|
+
assert_equal(-100, IP.to_integer(-100, 0))
|
21
|
+
assert_equal(-100, IP.to_integer(-100.0, 0))
|
22
|
+
assert_equal(-100, IP.to_integer(-100.0, 10))
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
assert_equal(-100, IP.to_integer('-100'))
|
25
|
+
assert_equal(-100, IP.to_integer('-100', 0))
|
26
|
+
assert_equal(-100, IP.to_integer('-100', 10))
|
27
|
+
assert_equal(-4, IP.to_integer('-100', 2))
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
def test_default_for_invalid_type
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
assert_equal 12345, IP.to_integer(12..345, default: 12345)
|
33
|
+
end
|
34
34
|
|
35
|
-
|
35
|
+
def test_to_integer_with_valid_values
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
assert_equal(0, IP.to_integer(0))
|
38
|
+
assert_equal(+1, IP.to_integer(1))
|
39
|
+
assert_equal(+1, IP.to_integer(+1))
|
40
|
+
assert_equal(-1, IP.to_integer(-1))
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
assert_equal(0, IP.to_integer('0'))
|
43
|
+
assert_equal(+1, IP.to_integer('1'))
|
44
|
+
assert_equal(+1, IP.to_integer('+1'))
|
45
|
+
assert_equal(-1, IP.to_integer('-1'))
|
46
|
+
end
|
47
47
|
|
48
|
-
|
48
|
+
def test_to_integer_with_invalid_values
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
assert_raise(TypeError) { IP.to_integer nil }
|
51
|
+
assert_raise(ArgumentError) { IP.to_integer '' }
|
52
|
+
assert_raise(ArgumentError) { IP.to_integer 'abc' }
|
53
|
+
assert_raise(ArgumentError) { IP.to_integer 'zero' }
|
54
|
+
assert_raise(ArgumentError) { IP.to_integer 'plus 1' }
|
55
|
+
assert_raise(ArgumentError) { IP.to_integer '/0' }
|
56
|
+
end
|
57
57
|
|
58
|
-
|
58
|
+
def test_to_integer_with_invalid_values_returning_nil
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
assert_nil IP.to_integer(nil, nil: true)
|
61
|
+
assert_nil IP.to_integer('', nil: true)
|
62
|
+
assert_nil IP.to_integer('abc', nil: true)
|
63
|
+
assert_nil IP.to_integer('zero', nil: true)
|
64
|
+
assert_nil IP.to_integer('plus 1', nil: true)
|
65
|
+
assert_nil IP.to_integer('/0', nil: true)
|
66
|
+
end
|
67
67
|
|
68
|
-
|
68
|
+
def test_to_integer_with_invalid_values_returning_0
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
assert_equal 0, IP.to_integer(nil, default: 0)
|
71
|
+
assert_equal 0, IP.to_integer('', default: 0)
|
72
|
+
assert_equal 0, IP.to_integer('abc', default: 0)
|
73
|
+
assert_equal 0, IP.to_integer('zero', default: 0)
|
74
|
+
assert_equal 0, IP.to_integer('plus 1', default: 0)
|
75
|
+
assert_equal 0, IP.to_integer('/0', default: 0)
|
76
|
+
end
|
77
77
|
|
78
|
-
|
78
|
+
def test_to_integer_with_invalid_values_returning_sentinel
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
assert_equal :sentinel, IP.to_integer(nil, default: :sentinel)
|
81
|
+
assert_equal :sentinel, IP.to_integer('', default: :sentinel)
|
82
|
+
assert_equal :sentinel, IP.to_integer('abc', default: :sentinel)
|
83
|
+
assert_equal :sentinel, IP.to_integer('zero', default: :sentinel)
|
84
|
+
assert_equal :sentinel, IP.to_integer('plus 1', default: :sentinel)
|
85
|
+
assert_equal :sentinel, IP.to_integer('/0', default: :sentinel)
|
86
|
+
end
|
87
87
|
|
88
|
-
|
88
|
+
def test_to_integer_with_invalid_values_returning_sentinel_of_nil
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
90
|
+
assert_equal nil, IP.to_integer(nil, default: nil)
|
91
|
+
assert_equal nil, IP.to_integer('', default: nil)
|
92
|
+
assert_equal nil, IP.to_integer('abc', default: nil)
|
93
|
+
assert_equal nil, IP.to_integer('zero', default: nil)
|
94
|
+
assert_equal nil, IP.to_integer('plus 1', default: nil)
|
95
|
+
assert_equal nil, IP.to_integer('/0', default: nil)
|
96
|
+
end
|
97
97
|
|
98
|
-
|
98
|
+
def test_to_integer_with_invalid_values_and_block
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
assert_equal nil, IP.to_integer(nil) { nil }
|
101
|
+
assert_equal nil, IP.to_integer('blah') { nil }
|
102
102
|
|
103
|
-
|
104
|
-
|
103
|
+
assert_equal 'one', IP.to_integer(nil) { 'one' }
|
104
|
+
assert_equal 'one', IP.to_integer('blah') { 'one' }
|
105
105
|
|
106
|
-
|
107
|
-
|
106
|
+
assert_raise(SomeRandomException) { IP.to_integer(nil) { raise SomeRandomException.new } }
|
107
|
+
end
|
108
108
|
end
|
109
109
|
|
110
110
|
|
@@ -9,38 +9,38 @@ require 'test/unit'
|
|
9
9
|
|
10
10
|
class Test_Xqsr3_ConversionMultiMap < Test::Unit::TestCase
|
11
11
|
|
12
|
-
|
12
|
+
include ::Xqsr3::Conversion
|
13
13
|
|
14
|
-
|
14
|
+
def test_parse_normal
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
assert_true BoolParser.to_bool 'true'
|
17
|
+
assert_false BoolParser.to_bool 'false'
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_parse_custom_true_false
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
true_values = [ 'affirmative', 'yup' ]
|
23
|
+
false_values = [ 'negative', 'nope' ]
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
assert_true BoolParser.to_bool 'affirmative', true_values: true_values, false_values: false_values
|
26
|
+
assert_true BoolParser.to_bool 'yup', true_values: true_values, false_values: false_values
|
27
|
+
assert_nil BoolParser.to_bool 'true', true_values: true_values, false_values: false_values
|
28
|
+
assert_false BoolParser.to_bool 'negative', true_values: true_values, false_values: false_values
|
29
|
+
assert_false BoolParser.to_bool 'nope', true_values: true_values, false_values: false_values
|
30
|
+
assert_nil BoolParser.to_bool 'false', true_values: true_values, false_values: false_values
|
31
|
+
end
|
32
32
|
|
33
|
-
|
33
|
+
def test_parse_custom_true_false_regexes
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
true_values = [ /affirm/, /yup/ ]
|
36
|
+
false_values = [ 'negative', /no/ ]
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
assert_true BoolParser.to_bool 'affirmative', true_values: true_values, false_values: false_values
|
39
|
+
assert_true BoolParser.to_bool 'yup', true_values: true_values, false_values: false_values
|
40
|
+
assert_nil BoolParser.to_bool 'true', true_values: true_values, false_values: false_values
|
41
|
+
assert_false BoolParser.to_bool 'negative', true_values: true_values, false_values: false_values
|
42
|
+
assert_false BoolParser.to_bool 'nope', true_values: true_values, false_values: false_values
|
43
|
+
assert_nil BoolParser.to_bool 'false', true_values: true_values, false_values: false_values
|
44
|
+
end
|
45
45
|
end
|
46
46
|
|
@@ -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
|
|