xqsr3 0.32.2 → 0.36.0

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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/lib/xqsr3/all_extensions.rb +6 -0
  3. data/lib/xqsr3/array_utilities.rb +10 -0
  4. data/lib/xqsr3/array_utilities/join_with_or.rb +7 -14
  5. data/lib/xqsr3/command_line_utilities.rb +10 -0
  6. data/lib/xqsr3/command_line_utilities/map_option_string.rb +21 -8
  7. data/lib/xqsr3/containers.rb +11 -0
  8. data/lib/xqsr3/containers/frequency_map.rb +19 -2
  9. data/lib/xqsr3/containers/multi_map.rb +316 -27
  10. data/lib/xqsr3/conversion.rb +11 -0
  11. data/lib/xqsr3/conversion/bool_parser.rb +11 -14
  12. data/lib/xqsr3/conversion/integer_parser.rb +10 -16
  13. data/lib/xqsr3/diagnostics.rb +11 -0
  14. data/lib/xqsr3/diagnostics/exception_utilities.rb +2 -2
  15. data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +15 -7
  16. data/lib/xqsr3/diagnostics/inspect_builder.rb +16 -16
  17. data/lib/xqsr3/doc_.rb +138 -9
  18. data/lib/xqsr3/extensions.rb +13 -0
  19. data/lib/xqsr3/extensions/array.rb +3 -0
  20. data/lib/xqsr3/extensions/array/join_with_or.rb +6 -0
  21. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +5 -4
  22. data/lib/xqsr3/extensions/enumerable/detect_map.rb +6 -7
  23. data/lib/xqsr3/extensions/hash.rb +5 -0
  24. data/lib/xqsr3/extensions/hash/has_match.rb +7 -0
  25. data/lib/xqsr3/extensions/hash/match.rb +7 -0
  26. data/lib/xqsr3/extensions/hash/slice.rb +22 -0
  27. data/lib/xqsr3/extensions/io/writelines.rb +38 -6
  28. data/lib/xqsr3/extensions/kernel/integer.rb +6 -13
  29. data/lib/xqsr3/extensions/string/to_bool.rb +4 -0
  30. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +1 -0
  31. data/lib/xqsr3/extensions/test/unit/assert_false.rb +1 -0
  32. data/lib/xqsr3/extensions/test/unit/assert_not.rb +1 -0
  33. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +1 -0
  34. data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +25 -4
  35. data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +1 -0
  36. data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +1 -0
  37. data/lib/xqsr3/extensions/test/unit/assert_true.rb +1 -0
  38. data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +3 -12
  39. data/lib/xqsr3/hash_utilities.rb +11 -0
  40. data/lib/xqsr3/hash_utilities/deep_transform.rb +2 -2
  41. data/lib/xqsr3/hash_utilities/key_matching.rb +6 -4
  42. data/lib/xqsr3/internal_/test_unit_version_.rb +30 -4
  43. data/lib/xqsr3/io/writelines.rb +55 -19
  44. data/lib/xqsr3/quality.rb +8 -1
  45. data/lib/xqsr3/quality/parameter_checking.rb +52 -78
  46. data/lib/xqsr3/string_utilities.rb +16 -0
  47. data/lib/xqsr3/string_utilities/ends_with.rb +16 -7
  48. data/lib/xqsr3/string_utilities/nil_if_empty.rb +8 -4
  49. data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +9 -4
  50. data/lib/xqsr3/string_utilities/quote_if.rb +12 -14
  51. data/lib/xqsr3/string_utilities/starts_with.rb +23 -5
  52. data/lib/xqsr3/string_utilities/to_symbol.rb +24 -5
  53. data/lib/xqsr3/string_utilities/truncate.rb +20 -4
  54. data/lib/xqsr3/version.rb +3 -2
  55. data/test/unit/containers/tc_multi_map.rb +174 -16
  56. data/test/unit/extensions/hash/tc_hash.rb +6 -0
  57. data/test/unit/extensions/hash/tc_slice.rb +31 -0
  58. data/test/unit/extensions/io/tc_writelines.rb +36 -0
  59. metadata +16 -3
@@ -0,0 +1,16 @@
1
+
2
+ %w{
3
+
4
+ ends_with
5
+ nil_if_empty
6
+ nil_if_whitespace
7
+ quote_if
8
+ starts_with
9
+ to_symbol
10
+ truncate
11
+ }.each do |name|
12
+
13
+ require File.join(File.dirname(__FILE__), 'string_utilities', name)
14
+ end
15
+
16
+
@@ -6,7 +6,7 @@
6
6
  # module
7
7
  #
8
8
  # Created: 13th April 2016
9
- # Updated: 12th April 2019
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
@@ -54,12 +54,15 @@
54
54
  module Xqsr3
55
55
  module StringUtilities
56
56
 
57
+ # +include+-able module that provides ::string_ends_with? and #ends_with?
58
+ # methods
57
59
  module EndsWith
58
60
 
59
61
  private
60
- module EndsWith_Helper_ #:nodoc:
62
+ # @!visibility private
63
+ module EndsWith_Helper_ # :nodoc: all
61
64
 
62
- def self.string_ends_with_helper_ s, prefix
65
+ def self.string_ends_with_helper_ s, prefix # :nodoc:
63
66
 
64
67
  if prefix.nil? || prefix.empty?
65
68
 
@@ -78,7 +81,7 @@ module EndsWith
78
81
  nil
79
82
  end
80
83
 
81
- def self.string_ends_with_array_ s, args
84
+ def self.string_ends_with_array_ s, args # :nodoc:
82
85
 
83
86
  return '' if args.empty?
84
87
 
@@ -115,14 +118,20 @@ module EndsWith
115
118
  # === Signature
116
119
  #
117
120
  # * *Parameters:*
118
- #
119
- # * *Required parameters*:
120
- # - +s+:: [String] The string to be evaluated
121
+ # - +s+ (String) The string to be evaluated
122
+ # - +args+ 0+ arguments against which +s+ will be evaluated
121
123
  def self.string_ends_with? s, *args
122
124
 
123
125
  EndsWith_Helper_.string_ends_with_array_ s, args
124
126
  end
125
127
 
128
+ # Reports on whether the instance ends with a given prefix or set of
129
+ # prefixes (+args+)
130
+ #
131
+ # === Signature
132
+ #
133
+ # * *Parameters:*
134
+ # - +args+ 0+ arguments against which the instance will be evaluated
126
135
  def ends_with? *args
127
136
 
128
137
  EndsWith_Helper_.string_ends_with_array_ self, args
@@ -6,7 +6,7 @@
6
6
  # module
7
7
  #
8
8
  # Created: 25th January 2018
9
- # Updated: 12th April 2019
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
@@ -54,12 +54,15 @@
54
54
  module Xqsr3
55
55
  module StringUtilities
56
56
 
57
+ # +include+-able module that provides ::string_nil_if_empty and
58
+ # #nil_if_empty methods
57
59
  module NilIfEmpty
58
60
 
59
61
  private
60
- module NilIfEmpty_Helper_ #:nodoc:
62
+ # @!visibility private
63
+ module NilIfEmpty_Helper_ # :nodoc: all
61
64
 
62
- def self.string_nil_if_empty_array_ s
65
+ def self.string_nil_if_empty_array_ s # :nodoc:
63
66
 
64
67
  return s if s && !s.empty?
65
68
 
@@ -76,12 +79,13 @@ module NilIfEmpty
76
79
  # * *Parameters:*
77
80
  #
78
81
  # * *Required parameters*:
79
- # - +s+:: [String] The string to be evaluated
82
+ # - +s+ (String) The string to be evaluated
80
83
  def self.string_nil_if_empty s
81
84
 
82
85
  NilIfEmpty_Helper_.string_nil_if_empty_array_ s
83
86
  end
84
87
 
88
+ # Returns +nil+ if the instance is empty, otherwise returning self
85
89
  def nil_if_empty
86
90
 
87
91
  NilIfEmpty_Helper_.string_nil_if_empty_array_ self
@@ -6,7 +6,7 @@
6
6
  # module
7
7
  #
8
8
  # Created: 25th January 2018
9
- # Updated: 12th April 2019
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
@@ -54,12 +54,15 @@
54
54
  module Xqsr3
55
55
  module StringUtilities
56
56
 
57
+ # +include+-able module that provides ::string_nil_if_whitespace and
58
+ # #nil_if_whitespace methods
57
59
  module NilIfWhitespace
58
60
 
59
61
  private
60
- module NilIfWhitespace_Helper_ #:nodoc:
62
+ # @!visibility private
63
+ module NilIfWhitespace_Helper_ # :nodoc: all
61
64
 
62
- def self.string_nil_if_whitespace_array_ s
65
+ def self.string_nil_if_whitespace_array_ s # :nodoc:
63
66
 
64
67
  return nil if s.strip.empty?
65
68
 
@@ -76,12 +79,14 @@ module NilIfWhitespace
76
79
  # * *Parameters:*
77
80
  #
78
81
  # * *Required parameters*:
79
- # - +s+:: [String] The string to be evaluated
82
+ # - +s+ (String) The string to be evaluated
80
83
  def self.string_nil_if_whitespace s
81
84
 
82
85
  NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ s
83
86
  end
84
87
 
88
+ # Returns +nil+ if the instance is empty or contains only whitespace,
89
+ # otherwise returning self
85
90
  def nil_if_whitespace
86
91
 
87
92
  NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ self
@@ -6,7 +6,7 @@
6
6
  # module
7
7
  #
8
8
  # Created: 3rd June 2017
9
- # Updated: 12th April 2019
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
@@ -54,12 +54,14 @@
54
54
  module Xqsr3
55
55
  module StringUtilities
56
56
 
57
+ # +include+-able module that provides ::quote_if and #quote_if methods
57
58
  module QuoteIf
58
59
 
59
60
  private
60
- module QuoteIf_Helper_ #:nodoc:
61
+ # @!visibility private
62
+ module QuoteIf_Helper_ # :nodoc: all
61
63
 
62
- def self.string_quote_if_array_ s, options
64
+ def self.string_quote_if_array_ s, options # :nodoc:
63
65
 
64
66
  s = s.to_s unless String === s
65
67
 
@@ -95,27 +97,23 @@ module QuoteIf
95
97
  # * *Parameters:*
96
98
  #
97
99
  # * *Required parameters*:
98
- # - +s+:: [String] The string to be evaluated
100
+ # - +s+ (String) The string to be evaluated
99
101
  #
100
102
  # * *Options parameters*:
101
- # - +options+:: [Hash] Options that control the behaviour of the
102
- # method
103
+ # - +options+ (Hash) Options that control the behaviour of the method
103
104
  #
104
105
  # * *Options:*
105
106
  #
106
- # - +:quotes+:: [String, Array] A string that is used as the opening
107
- # and closing quotes, or an array whose first two elements are
108
- # used as the opening and closing quotes. Defaults to '"'
109
- # - +:quotables+:: [String, Array, Regexp] A string representing the
110
- # quotable character, or an array containing the quotable
111
- # characters, or a regular expression that determines by match
112
- # whether the string should be quoted. Defaults to the regular
113
- # expression /\s/
107
+ # - +:quotes+ (String, Array) A string that is used as the opening and closing quotes, or an array whose first two elements are used as the opening and closing quotes. Defaults to +'"'+
108
+ # - +:quotables+ (String, Array, Regexp) A string representing the quotable character, or an array containing the quotable characters, or a regular expression that determines by match whether the string should be quoted. Defaults to the regular expression +/\s/+
114
109
  def self.quote_if s, **options
115
110
 
116
111
  QuoteIf_Helper_.string_quote_if_array_ s, options
117
112
  end
118
113
 
114
+ # Converts the instance to a quoted form if necessary
115
+ #
116
+ # See Xqsr3::StringUtilities::QuoteIf::quite_if() for options
119
117
  def quote_if **options
120
118
 
121
119
  QuoteIf_Helper_.string_quote_if_array_ self, options
@@ -6,13 +6,13 @@
6
6
  # module
7
7
  #
8
8
  # Created: 13th April 2016
9
- # Updated: 10th June 2016
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
13
13
  # Author: Matthew Wilson
14
14
  #
15
- # Copyright (c) 2016, Matthew Wilson and Synesis Software
15
+ # Copyright (c) 2016-2019, Matthew Wilson and Synesis Software
16
16
  # All rights reserved.
17
17
  #
18
18
  # Redistribution and use in source and binary forms, with or without
@@ -54,12 +54,15 @@
54
54
  module Xqsr3
55
55
  module StringUtilities
56
56
 
57
+ # +include+-able module that provides ::string_starts_with? and #starts_with?
58
+ # methods
57
59
  module StartsWith
58
60
 
59
61
  private
60
- module StartsWith_Helper_ #:nodoc:
62
+ # @!visibility private
63
+ module StartsWith_Helper_ # :nodoc: all
61
64
 
62
- def self.string_starts_with_helper_ s, prefix
65
+ def self.string_starts_with_helper_ s, prefix # :nodoc:
63
66
 
64
67
  if prefix.nil? || prefix.empty?
65
68
 
@@ -78,7 +81,7 @@ module StartsWith
78
81
  nil
79
82
  end
80
83
 
81
- def self.string_starts_with_array_ s, args
84
+ def self.string_starts_with_array_ s, args # :nodoc:
82
85
 
83
86
  return '' if args.empty?
84
87
 
@@ -109,11 +112,26 @@ module StartsWith
109
112
  end
110
113
  public
111
114
 
115
+ # Reports on whether a string +s+ starts with a given prefix or set of
116
+ # prefixes (+args+)
117
+ #
118
+ # === Signature
119
+ #
120
+ # * *Parameters:*
121
+ # - +s+ (String) The string to be evaluated
122
+ # - +args+ 0+ arguments against which +s+ will be evaluated
112
123
  def self.string_starts_with? s, *args
113
124
 
114
125
  StartsWith_Helper_.string_starts_with_array_ s, args
115
126
  end
116
127
 
128
+ # Reports on whether the instance starts with a given prefix or set of
129
+ # prefixes (+args+)
130
+ #
131
+ # === Signature
132
+ #
133
+ # * *Parameters:*
134
+ # - +args+ 0+ arguments against which the instance will be evaluated
117
135
  def starts_with? *args
118
136
 
119
137
  StartsWith_Helper_.string_starts_with_array_ self, args
@@ -6,13 +6,13 @@
6
6
  # module
7
7
  #
8
8
  # Created: 14th April 2016
9
- # Updated: 10th June 2016
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
13
13
  # Author: Matthew Wilson
14
14
  #
15
- # Copyright (c) 2016, Matthew Wilson and Synesis Software
15
+ # Copyright (c) 2016-2019, Matthew Wilson and Synesis Software
16
16
  # All rights reserved.
17
17
  #
18
18
  # Redistribution and use in source and binary forms, with or without
@@ -59,15 +59,16 @@ module StringUtilities
59
59
  module ToSymbol
60
60
 
61
61
  private
62
- module ToSymbol_Helper_ #:nodoc:
62
+ # @!visibility private
63
+ module ToSymbol_Helper_ # :nodoc: all
63
64
 
64
- module Constants #:nodoc:
65
+ module Constants # :nodoc:
65
66
 
66
67
  SymbolCharacters0 = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
67
68
  SymbolCharactersN = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'
68
69
  end
69
70
 
70
- def self.string_to_symbol_with_options_ s, options
71
+ def self.string_to_symbol_with_options_ s, options # :nodoc:
71
72
 
72
73
  case s
73
74
  when ::String
@@ -127,11 +128,29 @@ module ToSymbol
127
128
  end
128
129
  public
129
130
 
131
+ # Converts the given string +s+ to a symbol according to the given
132
+ # +options+
133
+ #
134
+ # === Signature
135
+ #
136
+ # * *Parameters:*
137
+ # - +s+ (String) The string to convert
138
+ # - +options+ (Hash) Options hash
139
+ #
140
+ # * *Options:*
141
+ # - +:reject_hyphens+ (boolean)
142
+ # - +:reject_spaces+ (boolean)
143
+ # - +:reject_tabs+ (boolean)
144
+ # - +:reject_whitespace+ (boolean)
145
+ # - +:transform_characters+ (boolean)
130
146
  def self.string_to_symbol s, options = {}
131
147
 
132
148
  ToSymbol_Helper_.string_to_symbol_with_options_ s, options
133
149
  end
134
150
 
151
+ # Converts the instance to a symbol, according to the given +options+
152
+ #
153
+ # See Xqsr3::StringUtilities::ToSymbol::string_to_symbol for options
135
154
  def to_symbol options = {}
136
155
 
137
156
  ToSymbol_Helper_.string_to_symbol_with_options_ self, options
@@ -6,13 +6,13 @@
6
6
  # module
7
7
  #
8
8
  # Created: 12th April 2018
9
- # Updated: 12th April 2018
9
+ # Updated: 15th April 2019
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
13
13
  # Author: Matthew Wilson
14
14
  #
15
- # Copyright (c) 2018, Matthew Wilson and Synesis Software
15
+ # Copyright (c) 2018-2019, Matthew Wilson and Synesis Software
16
16
  # All rights reserved.
17
17
  #
18
18
  # Redistribution and use in source and binary forms, with or without
@@ -59,9 +59,10 @@ module StringUtilities
59
59
  module Truncate
60
60
 
61
61
  private
62
- module Truncate_Helper_ #:nodoc:
62
+ # @!visibility private
63
+ module Truncate_Helper_ # :nodoc: all
63
64
 
64
- def self.string_truncate_with_options_ s, width, options
65
+ def self.string_truncate_with_options_ s, width, options # :nodoc:
65
66
 
66
67
  case s
67
68
  when ::String
@@ -102,11 +103,26 @@ module Truncate
102
103
  end
103
104
  public
104
105
 
106
+ # Truncates the given string +s+ to the given +width+ according to the
107
+ # given +options+
108
+ #
109
+ # === Signature
110
+ #
111
+ # * *Parameters:*
112
+ # - +s+ (String) The string to convert
113
+ # - +width+ (Integer) The truncation width
114
+ # - +options+ (Hash) Options hash
115
+ #
116
+ # * *Options:*
117
+ # - +:omission+ (String) Omission string. Defaults to "..."
105
118
  def self.string_truncate s, width, options = {}
106
119
 
107
120
  Truncate_Helper_.string_truncate_with_options_ s, width, options
108
121
  end
109
122
 
123
+ # Truncates the instance, according to the given +width+ and +options+
124
+ #
125
+ # See Xqsr3::StringUtilities::ToSymbol::string_truncate for options
110
126
  def truncate width, options = {}
111
127
 
112
128
  Truncate_Helper_.string_truncate_with_options_ self, width, options
@@ -5,12 +5,13 @@
5
5
  # Purpose: Version for Xqsr3 library
6
6
  #
7
7
  # Created: 3rd April 2016
8
- # Updated: 12th April 2019
8
+ # Updated: 26th May 2020
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2016-2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -50,7 +51,7 @@
50
51
  module Xqsr3
51
52
 
52
53
  # Current version of the Xqsr3 library
53
- VERSION = '0.32.2'
54
+ VERSION = '0.36.0'
54
55
 
55
56
  private
56
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -481,7 +481,7 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
481
481
 
482
482
  assert_not mm.has_key? :abc
483
483
 
484
- mm.push :abc
484
+ mm.push :abc, *[ :v1, :v2 ]
485
485
 
486
486
  assert mm.has_key? :abc
487
487
 
@@ -494,15 +494,37 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
494
494
 
495
495
  mm = MultiMap.new
496
496
 
497
- assert_not mm.has_value? []
497
+ assert_not mm.has_value? :abc
498
+
499
+ mm.push :abc, *[ :v1, :v2 ]
500
+
501
+ assert mm.has_value? :v1
502
+ assert mm.has_value? :v2
503
+ assert_not mm.has_value? :v3
504
+
505
+ mm.delete :abc
506
+
507
+ assert_not mm.has_value? :abc
508
+ end
509
+
510
+ def test_has_values?
511
+
512
+ mm = MultiMap.new
513
+
514
+ assert_not mm.has_values? []
498
515
 
499
516
  mm.push :abc
500
517
 
501
- assert mm.has_value? []
518
+ assert mm.has_values? []
519
+
520
+ mm.push :abc, * [ :v1, :v2 ]
521
+
522
+ assert_not mm.has_values? []
523
+ assert mm.has_values? [ :v1, :v2 ]
502
524
 
503
525
  mm.delete :abc
504
526
 
505
- assert_not mm.has_value? []
527
+ assert_not mm.has_values? []
506
528
  end
507
529
 
508
530
  def test_key
@@ -512,13 +534,43 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
512
534
  assert_nil mm.key []
513
535
  assert_nil mm.key :not_defined
514
536
 
515
- mm.push :abc
537
+ mm.push :abc, :v1
516
538
 
517
- assert_equal :abc, mm.key([])
539
+ assert_equal :abc, mm.key(:v1)
540
+ assert_nil mm.key(:v2)
518
541
 
519
- mm.push :abc, 1
542
+ mm.push :abc, :v2
543
+
544
+ assert_equal :abc, mm.key(:v1)
545
+ assert_equal :abc, mm.key(:v2)
546
+ assert_equal :abc, mm.key(:v1, :v2)
547
+ assert_nil mm.key(:v2, :v1)
548
+ assert_nil mm.key([:v1, :v2])
549
+
550
+ mm.delete :abc
551
+
552
+ mm.push :def, :v2, :v1
553
+
554
+ assert_equal :def, mm.key(:v2, :v1)
555
+ assert_nil mm.key(:v1, :v2)
556
+ assert_equal :def, mm.key(:v1)
557
+ assert_equal :def, mm.key(:v2)
558
+
559
+ mm.delete :def
560
+
561
+ mm.push :ghi, [ :v2, :v1 ]
562
+
563
+ assert_equal :ghi, mm.key([:v2, :v1])
564
+ assert_nil mm.key([:v1, :v2])
565
+ assert_nil mm.key(:v1)
566
+ assert_nil mm.key(:v2)
567
+
568
+ mm.push :ghi, :v1
520
569
 
521
- assert_equal :abc, mm.key([ 1 ])
570
+ assert_equal :ghi, mm.key([:v2, :v1])
571
+ assert_nil mm.key([:v1, :v2])
572
+ assert_equal :ghi, mm.key(:v1)
573
+ assert_nil mm.key(:v2)
522
574
  end
523
575
 
524
576
  def test_length_and_size
@@ -549,7 +601,7 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
549
601
  test_length_and_size
550
602
  end
551
603
 
552
- def test_merge
604
+ def test_multi_merge
553
605
 
554
606
  mm1 = MultiMap.new
555
607
 
@@ -562,12 +614,42 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
562
614
  mm2.push :abc, 4, 5
563
615
  mm2.push :def, 'a'
564
616
 
565
- mm3 = mm1.merge mm2
617
+ mm3 = mm1.multi_merge mm2
566
618
 
567
- assert_equal [ :abc, 1, :abc, 2, :abc, 3, :abc, 4, :abc, 5, :def, 'a' ], mm3.flatten
619
+ h = Hash.new
620
+
621
+ h.store :ghi, 'x'
622
+
623
+ mm4 = mm3.multi_merge h
624
+
625
+ assert_equal [ :abc, 1, :abc, 2, :abc, 3, :abc, 4, :abc, 5, :def, 'a', :ghi, 'x' ], mm4.flatten
626
+ end
627
+
628
+ def test_multi_merge!
629
+
630
+ mm1 = MultiMap.new
631
+
632
+ mm1.push :abc, 1, 2, 3
633
+
634
+ assert_equal [ :abc, 1, :abc, 2, :abc, 3 ], mm1.flatten
635
+
636
+ mm2 = MultiMap.new
637
+
638
+ mm2.push :abc, 4, 5
639
+ mm2.push :def, 'a'
640
+
641
+ mm1.multi_merge! mm2
642
+
643
+ h = Hash.new
644
+
645
+ h.store :ghi, 'x'
646
+
647
+ mm1.multi_merge! h
648
+
649
+ assert_equal [ :abc, 1, :abc, 2, :abc, 3, :abc, 4, :abc, 5, :def, 'a', :ghi, 'x' ], mm1.flatten
568
650
  end
569
651
 
570
- def test_merge!
652
+ def test_strict_merge
571
653
 
572
654
  mm1 = MultiMap.new
573
655
 
@@ -580,9 +662,39 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
580
662
  mm2.push :abc, 4, 5
581
663
  mm2.push :def, 'a'
582
664
 
583
- mm1.merge! mm2
665
+ mm3 = mm1.strict_merge mm2
666
+
667
+ h = Hash.new
668
+
669
+ h.store :ghi, 'x'
670
+
671
+ mm4 = mm3.strict_merge h
584
672
 
585
- assert_equal [ :abc, 1, :abc, 2, :abc, 3, :abc, 4, :abc, 5, :def, 'a' ], mm1.flatten
673
+ assert_equal [ :abc, 4, :abc, 5, :def, 'a', :ghi, 'x' ], mm4.flatten
674
+ end
675
+
676
+ def test_strict_merge!
677
+
678
+ mm1 = MultiMap.new
679
+
680
+ mm1.push :abc, 1, 2, 3
681
+
682
+ assert_equal [ :abc, 1, :abc, 2, :abc, 3 ], mm1.flatten
683
+
684
+ mm2 = MultiMap.new
685
+
686
+ mm2.push :abc, 4, 5
687
+ mm2.push :def, 'a'
688
+
689
+ mm1.strict_merge! mm2
690
+
691
+ h = Hash.new
692
+
693
+ h.store :ghi, 'x'
694
+
695
+ mm1.strict_merge! h
696
+
697
+ assert_equal [ :abc, 4, :abc, 5, :def, 'a', :ghi, 'x' ], mm1.flatten
586
698
  end
587
699
 
588
700
  def test_push
@@ -698,6 +810,25 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
698
810
  assert_equal ({ abc: [ 1, 2, 3, 4, 5 ], def: [] }), mm.to_h
699
811
  end
700
812
 
813
+ def test_values_unflattened
814
+
815
+ mm = MultiMap.new
816
+
817
+ assert_equal [], mm.values_unflattened
818
+
819
+ mm.store :abc
820
+
821
+ assert_equal [ [] ], mm.values_unflattened
822
+
823
+ mm.store :abc, 1, 2, '3', nil, false
824
+
825
+ assert_equal [ [ 1, 2, '3', nil, false ] ], mm.values_unflattened
826
+
827
+ mm.store :def, true
828
+
829
+ assert_equal [ [ 1, 2, '3', nil, false ], [ true ] ], mm.values_unflattened
830
+ end
831
+
701
832
  def test_values
702
833
 
703
834
  mm = MultiMap.new
@@ -706,11 +837,38 @@ class Test_Xqsr3_Containers_MultiMap < Test::Unit::TestCase
706
837
 
707
838
  mm.store :abc
708
839
 
709
- assert_equal [ [] ], mm.values
840
+ assert_equal [], mm.values
710
841
 
711
842
  mm.store :abc, 1, 2, '3', nil, false
712
843
 
713
- assert_equal [ [ 1, 2, '3', nil, false ] ], mm.values
844
+ assert_equal [ 1, 2, '3', nil, false ], mm.values
845
+
846
+ mm.store :def, true
847
+
848
+ assert_equal [ 1, 2, '3', nil, false, true ], mm.values
849
+ end
850
+
851
+ def test_to_s
852
+
853
+ mm = MultiMap[]
854
+
855
+ assert_equal "{}", mm.to_s
856
+
857
+ mm.store :abc
858
+
859
+ assert_equal "{:abc=>[]}", mm.to_s
860
+
861
+ mm.store :abc, 1
862
+
863
+ assert_equal "{:abc=>[1]}", mm.to_s
864
+
865
+ mm.store :abc, 1, 23
866
+
867
+ assert_equal "{:abc=>[1, 23]}", mm.to_s
868
+
869
+ mm.store :def, *(0...10).to_a
870
+
871
+ assert_equal "{:abc=>[1, 23], :def=>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}", mm.to_s
714
872
  end
715
873
  end
716
874