xqsr3 0.38.2 → 0.39.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -6
  3. data/examples/count_word_frequencies.md +12 -12
  4. data/examples/count_word_frequencies.rb +4 -4
  5. data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
  6. data/lib/xqsr3/array_utilities.rb +2 -2
  7. data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
  8. data/lib/xqsr3/command_line_utilities.rb +2 -2
  9. data/lib/xqsr3/containers/frequency_map.rb +399 -399
  10. data/lib/xqsr3/containers/multi_map.rb +448 -448
  11. data/lib/xqsr3/containers.rb +3 -3
  12. data/lib/xqsr3/conversion/bool_parser.rb +51 -51
  13. data/lib/xqsr3/conversion/integer_parser.rb +87 -87
  14. data/lib/xqsr3/conversion.rb +3 -3
  15. data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
  16. data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
  17. data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
  18. data/lib/xqsr3/diagnostics.rb +3 -3
  19. data/lib/xqsr3/doc_.rb +130 -130
  20. data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
  21. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
  22. data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
  23. data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
  24. data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
  25. data/lib/xqsr3/extensions/hash/except.rb +16 -16
  26. data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
  27. data/lib/xqsr3/extensions/hash/match.rb +10 -10
  28. data/lib/xqsr3/extensions/hash/slice.rb +11 -11
  29. data/lib/xqsr3/extensions/hash.rb +1 -1
  30. data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
  31. data/lib/xqsr3/extensions/integer.rb +3 -0
  32. data/lib/xqsr3/extensions/io/writelines.rb +28 -28
  33. data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
  34. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
  35. data/lib/xqsr3/extensions/kernel.rb +1 -0
  36. data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
  37. data/lib/xqsr3/extensions/string/map_option_string.rb +4 -4
  38. data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
  39. data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
  40. data/lib/xqsr3/extensions/string/quote_if.rb +1 -1
  41. data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
  42. data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
  43. data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
  44. data/lib/xqsr3/extensions/string/truncate.rb +1 -1
  45. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
  46. data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
  47. data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
  48. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
  49. data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
  50. data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
  51. data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
  52. data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
  53. data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
  54. data/lib/xqsr3/extensions.rb +5 -5
  55. data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
  56. data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
  57. data/lib/xqsr3/hash_utilities.rb +3 -3
  58. data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
  59. data/lib/xqsr3/io/writelines.rb +122 -120
  60. data/lib/xqsr3/quality/parameter_checking.rb +445 -445
  61. data/lib/xqsr3/quality.rb +2 -2
  62. data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
  63. data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
  64. data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
  65. data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
  66. data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
  67. data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
  68. data/lib/xqsr3/string_utilities/truncate.rb +55 -55
  69. data/lib/xqsr3/string_utilities.rb +8 -8
  70. data/lib/xqsr3/version.rb +12 -12
  71. data/test/performance/frequency_map.rb +12 -12
  72. data/test/scratch/test_assert_raise_with_message.rb +11 -11
  73. data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
  74. data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
  75. data/test/unit/containers/tc_frequency_map.rb +591 -591
  76. data/test/unit/containers/tc_multi_map.rb +558 -558
  77. data/test/unit/conversion/tc_integer_parser.rb +72 -72
  78. data/test/unit/conversion/tc_to_bool.rb +25 -25
  79. data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
  80. data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
  81. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
  82. data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
  83. data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
  84. data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
  85. data/test/unit/extensions/hash/tc_except.rb +28 -28
  86. data/test/unit/extensions/hash/tc_slice.rb +13 -13
  87. data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
  88. data/test/unit/extensions/integer/ts_all.rb +12 -0
  89. data/test/unit/extensions/io/tc_writelines.rb +149 -77
  90. data/test/unit/extensions/kernel/tc_integer.rb +75 -75
  91. data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
  92. data/test/unit/extensions/object/tc_inspect.rb +50 -50
  93. data/test/unit/extensions/string/tc_bool.tb +24 -24
  94. data/test/unit/extensions/string/tc_ends_with.rb +53 -53
  95. data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
  96. data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
  97. data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
  98. data/test/unit/extensions/string/tc_quote_if.rb +18 -18
  99. data/test/unit/extensions/string/tc_starts_with.rb +53 -53
  100. data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
  101. data/test/unit/extensions/string/tc_truncate.rb +18 -18
  102. data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
  103. data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
  104. data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
  105. data/test/unit/hash_utilities/tc_has_match.rb +70 -70
  106. data/test/unit/hash_utilities/tc_match.rb +83 -83
  107. data/test/unit/io/tc_writelines.rb +166 -106
  108. data/test/unit/quality/tc_parameter_checking.rb +389 -389
  109. data/test/unit/string_utilities/tc_truncate.rb +27 -27
  110. data/test/unit/tc_version.rb +15 -15
  111. metadata +6 -2
@@ -10,101 +10,101 @@ require 'test/unit'
10
10
 
11
11
  class Test_IntegerParser < Test::Unit::TestCase
12
12
 
13
- IP = ::Xqsr3::Conversion::IntegerParser
13
+ IP = ::Xqsr3::Conversion::IntegerParser
14
14
 
15
- class SomeRandomException < Exception; end
15
+ class SomeRandomException < Exception; end
16
16
 
17
- def test_show_base_being_ignored
17
+ def test_show_base_being_ignored
18
18
 
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)
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
- 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
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
- def test_default_for_invalid_type
30
+ def test_default_for_invalid_type
31
31
 
32
- assert_equal 12345, IP.to_integer(12..345, default: 12345)
33
- end
32
+ assert_equal 12345, IP.to_integer(12..345, default: 12345)
33
+ end
34
34
 
35
- def test_to_integer_with_valid_values
35
+ def test_to_integer_with_valid_values
36
36
 
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)
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
- 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
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
- def test_to_integer_with_invalid_values
48
+ def test_to_integer_with_invalid_values
49
49
 
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
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
- def test_to_integer_with_invalid_values_returning_nil
58
+ def test_to_integer_with_invalid_values_returning_nil
59
59
 
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
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
- def test_to_integer_with_invalid_values_returning_0
68
+ def test_to_integer_with_invalid_values_returning_0
69
69
 
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
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
- def test_to_integer_with_invalid_values_returning_sentinel
78
+ def test_to_integer_with_invalid_values_returning_sentinel
79
79
 
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
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
- def test_to_integer_with_invalid_values_returning_sentinel_of_nil
88
+ def test_to_integer_with_invalid_values_returning_sentinel_of_nil
89
89
 
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
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
- def test_to_integer_with_invalid_values_and_block
98
+ def test_to_integer_with_invalid_values_and_block
99
99
 
100
- assert_equal nil, IP.to_integer(nil) { nil }
101
- assert_equal nil, IP.to_integer('blah') { nil }
100
+ assert_equal nil, IP.to_integer(nil) { nil }
101
+ assert_equal nil, IP.to_integer('blah') { nil }
102
102
 
103
- assert_equal 'one', IP.to_integer(nil) { 'one' }
104
- assert_equal 'one', IP.to_integer('blah') { 'one' }
103
+ assert_equal 'one', IP.to_integer(nil) { 'one' }
104
+ assert_equal 'one', IP.to_integer('blah') { 'one' }
105
105
 
106
- assert_raise(SomeRandomException) { IP.to_integer(nil) { raise SomeRandomException.new } }
107
- end
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
- include ::Xqsr3::Conversion
12
+ include ::Xqsr3::Conversion
13
13
 
14
- def test_parse_normal
14
+ def test_parse_normal
15
15
 
16
- assert_true BoolParser.to_bool 'true'
17
- assert_false BoolParser.to_bool 'false'
18
- end
16
+ assert_true BoolParser.to_bool 'true'
17
+ assert_false BoolParser.to_bool 'false'
18
+ end
19
19
 
20
- def test_parse_custom_true_false
20
+ def test_parse_custom_true_false
21
21
 
22
- true_values = [ 'affirmative', 'yup' ]
23
- false_values = [ 'negative', 'nope' ]
22
+ true_values = [ 'affirmative', 'yup' ]
23
+ false_values = [ 'negative', 'nope' ]
24
24
 
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
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
- def test_parse_custom_true_false_regexes
33
+ def test_parse_custom_true_false_regexes
34
34
 
35
- true_values = [ /affirm/, /yup/ ]
36
- false_values = [ 'negative', /no/ ]
35
+ true_values = [ /affirm/, /yup/ ]
36
+ false_values = [ 'negative', /no/ ]
37
37
 
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
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
- class SomeExceptionWithCause < ::Exception
11
+ class SomeExceptionWithCause < ::Exception
12
12
 
13
- include ::Xqsr3::Diagnostics::Exceptions::WithCause
14
- end
13
+ include ::Xqsr3::Diagnostics::Exceptions::WithCause
14
+ end
15
15
 
16
- def test_no_ctor_args
16
+ def test_no_ctor_args
17
17
 
18
- x = SomeExceptionWithCause.new
18
+ x = SomeExceptionWithCause.new
19
19
 
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
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
- def test_1_ctor_arg_that_is_a_message
29
+ def test_1_ctor_arg_that_is_a_message
30
30
 
31
- msg = 'stuff'
31
+ msg = 'stuff'
32
32
 
33
- x = SomeExceptionWithCause.new msg
33
+ x = SomeExceptionWithCause.new msg
34
34
 
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
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
- def test_1_ctor_arg_that_is_a_cause_and_has_no_message
44
+ def test_1_ctor_arg_that_is_a_cause_and_has_no_message
45
45
 
46
- c = RuntimeError.new
46
+ c = RuntimeError.new
47
47
 
48
- x = SomeExceptionWithCause.new c
48
+ x = SomeExceptionWithCause.new c
49
49
 
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
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
- def test_1_ctor_arg_that_is_a_cause_and_has_a_message
60
+ def test_1_ctor_arg_that_is_a_cause_and_has_a_message
61
61
 
62
- c = RuntimeError.new 'blah'
62
+ c = RuntimeError.new 'blah'
63
63
 
64
- x = SomeExceptionWithCause.new c
64
+ x = SomeExceptionWithCause.new c
65
65
 
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
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
- def test_2_ctor_args_that_are_message_and_cause
76
+ def test_2_ctor_args_that_are_message_and_cause
77
77
 
78
- msg = 'stuff'
78
+ msg = 'stuff'
79
79
 
80
- c = RuntimeError.new
80
+ c = RuntimeError.new
81
81
 
82
- x = SomeExceptionWithCause.new msg, c
82
+ x = SomeExceptionWithCause.new msg, c
83
83
 
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
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
- def test_2_ctor_args_that_are_message_and_cause_that_has_a_message
94
+ def test_2_ctor_args_that_are_message_and_cause_that_has_a_message
95
95
 
96
- msg = 'stuff'
96
+ msg = 'stuff'
97
97
 
98
- c = RuntimeError.new 'blah'
98
+ c = RuntimeError.new 'blah'
99
99
 
100
- x = SomeExceptionWithCause.new msg, c
100
+ x = SomeExceptionWithCause.new msg, c
101
101
 
102
- assert_not_nil x.cause
103
- assert_equal msg, x.message
104
- assert_equal 'stuff: blah', x.chained_message
102
+ assert_not_nil x.cause
103
+ assert_equal msg, x.message
104
+ assert_equal 'stuff: blah', x.chained_message
105
105
 
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
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
- def test_cause_in_options
113
+ def test_cause_in_options
114
114
 
115
- c = RuntimeError.new 'inner'
115
+ c = RuntimeError.new 'inner'
116
116
 
117
- x = SomeExceptionWithCause.new 'outer', cause: c
117
+ x = SomeExceptionWithCause.new 'outer', cause: c
118
118
 
119
- assert_not_nil x.cause
120
- assert_equal 'outer', x.message
121
- assert_equal 'outer: inner', x.chained_message
119
+ assert_not_nil x.cause
120
+ assert_equal 'outer', x.message
121
+ assert_equal 'outer: inner', x.chained_message
122
122
 
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
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
- class GrandchildException < Exception
132
+ class GrandchildException < Exception
133
133
 
134
- include ::Xqsr3::Diagnostics::Exceptions::WithCause
135
- end
134
+ include ::Xqsr3::Diagnostics::Exceptions::WithCause
135
+ end
136
136
 
137
- class ChildException < Exception
137
+ class ChildException < Exception
138
138
 
139
- def initialize(*args, **options)
139
+ def initialize(*args, **options)
140
140
 
141
- super *args, **options
142
- end
141
+ super(*args, **options)
142
+ end
143
143
 
144
- include ::Xqsr3::Diagnostics::Exceptions::WithCause
145
- end
144
+ include ::Xqsr3::Diagnostics::Exceptions::WithCause
145
+ end
146
146
 
147
- class ParentException < Exception
147
+ class ParentException < Exception
148
148
 
149
- include ::Xqsr3::Diagnostics::Exceptions::WithCause
149
+ include ::Xqsr3::Diagnostics::Exceptions::WithCause
150
150
 
151
- def initialize(*args, **options)
151
+ def initialize(*args, **options)
152
152
 
153
- super *args, **options
154
- end
155
- end
153
+ super(*args, **options)
154
+ end
155
+ end
156
156
 
157
- class GrandparentException < Exception
157
+ class GrandparentException < Exception
158
158
 
159
- include ::Xqsr3::Diagnostics::Exceptions::WithCause
160
- end
159
+ include ::Xqsr3::Diagnostics::Exceptions::WithCause
160
+ end
161
161
 
162
162
 
163
- def test_four_levels
163
+ def test_four_levels
164
164
 
165
- gc = GrandchildException.new 'gc'
165
+ gc = GrandchildException.new 'gc'
166
166
 
167
- c = ChildException.new 'c', gc
167
+ c = ChildException.new 'c', gc
168
168
 
169
- p = ParentException.new c, 'p'
169
+ p = ParentException.new c, 'p'
170
170
 
171
- gp = GrandparentException.new 'gp', cause: p
171
+ gp = GrandparentException.new 'gp', cause: p
172
172
 
173
- assert_equal 'gp: p: c: gc', gp.chained_message
174
- assert_equal 'gp-p-c-gc', gp.chained_message(separator: '-')
175
- end
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
- class SomeExceptionWithCause < ::Exception
180
+ class SomeExceptionWithCause < ::Exception
181
181
 
182
- include ::Xqsr3::Diagnostics::Exceptions::WithCause
183
- end
182
+ include ::Xqsr3::Diagnostics::Exceptions::WithCause
183
+ end
184
184
 
185
- def f m
185
+ def f m
186
186
 
187
- raise SomeExceptionWithCause, m
188
- end
187
+ raise SomeExceptionWithCause, m
188
+ end
189
189
 
190
- def g m, n
190
+ def g m, n
191
191
 
192
- begin
192
+ begin
193
193
 
194
- f n
195
- rescue Exception => x
194
+ f n
195
+ rescue Exception => x
196
196
 
197
- raise SomeExceptionWithCause.new m, x
198
- end
199
- end
197
+ raise SomeExceptionWithCause.new m, x
198
+ end
199
+ end
200
200
 
201
- def h m, n, o
201
+ def h m, n, o
202
202
 
203
- begin
203
+ begin
204
204
 
205
- g n, 0
206
- rescue Exception => x
205
+ g n, 0
206
+ rescue Exception => x
207
207
 
208
- raise SomeExceptionWithCause.new m, x
209
- end
210
- end
208
+ raise SomeExceptionWithCause.new m, x
209
+ end
210
+ end
211
211
 
212
- def test_one_level
212
+ def test_one_level
213
213
 
214
- begin
214
+ begin
215
215
 
216
- f 'one-level'
216
+ f 'one-level'
217
217
 
218
- assert false, 'should not get here!'
219
- rescue Exception => x
218
+ assert false, 'should not get here!'
219
+ rescue Exception => x
220
220
 
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
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
- x_bt0 = x.backtrace[0]
227
+ x_bt0 = x.backtrace[0]
228
228
 
229
- assert /:in\s+\`f\'\s*$/ =~ x_bt0, 'not receieved from f()'
230
- end
231
- end
229
+ assert (/:in\s+\`f\'\s*$/ =~ x_bt0), 'not receieved from f()'
230
+ end
231
+ end
232
232
 
233
- def test_two_levels
233
+ def test_two_levels
234
234
 
235
- begin
235
+ begin
236
236
 
237
- g 'two-levels', 'one-level'
237
+ g 'two-levels', 'one-level'
238
238
 
239
- assert false, 'should not get here!'
240
- rescue Exception => x
239
+ assert false, 'should not get here!'
240
+ rescue Exception => x
241
241
 
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
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
- x_bt0 = x.backtrace[0]
250
+ x_bt0 = x.backtrace[0]
251
251
 
252
- assert /:in\s+\`rescue in g\'\s*$/ =~ x_bt0, 'not receieved from g()'
252
+ assert (/:in\s+\`rescue in g\'\s*$/ =~ x_bt0), 'not receieved from g()'
253
253
 
254
- c_bt0 = x.cause.backtrace[0]
254
+ c_bt0 = x.cause.backtrace[0]
255
255
 
256
- assert /:in\s+\`f\'\s*$/ =~ c_bt0, 'not receieved from f()'
256
+ assert (/:in\s+\`f\'\s*$/ =~ c_bt0), 'not receieved from f()'
257
257
 
258
- assert_not_empty x.chained_backtrace
259
- end
260
- end
258
+ assert_not_empty x.chained_backtrace
259
+ end
260
+ end
261
261
  end
262
262