xqsr3 0.27.2 → 0.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 786185c865b23fafc7fc1ebc7d81cf0bf5f39f36
4
- data.tar.gz: a16dcecb9fed63c95545371cae951c4ced42f43f
3
+ metadata.gz: 67a291e75a1f5250c92410e09cb8ce4afc2e706b
4
+ data.tar.gz: 17b2fd750488be59288a0ac67df35253455eadcd
5
5
  SHA512:
6
- metadata.gz: '098d22e4dbee898ba1ab8f44ffa48114890a5c289afcf079ec5da96809e5218d387ff614fb049601d4cfadf8a3976d2066d0fe86f8a772d0ed07d75186a93f03'
7
- data.tar.gz: 565ce70a0c6ecbc82f87d9c57e534fddceaab7a8c33c71ee568385b4edda3406693f4c7a7e82265bef85d1016fd6adf9fc3a3c8af68a7eecea166abe3035a5ea
6
+ metadata.gz: e2210e3dfc465b1c899c5dff468349d5c1df6d24aeecf96fc2c9bcb7186d1dbb1923bee39ee1e940493bb4f16b9b70c4c74e21f23752cb7977267f8beb83c7ca
7
+ data.tar.gz: 83e3b052e816d7eaf90dc5e27c2c8565693fe84108456f8f0417fdc156ef7c2cd3b5953443b20ebd7c66c94cb59e65dc8416baf45e8aa312daa652e91a26e717
@@ -5,13 +5,13 @@
5
5
  # Purpose: FrequencyMap container
6
6
  #
7
7
  # Created: 28th January 2005
8
- # Updated: 30th July 2017
8
+ # Updated: 13th October 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2005-2017, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2005-2018, Matthew Wilson and Synesis Software
15
15
  # All rights reserved.
16
16
  #
17
17
  # Redistribution and use in source and binary forms, with or without
@@ -225,13 +225,9 @@ class FrequencyMap
225
225
  tm = {}
226
226
  @counts.each do |element, frequency|
227
227
 
228
- if not tm.has_key? frequency
228
+ tm[frequency] = [] unless tm.has_key?(frequency)
229
229
 
230
- tm[frequency] = [element]
231
- else
232
-
233
- tm[frequency].push element
234
- end
230
+ tm[frequency].push element
235
231
  end
236
232
 
237
233
  keys = tm.keys.sort.reverse
@@ -5,7 +5,7 @@
5
5
  # Purpose: Definition of the WithCause inclusion module
6
6
  #
7
7
  # Created: 16th December 2017
8
- # Updated: 14th March 2018
8
+ # Updated: 5th September 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -66,6 +66,8 @@ module Exceptions
66
66
  #
67
67
  module WithCause
68
68
 
69
+ INSPECT_HIDDEN_FIELDS = [ 'has_implicit_message', 'uses_cause_message' ]
70
+
69
71
  # Defines an initializer for an exception class that allows a cause (aka
70
72
  # an inner exception) to be specified, either as the first or last
71
73
  # argument or as a +:cause+ option
@@ -0,0 +1,176 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/diagnostics/inspect_builder.rb
4
+ #
5
+ # Purpose: ::Xqsr3::Diagnostics::InspectBuilder module
6
+ #
7
+ # Created: 4th September 2018
8
+ # Updated: 5th September 2018
9
+ #
10
+ # Home: http://github.com/synesissoftware/xqsr3
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2018, Matthew Wilson and Synesis Software
15
+ # All rights reserved.
16
+ #
17
+ # Redistribution and use in source and binary forms, with or without
18
+ # modification, are permitted provided that the following conditions are
19
+ # met:
20
+ #
21
+ # * Redistributions of source code must retain the above copyright
22
+ # notice, this list of conditions and the following disclaimer.
23
+ #
24
+ # * Redistributions in binary form must reproduce the above copyright
25
+ # notice, this list of conditions and the following disclaimer in the
26
+ # documentation and/or other materials provided with the distribution.
27
+ #
28
+ # * Neither the names of the copyright holder nor the names of its
29
+ # contributors may be used to endorse or promote products derived from
30
+ # this software without specific prior written permission.
31
+ #
32
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
33
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
34
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
36
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
+ #
44
+ # ######################################################################## #
45
+
46
+
47
+ require 'xqsr3/string_utilities/truncate'
48
+
49
+ =begin
50
+ =end
51
+
52
+ module Xqsr3
53
+ module Diagnostics
54
+
55
+ module InspectBuilder
56
+
57
+ module InspectBuilder_Utilities
58
+
59
+ NORMALISE_FUNCTION = lambda { |ar| ar.map { |v| v.to_s }.map { |v| '@' == v[0] ? v : "@#{v}" } }
60
+ end # module InspectBuilder_Utilities
61
+
62
+ #
63
+ # === Signature
64
+ #
65
+ # * *Parameters:*
66
+ # @param +o+:: The target of the +inspect+ message for which a message
67
+ # will be built
68
+ #
69
+ # * *Options:*
70
+ # @option +:no_class+:: (boolean) Elides the class qualification
71
+ # @option +:no_object_id+:: (boolean) Elides the object id
72
+ # @option +:show_fields+:: (boolean) Shows (all) object fields
73
+ # @option +:hidden_fields+:: ([ String ]) Names of fields to be omitted
74
+ # (when +:show_fields+ is specified). Overridden by +:shown_fields+
75
+ # @option +:shown_fields+:: ([ String ]) Names of fields to be shown
76
+ # (when +:show_fields+ is specified). Overrides +:hidden_fields+
77
+ # @option +:truncate_width+:: (Integer) Specifies a maximum width for
78
+ # the values of fields
79
+ # @option +:deep_inspect+:: (boolean) Causes fields' values to be
80
+ # obtained via their own +inspect+ methods
81
+ def self.make_inspect o, **options
82
+
83
+ r = ''
84
+
85
+ unless options[:no_class]
86
+
87
+ r += o.class.to_s
88
+ end
89
+
90
+ unless options[:no_object_id]
91
+
92
+ r += ':' unless r.empty?
93
+ r += "0x#{o.object_id.to_s.rjust(16, '0')}"
94
+ end
95
+
96
+ if options[:show_fields]
97
+
98
+ normalise = InspectBuilder_Utilities::NORMALISE_FUNCTION
99
+
100
+ hide_fields = normalise.call(options[:hidden_fields] || [])
101
+ show_fields = normalise.call(options[:shown_fields] || [])
102
+ trunc_w = options[:truncate_width]
103
+ ivars = normalise.call(o.instance_variables)
104
+
105
+ unless show_fields.empty?
106
+
107
+ ivars = ivars & show_fields
108
+ else
109
+
110
+ o.class.ancestors.each do |ancestor|
111
+
112
+ ihf_constant = :INSPECT_HIDDEN_FIELDS
113
+
114
+ if ancestor.const_defined? ihf_constant
115
+
116
+ ihfs = ancestor.const_get ihf_constant
117
+
118
+ if ::Array === ihfs && ihfs.all? { |c| ::String === c }
119
+
120
+ hide_fields += normalise.call(ihfs)
121
+ else
122
+
123
+ warn "class/module #{ancestor}'s #{ihf_constant} should be an array of strings"
124
+ end
125
+ end
126
+ end
127
+
128
+ ivars = ivars - hide_fields
129
+ end
130
+
131
+ els = ivars.sort.map do |iv_name|
132
+
133
+ iv_value = o.instance_variable_get(iv_name)
134
+ iv_class = iv_value.class
135
+ iv_value = ::Xqsr3::StringUtilities::Truncate.string_truncate(iv_value.to_s, trunc_w) if trunc_w
136
+ if options[:deep_inspect]
137
+
138
+ iv_value = iv_value.inspect
139
+ else
140
+
141
+ case iv_value
142
+ when ::Array
143
+
144
+
145
+ when ::String
146
+
147
+ iv_value = "'#{iv_value}'"
148
+ end
149
+ end
150
+
151
+ "#{iv_name}(#{iv_class})=#{iv_value}"
152
+ end.join('; ')
153
+
154
+ r += ': ' unless r.empty?
155
+ r += els
156
+ end
157
+
158
+ r = '#<' + r + '>'
159
+
160
+ r
161
+ end
162
+
163
+ # Creates an inspect string from self
164
+ def make_inspect **options
165
+
166
+ ::Xqsr3::Diagnostics::InspectBuilder.make_inspect self, **options
167
+ end
168
+
169
+ end # module InspectBuilder
170
+
171
+ end # module Diagnostics
172
+ end # module Xqsr3
173
+
174
+ # ############################## end of file ############################# #
175
+
176
+
@@ -5,7 +5,7 @@
5
5
  # Purpose: Definition of the ParameterChecking module
6
6
  #
7
7
  # Created: 12th February 2015
8
- # Updated: 29th July 2018
8
+ # Updated: 20th September 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -81,17 +81,18 @@ module ParameterChecking
81
81
  RECOGNISED_OPTION_NAMES = %w{
82
82
 
83
83
  allow_nil
84
+ ignore_case
85
+ message
84
86
  nil
85
- types
86
- type
87
- values
88
- responds_to
87
+ nothrow
89
88
  reject_empty
90
89
  require_empty
91
- nothrow
92
- message
90
+ responds_to
93
91
  strip_str_whitespace
94
92
  treat_as_option
93
+ type
94
+ types
95
+ values
95
96
  }.map { |v| v.to_sym }
96
97
 
97
98
  end # module Constants
@@ -114,6 +115,9 @@ module ParameterChecking
114
115
  # @option +:allow_nil+:: (boolean) The +value+ must not be +nil+ unless
115
116
  # this option is true
116
117
  # @option +:nil+:: an alias for +:allow_nil+
118
+ # @option +:ignore_case+:: (boolean) When +:values+ is specified,
119
+ # comparisons of strings, or arrays of strings, will be carried out in
120
+ # a case-insensitive manner
117
121
  # @option +:types+:: (::Array) An array of types one of which +value+
118
122
  # must be (or must be derived from). One of these types may be
119
123
  # an array of types, in which case +value+ may be an array that
@@ -182,6 +186,9 @@ module ParameterChecking
182
186
  # @option +:allow_nil+:: (boolean) The +value+ must not be +nil+ unless
183
187
  # this option is true
184
188
  # @option +:nil+:: an alias for +:allow_nil+
189
+ # @option +:ignore_case+:: (boolean) When +:values+ is specified,
190
+ # comparisons of strings, or arrays of strings, will be carried out in
191
+ # a case-insensitive manner
185
192
  # @option +:types+:: (::Array) An array of types one of which +value+ must
186
193
  # be (or must be derived from). One of these types may be an
187
194
  # array of types, in which case +value+ may be an array that
@@ -339,6 +346,7 @@ module ParameterChecking
339
346
  types << options[:type] if types.empty?
340
347
  end
341
348
  types = [value.class] if types.empty?
349
+ types = types.map { |type| :boolean == type ? [ ::TrueClass, ::FalseClass ] : type }.flatten if types.include?(:boolean)
342
350
 
343
351
  warn "#{self}::check_parameter: options[:types] of type #{types.class} - should be #{::Array}" unless types.is_a?(Array)
344
352
  warn "#{self}::check_parameter: options[:types] - '#{types}' - should contain only classes or arrays of classes" if types.is_a?(::Array) && !types.all? { |c| ::Class === c || (::Array === c && c.all? { |c2| ::Class === c2 }) }
@@ -449,6 +457,7 @@ module ParameterChecking
449
457
  unless options[:nothrow]
450
458
 
451
459
  unless message
460
+
452
461
  s_name = name.is_a?(String) ? "'#{name}' " : ''
453
462
 
454
463
  message = "#{param_s} #{s_name}must be empty"
@@ -462,14 +471,32 @@ module ParameterChecking
462
471
 
463
472
  # check value(s)
464
473
 
465
- unless value.nil?
466
-
467
- values = options[:values] || [ value ]
474
+ unless value.nil? || !(values = options[:values])
468
475
 
469
476
  warn "#{self}::check_parameter: options[:values] of type #{values.class} - should be #{::Array}" unless values.is_a?(Array)
470
477
 
471
478
  found = false
472
479
 
480
+ io = options[:ignore_order] && ::Array === value
481
+
482
+ do_case = options[:ignore_case] ? lambda do |v|
483
+
484
+ case v
485
+ when ::String
486
+
487
+ return :string
488
+ when ::Array
489
+
490
+ return :array_of_strings if v.all? { |s| ::String === s }
491
+ end
492
+
493
+ nil
494
+ end : lambda { |v| nil }
495
+
496
+ value_ic = do_case.call(value)
497
+ value_io = nil
498
+ value_uc = nil
499
+
473
500
  values.each do |v|
474
501
 
475
502
  if ::Range === v && !(::Range === value) && v.cover?(value)
@@ -483,6 +510,66 @@ module ParameterChecking
483
510
  found = true
484
511
  break
485
512
  end
513
+
514
+ # ignore-case comparing
515
+
516
+ if value_ic
517
+
518
+ unless value_uc
519
+
520
+ case value_ic
521
+ when :string
522
+
523
+ value_uc = value.upcase
524
+ when :array_of_strings
525
+
526
+ value_uc = value.map { |s| s.upcase }
527
+ value_uc = value_uc.sort if io
528
+ end
529
+ end
530
+
531
+ v_ic = do_case.call(v)
532
+
533
+ if v_ic == value_ic
534
+
535
+ case v_ic
536
+ when :string
537
+
538
+ if value_uc == v.upcase
539
+
540
+ found = true
541
+ break
542
+ end
543
+ when :array_of_strings
544
+
545
+ v_uc = v.map { |s| s.upcase }
546
+ v_uc = v_uc.sort if io
547
+
548
+ if value_uc == v_uc
549
+
550
+ found = true
551
+ break
552
+ end
553
+ end
554
+ end
555
+ elsif io
556
+
557
+ unless value_io
558
+
559
+ value_io = value.sort
560
+ end
561
+
562
+ if ::Array === v
563
+
564
+ v_io = v.sort
565
+
566
+ if value_io == v_io
567
+
568
+ found = true
569
+ break
570
+ end
571
+ end
572
+ end
486
573
  end
487
574
 
488
575
  unless found
@@ -492,6 +579,7 @@ module ParameterChecking
492
579
  unless options[:nothrow]
493
580
 
494
581
  unless message
582
+
495
583
  s_name = name.is_a?(String) ? "'#{name}' " : ''
496
584
 
497
585
  message = "#{param_s} #{s_name}value '#{value}' not found equal/within any of required values or ranges"
data/lib/xqsr3/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for Xqsr3 library
6
6
  #
7
7
  # Created: 3rd April 2016
8
- # Updated: 24th August 2018
8
+ # Updated: 13th October 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -50,7 +50,7 @@
50
50
  module Xqsr3
51
51
 
52
52
  # Current version of the Xqsr3 library
53
- VERSION = '0.27.2'
53
+ VERSION = '0.29.2'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
4
+
5
+ require 'xqsr3/diagnostics/inspect_builder'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+ class Test_X_Object_inspect < Test::Unit::TestCase
11
+
12
+ class Example1
13
+
14
+ include ::Xqsr3::Diagnostics::InspectBuilder
15
+
16
+ def initialize **inspect_options
17
+
18
+ @alphabet = 'abcdefghijklmnopqrstuvwxyz'
19
+ @letters = @alphabet.chars.map { |c| c.upcase }
20
+ @inspect_options = inspect_options
21
+ end
22
+
23
+ def inspect
24
+
25
+ make_inspect **@inspect_options
26
+ end
27
+ end
28
+
29
+ class ExampleWithHiddenFields < Example1
30
+
31
+ INSPECT_HIDDEN_FIELDS = [ 'letters' ]
32
+ end
33
+
34
+ def test_default_use
35
+
36
+ ex = Example1.new
37
+
38
+ assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+>\z/, ex.inspect
39
+
40
+ ex2 = ExampleWithHiddenFields.new
41
+
42
+ assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+>\z/, ex2.inspect
43
+ end
44
+
45
+ def test_no_class
46
+
47
+ ex = Example1.new(no_class: true)
48
+
49
+ assert_match /\A#<0x\d+>\z/, ex.inspect
50
+
51
+ ex2 = ExampleWithHiddenFields.new(no_class: true)
52
+
53
+ assert_match /\A#<0x\d+>\z/, ex2.inspect
54
+ end
55
+
56
+ def test_no_object_id
57
+
58
+ ex = Example1.new(no_object_id: true)
59
+
60
+ assert_match /\A#<Test_X_Object_inspect::Example1>\z/, ex.inspect
61
+
62
+ ex2 = ExampleWithHiddenFields.new(no_object_id: true)
63
+
64
+ assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields>\z/, ex2.inspect
65
+ end
66
+
67
+ def test_show_fields
68
+
69
+ ex = Example1.new(show_fields: true)
70
+
71
+ assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz';\s*@inspect_options.*;\s*@letters.*>\z/, ex.inspect
72
+
73
+ ex2 = ExampleWithHiddenFields.new(show_fields: true)
74
+
75
+ assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz';\s*@inspect_options\(.+\)=[^;]+>\z/, ex2.inspect
76
+ end
77
+
78
+ def test_show_fields_hidden
79
+
80
+ ex = Example1.new(show_fields: true, hidden_fields: [ 'inspect_options' ])
81
+
82
+ assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz';\s*@letters.*>\z/, ex.inspect
83
+
84
+ ex2 = ExampleWithHiddenFields.new(show_fields: true, hidden_fields: [ 'inspect_options' ])
85
+
86
+ assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+:\s*@alphabet\(String\)='abcdefghijklmnopqrstuvwxyz'>\z/, ex2.inspect
87
+ end
88
+
89
+ def test_show_fields_truncated
90
+
91
+ ex = Example1.new(show_fields: true, truncate_width: 10)
92
+
93
+ assert_match /\A#<Test_X_Object_inspect::Example1:0x\d+:\s*@alphabet\(String\)='abcdefg...';\s*@inspect_options.*;\s*@letters.*>\z/, ex.inspect
94
+
95
+ ex2 = ExampleWithHiddenFields.new(show_fields: true, truncate_width: 10)
96
+
97
+ assert_match /\A#<Test_X_Object_inspect::ExampleWithHiddenFields:0x\d+:\s*@alphabet\(String\)='abcdefg...';\s*@inspect_options.*>\z/, ex2.inspect
98
+ end
99
+ end
100
+
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
@@ -103,6 +103,7 @@ class Test_parameter_checks_as_included_module < Test::Unit::TestCase
103
103
  def test_2
104
104
 
105
105
  assert_equal true, check_method_2(true, [ ::TrueClass ])
106
+ assert_equal true, check_method_2(true, [ :boolean ])
106
107
  assert_equal true, check_method_2(true, [ ::TrueClass, ::String, ::Symbol ])
107
108
  assert_raise TypeError do
108
109
  check_method_2(true, [ ::String, ::Symbol, ::FalseClass ])
@@ -568,5 +569,41 @@ end
568
569
 
569
570
  assert_nil(check_parameter(nil, 'the_param', nil: true))
570
571
  end
572
+
573
+
574
+ # test_ignore_case
575
+
576
+ def test_ignore_case
577
+
578
+ assert_not_nil check_parameter('TheString', 'the_param', values: [ 'TheString', 'the-string' ])
579
+
580
+ assert_raise_with_message(::ArgumentError, /parameter.*the_param.*not found.*values/) { check_parameter('THESTRING', 'the_param', values: [ 'TheString', 'the-string' ]) }
581
+
582
+ assert_not_nil check_parameter('TheString', 'the_param', values: [ 'THESTRING', 'the-string' ], ignore_case: true)
583
+ end
584
+
585
+ def test_ignore_case_in_array
586
+
587
+ assert_not_nil check_parameter([ 'abc', 'def' ], 'the_param', values: [ [ 'ABC', 'DEF' ], [ 'abc', 'def' ] ])
588
+
589
+ assert_raise_with_message(::ArgumentError, /parameter.*the_param.*not found.*values/) { check_parameter([ 'Abc', 'Def' ], 'the_param', values: [ [ 'ABC', 'DEF' ], [ 'abc', 'def' ] ]) }
590
+
591
+ assert_not_nil check_parameter([ 'Abc', 'Def' ], 'the_param', values: [ [ 'ABC', 'DEF' ], [ 'abc', 'def' ] ], ignore_case: true)
592
+
593
+ assert_raise_with_message(::ArgumentError, /parameter.*the_param.*not found.*values/) { check_parameter([ 'Def', 'Abc' ], 'the_param', values: [ [ 'ABC', 'DEF' ], [ 'abc', 'def' ] ], ignore_case: true) }
594
+
595
+ end
596
+
597
+ def test_ignore_case_and_order_in_array
598
+
599
+ assert_not_nil check_parameter([ 'Def', 'Abc', 'Ghi' ], 'the_param', values: [ [ 'GHI', 'ABC', 'DEF' ], [ 'ghi', 'abc', 'def' ] ], ignore_case: true, ignore_order: true)
600
+ end
601
+
602
+ def test_ignore_order_in_array
603
+
604
+ assert_raise(::ArgumentError) { check_parameter([ 'abc', 'def', 'ghi' ], 'the_param', values: [ [ 'ghi', 'def', 'abc' ], [ 'ghi', 'abc', 'def' ] ]) }
605
+
606
+ assert_not_nil check_parameter([ 'abc', 'def', 'ghi' ], 'the_param', values: [ [ 'ghi', 'def', 'abc' ], [ 'ghi', 'abc', 'def' ] ], ignore_order: true)
607
+ end
571
608
  end
572
609
 
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
4
+
5
+ require 'xqsr3/string_utilities/truncate'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+ class Test_StringUtilities_Truncate < ::Test::Unit::TestCase
11
+
12
+ Truncator = ::Xqsr3::StringUtilities::Truncate
13
+
14
+ def test_truncate_of_empty_string
15
+
16
+ assert_equal '', Truncator.string_truncate('', 0)
17
+ assert_equal '', Truncator.string_truncate('', 1)
18
+ assert_equal '', Truncator.string_truncate('', 10)
19
+ end
20
+
21
+ def test_truncate_of_smallest_string
22
+
23
+ assert_equal '', Truncator.string_truncate('a', 0)
24
+ assert_equal 'a', Truncator.string_truncate('a', 1)
25
+ assert_equal 'a', Truncator.string_truncate('a', 10)
26
+ end
27
+
28
+ def test_truncate_of_smaller_string
29
+
30
+ assert_equal '', Truncator.string_truncate('abc', 0)
31
+ assert_equal '.', Truncator.string_truncate('abc', 1)
32
+ assert_equal '..', Truncator.string_truncate('abc', 2)
33
+ assert_equal 'abc', Truncator.string_truncate('abc', 3)
34
+ assert_equal 'abc', Truncator.string_truncate('abc', 4)
35
+ assert_equal 'abc', Truncator.string_truncate('abc', 10)
36
+ end
37
+
38
+ def test_truncate_of_small_string
39
+
40
+ assert_equal '', Truncator.string_truncate('abcdefghijklmnopqrstuvwxyz', 0)
41
+ assert_equal '.', Truncator.string_truncate('abcdefghijklmnopqrstuvwxyz', 1)
42
+ assert_equal '..', Truncator.string_truncate('abcdefghijklmnopqrstuvwxyz', 2)
43
+ assert_equal '...', Truncator.string_truncate('abcdefghijklmnopqrstuvwxyz', 3)
44
+ assert_equal 'a...', Truncator.string_truncate('abcdefghijklmnopqrstuvwxyz', 4)
45
+ assert_equal 'abcdefg...', Truncator.string_truncate('abcdefghijklmnopqrstuvwxyz', 10)
46
+ end
47
+
48
+
49
+ end
50
+
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xqsr3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.2
4
+ version: 0.29.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
@@ -29,6 +29,7 @@ files:
29
29
  - lib/xqsr3/conversion/integer_parser.rb
30
30
  - lib/xqsr3/diagnostics/exception_utilities.rb
31
31
  - lib/xqsr3/diagnostics/exceptions/with_cause.rb
32
+ - lib/xqsr3/diagnostics/inspect_builder.rb
32
33
  - lib/xqsr3/doc_.rb
33
34
  - lib/xqsr3/extensions/array/join_with_or.rb
34
35
  - lib/xqsr3/extensions/enumerable.rb
@@ -104,6 +105,8 @@ files:
104
105
  - test/unit/extensions/kernel/tc_integer.rb
105
106
  - test/unit/extensions/kernel/tc_raise_with_options.rb
106
107
  - test/unit/extensions/kernel/ts_all.rb
108
+ - test/unit/extensions/object/tc_inspect.rb
109
+ - test/unit/extensions/object/ts_all.rb
107
110
  - test/unit/extensions/string/tc_bool.tb
108
111
  - test/unit/extensions/string/tc_ends_with.rb
109
112
  - test/unit/extensions/string/tc_map_option_string.rb
@@ -127,6 +130,8 @@ files:
127
130
  - test/unit/io/ts_all.rb
128
131
  - test/unit/quality/tc_parameter_checking.rb
129
132
  - test/unit/quality/ts_all.rb
133
+ - test/unit/string_utilities/tc_truncate.rb
134
+ - test/unit/string_utilities/ts_all.rb
130
135
  - test/unit/tc_version.rb
131
136
  - test/unit/ts_all.rb
132
137
  - test/unit/xml/ts_all.rb