xqsr3 0.18.1 → 0.19.3

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: fdaa43c901071d88f6fe3737998e4cd6a741c69b
4
- data.tar.gz: c6876d3f0814a79a4c9a37bcb313c834ebae4096
3
+ metadata.gz: 77b11de6b0e214ce904216d2d6c1818e4d72e3cd
4
+ data.tar.gz: c383a8ddaab643a4d487d0fe44f37e794ae81217
5
5
  SHA512:
6
- metadata.gz: 308f153ed24f39fa50494df2099e8978b5aa55c99b5b016a48ab03e73f9cff058f00d8056364a87695fe16497a0c1b3d70225c9146b4fb1e23bd4fd2cef250ca
7
- data.tar.gz: 7590f907009d95b6057aec1573d7841c39ea2bbd8ff0713fa29356ae3d3836e39121c587285144db6d6f8e05019744caf493c6ead4682d1e648354b2e66c4c46
6
+ metadata.gz: 64e58c0bd8362c0971340a33cf2442f3eb78f0fbe81b76e04df28ea06c2bd738383238528251f0015810c0f6586b850731b4ba62b03ac943574e627299c8cd9d
7
+ data.tar.gz: 7ebf55437cd838b30620d950bf0f02c202c759022ab400ea046006b138ee95816ae3527cebd00bd881948b5be0df48af5f23adceff1df08e7df66b069f105b88
@@ -16,3 +16,4 @@ end # class Assertions
16
16
  end # module Unit
17
17
  end # module Test
18
18
 
19
+
@@ -16,3 +16,4 @@ end # class Assertions
16
16
  end # module Unit
17
17
  end # module Test
18
18
 
19
+
@@ -16,3 +16,4 @@ end # class Assertions
16
16
  end # module Unit
17
17
  end # module Test
18
18
 
19
+
@@ -0,0 +1,21 @@
1
+
2
+ module Test
3
+ module Unit
4
+
5
+ module Assertions
6
+
7
+ unless respond_to? :assert_subclass_of
8
+
9
+ def assert_subclass_of(parent_class, tested_class, failure_message = nil)
10
+
11
+ failure_message ||= "#{tested_class} is not a subclass of #{parent_class}"
12
+
13
+ assert (tested_class < parent_class), failure_message
14
+ end
15
+ end
16
+
17
+ end # class Assertions
18
+ end # module Unit
19
+ end # module Test
20
+
21
+
@@ -0,0 +1,21 @@
1
+
2
+ module Test
3
+ module Unit
4
+
5
+ module Assertions
6
+
7
+ unless respond_to? :assert_superclass_of
8
+
9
+ def assert_superclass_of(child_class, tested_class, failure_message = nil)
10
+
11
+ failure_message ||= "#{tested_class} is not a superclass of #{child_class}"
12
+
13
+ assert (child_class < tested_class), failure_message
14
+ end
15
+ end
16
+
17
+ end # class Assertions
18
+ end # module Unit
19
+ end # module Test
20
+
21
+
@@ -17,4 +17,3 @@ end # module Unit
17
17
  end # module Test
18
18
 
19
19
 
20
-
@@ -3,5 +3,7 @@ require 'xqsr3/extensions/test/unit/assert_eql'
3
3
  require 'xqsr3/extensions/test/unit/assert_false'
4
4
  require 'xqsr3/extensions/test/unit/assert_not'
5
5
  require 'xqsr3/extensions/test/unit/assert_not_eql'
6
+ require 'xqsr3/extensions/test/unit/assert_subclass_of'
7
+ require 'xqsr3/extensions/test/unit/assert_superclass_of'
6
8
  require 'xqsr3/extensions/test/unit/assert_true'
7
9
 
@@ -5,7 +5,7 @@
5
5
  # Purpose: Definition of the ParameterChecking module
6
6
  #
7
7
  # Created: 12th February 2015
8
- # Updated: 16th December 2017
8
+ # Updated: 21st December 2017
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -53,7 +53,8 @@
53
53
  module Xqsr3
54
54
  module Quality
55
55
 
56
- # Parameter-checking utilities
56
+ # Inclusion module that creates class and instance methods +check_parameter+
57
+ # that may be used to check parameter values and types
57
58
  #
58
59
  module ParameterChecking
59
60
 
@@ -64,10 +65,13 @@ module ParameterChecking
64
65
 
65
66
  case a.size
66
67
  when 1
68
+
67
69
  a[0]
68
70
  when 2
71
+
69
72
  "#{a[0]} or #{a[1]}"
70
73
  else
74
+
71
75
  "#{a[0...-1].join(', ')}, or #{a[-1]}"
72
76
  end
73
77
  end
@@ -79,36 +83,40 @@ module ParameterChecking
79
83
  base.extend self
80
84
  end
81
85
 
86
+ private
82
87
  # Check a given parameter (value=+value+, name=+name+) for type and value
83
88
  #
84
89
  # @param +value+ the parameter whose value and type is to be checked
85
- # @param +name+ the name of the parameter to be checked
86
- # @param +options+ options
90
+ # @param +name+ [::String, ::Symbol] the name of the parameter to be
91
+ # checked
92
+ # @param +options+ [::Hash] options that moderate the behaviour
87
93
  #
88
- # @option +:allow_nil+ the +value+ must not be +nil+ unless this option
89
- # is true
90
- # @option +:types+ an array of types one of which +value+ must be (or
91
- # must be derived from). One of these types may be an array
92
- # of types, in which case +value+ may be an array that must
93
- # consist wholly of those types
94
- # @option +:type+ a single type parameter, used only if +:types+ is not
95
- # specified
96
- # @option +:values+ an array of values one of which +value+ must be
97
- # @option +:responds_to+ an array of symbols specifying all messages to
98
- # which the parameter will respond
99
- # @option +:reject_empty+ requires value to respond to +empty?+
94
+ # @option +:allow_nil+ [boolean] The +value+ must not be +nil+ unless
95
+ # this option is true
96
+ # @option +:nil+ an alias for +:allow_nil+
97
+ # @option +:types+ [::Array] An array of types one of which +value+ must
98
+ # be (or must be derived from). One of these types may be an
99
+ # array of types, in which case +value+ may be an array that
100
+ # must consist wholly of those types
101
+ # @option +:type+ [::Class] A single type parameter, used only if
102
+ # +:types+ is not specified
103
+ # @option +:values+ [::Array] an array of values one of which +value+
104
+ # must be
105
+ # @option +:responds_to+ [::Array] An array of symbols specifying all
106
+ # messages to which the parameter will respond
107
+ # @option +:reject_empty+ [boolean] requires value to respond to +empty?+
100
108
  # message and to do so with false, unless +nil+
101
- # @option +:require_empty+ requires value to respond to +empty?+
102
- # message and to do so with true, unless +nil+
103
- # @option +:nothrow+ causes failure to be indicated by a +nil+ return
104
- # rather than a thrown exception
105
- # @option +:message+ specifies a message to be used in any thrown
106
- # exception, which suppresses internal message preparation
107
- # @option +:treat_as_option+ if true, the value will be treated as an
108
- # option when reporting check failure
109
+ # @option +:require_empty+ [boolean] requires value to respond to
110
+ # +empty?+ message and to do so with true, unless +nil+
111
+ # @option +:nothrow+ [boolean] causes failure to be indicated by a +nil+
112
+ # return rather than a thrown exception
113
+ # @option +:message+ [::String] specifies a message to be used in any
114
+ # thrown exception, which suppresses internal message
115
+ # preparation
116
+ # @option +:treat_as_option+ [boolean] If true, the value will be
117
+ # treated as an option when reporting check failure
109
118
  #
110
119
  # This method is private, because it should only be used within methods
111
- private
112
120
  def check_parameter value, name, options = {}, &block
113
121
 
114
122
  Util_.check_parameter value, name, options, &block
@@ -118,40 +126,61 @@ module ParameterChecking
118
126
  #
119
127
  # @note This is obsolete, and will be removed in a future version.
120
128
  # Please use +check_parameter+ instead
121
- private
122
129
  def check_param value, name, options = {}, &block
123
130
 
124
131
  Util_.check_parameter value, name, options, &block
125
132
  end
126
133
 
134
+ # Specific form of the +check_parameter()+ that is used to check
135
+ # options, taking instead the hash and the key
136
+ #
137
+ # @param +h+ [::Hash] The options hash from which the named element is
138
+ # to be tested. May not be +nil+
139
+ # @param +name+ [::String, ::Symbol] The options key name. May not be
140
+ # +nil+
141
+ # @param +options+ [::Hash] options that moderate the behaviour in the
142
+ # same way as for +check_parameter()+ except that the
143
+ # +:treat_as_option+ option (with the value +true+) is merged in
144
+ # before calling +check_parameter()+
145
+ #
146
+ #
147
+ def check_option h, name, options = {}, &block
148
+
149
+ Util_.check_parameter h[name], name, options.merge({ treat_as_option: true }), &block
150
+ end
151
+
152
+ public
127
153
  # Check a given parameter (value=+value+, name=+name+) for type and value
128
154
  #
129
155
  # @param +value+ the parameter whose value and type is to be checked
130
156
  # @param +name+ the name of the parameter to be checked
131
157
  # @param +options+ options
132
158
  #
133
- # @option +:allow_nil+ the +value+ must not be +nil+ unless this option
134
- # is true
135
- # @option +:types+ an array of types one of which +value+ must be (or
136
- # must be derived from). One of these types may be an array
137
- # of types, in which case +value+ may be an array that must
138
- # consist wholly of those types
139
- # @option +:type+ a single type parameter, used only if +:types+ is not
140
- # specified
141
- # @option +:values+ an array of values one of which +value+ must be
142
- # @option +:responds_to+ an array of symbols specifying all messages to
143
- # which the parameter will respond
144
- # @option +:reject_empty+ requires value to respond to +empty?+
159
+ # @option +:allow_nil+ [boolean] The +value+ must not be +nil+ unless
160
+ # this option is true
161
+ # @option +:nil+ an alias for +:allow_nil+
162
+ # @option +:types+ [::Array] An array of types one of which +value+ must
163
+ # be (or must be derived from). One of these types may be an
164
+ # array of types, in which case +value+ may be an array that
165
+ # must consist wholly of those types
166
+ # @option +:type+ [::Class] A single type parameter, used only if
167
+ # +:types+ is not specified
168
+ # @option +:values+ [::Array] an array of values one of which +value+
169
+ # must be
170
+ # @option +:responds_to+ [::Array] An array of symbols specifying all
171
+ # messages to which the parameter will respond
172
+ # @option +:reject_empty+ [boolean] requires value to respond to +empty?+
145
173
  # message and to do so with false, unless +nil+
146
- # @option +:require_empty+ requires value to respond to +empty?+
147
- # message and to do so with true, unless +nil+
148
- # @option +:nothrow+ causes failure to be indicated by a +nil+ return
149
- # rather than a thrown exception
150
- # @option +:message+ specifies a message to be used in any thrown
151
- # exception, which suppresses internal message preparation
152
- # @option +:treat_as_option+ if true, the value will be treated as an
153
- # option when reporting check failure
154
- public
174
+ # @option +:require_empty+ [boolean] requires value to respond to
175
+ # +empty?+ message and to do so with true, unless +nil+
176
+ # @option +:nothrow+ [boolean] causes failure to be indicated by a +nil+
177
+ # return rather than a thrown exception
178
+ # @option +:message+ [boolean] specifies a message to be used in any
179
+ # thrown exception, which suppresses internal message
180
+ # preparation
181
+ # @option +:treat_as_option+ [boolean] If true, the value will be
182
+ # treated as an option when reporting check failure
183
+ #
155
184
  def self.check_parameter value, name, options = {}, &block
156
185
 
157
186
  Util_.check_parameter value, name, options, &block
@@ -161,7 +190,6 @@ module ParameterChecking
161
190
  #
162
191
  # @note This is obsolete, and will be removed in a future version.
163
192
  # Please use +check_parameter+ instead
164
- public
165
193
  def self.check_param value, name, options = {}, &block
166
194
 
167
195
  Util_.check_parameter value, name, options, &block
@@ -179,8 +207,17 @@ module ParameterChecking
179
207
 
180
208
  warn "#{self}::check_parameter: invoked with non-string/non-symbol name: name.class=#{name.class}" unless name && [ ::String, ::Symbol ].any? { |c| name.is_a?(c) }
181
209
 
182
- name = name.to_s if name.is_a?(::Symbol)
183
- name = (':' + name.to_s) if treat_as_option and name.is_a?(::String)
210
+ if treat_as_option
211
+
212
+ case name
213
+ when ::String
214
+ name = ':' + name if ':' != name[0]
215
+ when ::Symbol
216
+ name = ':' + name.to_s
217
+ else
218
+ end
219
+ end
220
+
184
221
 
185
222
  # nil check
186
223
 
@@ -481,3 +518,4 @@ end # module Xqsr3
481
518
 
482
519
  # ############################## end of file ############################# #
483
520
 
521
+
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: 16th December 2017
8
+ # Updated: 21st December 2017
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.18.1'
53
+ VERSION = '0.19.3'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -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
+
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..']*5), 'lib')
4
+
5
+ require 'xqsr3/extensions/test/unit/assert_subclass_of'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_assert_subclass_of < Test::Unit::TestCase
10
+
11
+ class Grandparent; end
12
+ class Parent < Grandparent; end
13
+ class Child < Parent; end
14
+
15
+ def test_1
16
+
17
+ assert_subclass_of Object, Grandparent
18
+ assert_subclass_of Grandparent, Parent
19
+ assert_subclass_of Parent, Child
20
+ assert_subclass_of Grandparent, Child
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *(['..']*5), 'lib')
4
+
5
+ require 'xqsr3/extensions/test/unit/assert_superclass_of'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_assert_superclass_of < Test::Unit::TestCase
10
+
11
+ class Grandparent; end
12
+ class Parent < Grandparent; end
13
+ class Child < Parent; end
14
+
15
+ def test_1
16
+
17
+ assert_superclass_of Grandparent, Object
18
+ assert_superclass_of Parent, Grandparent
19
+ assert_superclass_of Child, Parent
20
+ assert_superclass_of Child, Grandparent
21
+ end
22
+ end
23
+
24
+
@@ -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
+
@@ -327,5 +327,116 @@ end
327
327
  self.class.check_method_type_class :sym, ::String
328
328
  end
329
329
  end
330
+
331
+
332
+ # test treat_as_option
333
+
334
+ def check_method_tao_1 h, o, options = {}, &block
335
+
336
+ check_parameter h[o], o, options.merge({ treat_as_option: true }), &block
337
+ end
338
+
339
+ def test_tao_1
340
+
341
+ assert_true check_method_tao_1({ thing: true }, :thing)
342
+ assert_false check_method_tao_1({ thing: false }, :thing)
343
+ assert_equal [], check_method_tao_1({ thing: [] }, :thing)
344
+
345
+ begin
346
+ check_method_tao_1({ thing: true }, :thingy)
347
+
348
+ assert(false, 'should not get here')
349
+ rescue ArgumentError => ax
350
+
351
+ assert_equal "option ':thingy' may not be nil", ax.message
352
+ rescue => x
353
+
354
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
355
+ end
356
+
357
+ begin
358
+ check_method_tao_1({ thing: true }, 'thingy')
359
+
360
+ assert(false, 'should not get here')
361
+ rescue ArgumentError => ax
362
+
363
+ assert_equal "option ':thingy' may not be nil", ax.message
364
+ rescue => x
365
+
366
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
367
+ end
368
+
369
+ begin
370
+ check_method_tao_1({ thing: true }, ':thingy')
371
+
372
+ assert(false, 'should not get here')
373
+ rescue ArgumentError => ax
374
+
375
+ assert_equal "option ':thingy' may not be nil", ax.message
376
+ rescue => x
377
+
378
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
379
+ end
380
+ end
381
+
382
+
383
+ # test treat_as_option
384
+
385
+ def check_method_tao_2 h, o, options = {}, &block
386
+
387
+ check_option h, o, options.merge({ }), &block
388
+ end
389
+
390
+ def check_method_tao_class_2 h, o, options = {}, &block
391
+
392
+ check_option h, o, options.merge({ }), &block
393
+ end
394
+
395
+ def test_tao_2
396
+
397
+ assert_true check_method_tao_2({ thing: true }, :thing)
398
+ assert_false check_method_tao_2({ thing: false }, :thing)
399
+ assert_equal [], check_method_tao_2({ thing: [] }, :thing)
400
+
401
+ assert_true check_method_tao_class_2({ thing: true }, :thing)
402
+ assert_false check_method_tao_class_2({ thing: false }, :thing)
403
+ assert_equal [], check_method_tao_class_2({ thing: [] }, :thing)
404
+
405
+ begin
406
+ check_method_tao_2({ thing: true }, :thingy)
407
+
408
+ assert(false, 'should not get here')
409
+ rescue ArgumentError => ax
410
+
411
+ assert_equal "option ':thingy' may not be nil", ax.message
412
+ rescue => x
413
+
414
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
415
+ end
416
+
417
+ begin
418
+ check_method_tao_2({ thing: true }, 'thingy')
419
+
420
+ assert(false, 'should not get here')
421
+ rescue ArgumentError => ax
422
+
423
+ assert_equal "option ':thingy' may not be nil", ax.message
424
+ rescue => x
425
+
426
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
427
+ end
428
+
429
+ begin
430
+ check_method_tao_2({ thing: true }, ':thingy')
431
+
432
+ assert(false, 'should not get here')
433
+ rescue ArgumentError => ax
434
+
435
+ assert_equal "option ':thingy' may not be nil", ax.message
436
+ rescue => x
437
+
438
+ assert(false, "wrong exception type #{x.class}) (with message '#{x.message}'")
439
+ end
440
+ end
330
441
  end
331
442
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xqsr3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.1
4
+ version: 0.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  eXtensions by fine Quantum for Standard Ruby and 3rd-party libraries is a
@@ -52,6 +52,8 @@ files:
52
52
  - lib/xqsr3/extensions/test/unit/assert_false.rb
53
53
  - lib/xqsr3/extensions/test/unit/assert_not.rb
54
54
  - lib/xqsr3/extensions/test/unit/assert_not_eql.rb
55
+ - lib/xqsr3/extensions/test/unit/assert_subclass_of.rb
56
+ - lib/xqsr3/extensions/test/unit/assert_superclass_of.rb
55
57
  - lib/xqsr3/extensions/test/unit/assert_true.rb
56
58
  - lib/xqsr3/extensions/test/unit.rb
57
59
  - lib/xqsr3/hash_utilities/deep_transform.rb
@@ -96,6 +98,10 @@ files:
96
98
  - test/unit/extensions/string/tc_starts_with.rb
97
99
  - test/unit/extensions/string/tc_to_symbol.rb
98
100
  - test/unit/extensions/string/ts_all.rb
101
+ - test/unit/extensions/test/ts_all.rb
102
+ - test/unit/extensions/test/unit/tc_assert_subclass_of.rb
103
+ - test/unit/extensions/test/unit/tc_assert_superclass_of.rb
104
+ - test/unit/extensions/test/unit/ts_all.rb
99
105
  - test/unit/extensions/ts_all.rb
100
106
  - test/unit/hash_utilities/tc_has_match.rb
101
107
  - test/unit/hash_utilities/tc_match.rb