hashslice 1.0.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 846d78f8f3d0c07324618f622a2020ff9ea79401d05698ca6744938ae31ed301
4
+ data.tar.gz: da64ebcd8bed12fc2c1258c8c4443e5c759fb85d10e1ea12231b178a91dd5561
5
+ SHA512:
6
+ metadata.gz: ca1dfa947f376f65c7a2f229b91a8681ed10d8f54328e4225ad37d4426898636631a9e2ea14fb28a7a869e67d9d2bb159cca64f0a9003db8ed2e1285c27f16e0
7
+ data.tar.gz: b88d35c86df40c4507c25b893a96dc6a7beceb5c2546e732c31c4ab3e16fc47f79dba7231df2d1f2c337d86b4b5feb689c65054b925514d49959d15ef629e7ce
Binary file
Binary file
@@ -1,3 +1,26 @@
1
+ == 1.2.0 - 23-Sep-2020
2
+ * Switched from test-unit to rspec.
3
+ * Added a Gemfile.
4
+ * Added some metadata to the gemspec.
5
+
6
+ == 1.1.2 - 14-Jul-2020
7
+ * Now silences the redefinition warning.
8
+ * Fix the license name in the gemspec (missing hyphen).
9
+ * Add an explicit .rdoc extension to the README, MANIFEST and CHANGES files.
10
+ * Added a loose dependency (version 3+) to the test-unit development dependency.
11
+
12
+ == 1.1.1 - 5-Apr-2018
13
+ * Fixed deprecation warnings for Ruby 2.4 and later.
14
+ * The VERSION_HASHSLICE constant is now frozen.
15
+ * Updated the cert.
16
+
17
+ == 1.1.0 - 7-Dec-2015
18
+ * This gem is now signed.
19
+ * Updates to the gemspec and Rakefile.
20
+
21
+ == 1.0.9 - 19-Sep-2011
22
+ * Cosmetic updates to silence Ruby 1.9.x warnings.
23
+
1
24
  == 1.0.8 - 31-Aug-2011
2
25
  * Removed an old install task, updated the clean task and set a
3
26
  default task in the Rakefile.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org' do
2
+ gem 'rake'
3
+ group 'test' do
4
+ gem 'rspec', '~> 3.9'
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ * CHANGES.rdoc
2
+ * MANIFEST.rdoc
3
+ * README.rdoc
4
+ * Gemfile
5
+ * Rakefile
6
+ * hashslice.gemspec
7
+ * certs/djberg96_pub.pem
8
+ * lib/hashslice.rb
9
+ * spec/hashslice_spec.rb
@@ -0,0 +1,49 @@
1
+ = Description
2
+ Slicing for Ruby hashes.
3
+
4
+ = Installation
5
+ gem install hashslice
6
+
7
+ = Synopsis
8
+ require 'hashslice'
9
+
10
+ hash = {'a' => 1, 'b' => 2, 'c' => 3}
11
+
12
+ # Slice reference
13
+ hash['a', 'b'] # -> [1, 2]
14
+ hash['a'] # -> 1
15
+
16
+ # Slice assignment
17
+ hash['a', 'b'] = 7, 8
18
+
19
+ hash # -> {'a' => 7, 'b' => 8, 'c' => 3}
20
+
21
+ # Sub hash
22
+ hash.hash_of('a', 'b') # -> {'a' => 1, 'b' => 2}
23
+
24
+ = Overview
25
+ This library modifies the Hash#[] and Hash#[]= methods so that they can
26
+ handle list reference or assignment. It also adds the Hash#hash_of method
27
+ that returns a hash slice.
28
+
29
+ == Hash#[*keys]
30
+ If more than one key is provided then an array is returned. Single
31
+ keys work as before, i.e. they return a single value.
32
+
33
+ == Hash#[*keys]=(*values)
34
+ The values on the right are assigned to the keys on left on a one for one
35
+ If there are more values than keys, the extra values are dropped.
36
+
37
+ = Copyright
38
+ Copyright (c) 2001-2020, The FaerieMUD Consortium and Daniel J. Berger.
39
+ All rights reserved.
40
+
41
+ = License
42
+ This module is free software. You may use, modify, and/or redistribute this
43
+ software under the terms of the Artistic License 2.0
44
+
45
+ http://www.perlfoundation.org/artistic_license_2_0
46
+
47
+ = Authors
48
+ * Michael Granger (original author)
49
+ * Daniel Berger (current maintainer)
data/Rakefile CHANGED
@@ -1,27 +1,26 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
- require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
4
 
5
5
  CLEAN.include("**/*.gem", "**/*.rbc")
6
6
 
7
7
  namespace :gem do
8
-
9
8
  desc 'Build the hashslice gem'
10
9
  task :create => [:clean] do
10
+ require 'rubygems/package'
11
11
  spec = eval(IO.read('hashslice.gemspec'))
12
- Gem::Builder.new(spec).build
12
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
+ Gem::Package.build(spec)
13
14
  end
14
15
 
15
16
  desc "Install the hashslice library as a gem"
16
17
  task :install => [:create] do
17
18
  file = Dir["*.gem"].first
18
- sh "gem install #{file}"
19
+ sh "gem install -l #{file}"
19
20
  end
20
21
  end
21
22
 
22
- Rake::TestTask.new do |t|
23
- t.warning = true
24
- t.verbose = true
25
- end
23
+ desc "Run the test suite"
24
+ RSpec::Core::RakeTask.new(:spec)
26
25
 
27
- task :default => :test
26
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
8
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
9
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
10
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
11
+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'
2
2
 
3
- Gem::Specification.new do |gem|
4
- gem.name = 'hashslice'
5
- gem.version = '1.0.8'
6
- gem.authors = ['Daniel J. Berger', 'Michael Granger']
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/shards'
10
- gem.summary = "Adds hash slicing to Ruby's Hash class"
11
- gem.test_file = 'test/test_hashslice.rb'
12
- gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'hashslice'
5
+ spec.version = '1.2.0'
6
+ spec.authors = ['Daniel J. Berger', 'Michael Granger']
7
+ spec.license = 'Artistic-2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/hashslice'
10
+ spec.summary = "Adds hash slicing to Ruby's Hash class"
11
+ spec.test_file = 'spec/hashslice_spec.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = Dir['certs/*']
13
14
 
14
- gem.rubyforge_project = 'shards'
15
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
15
+ spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc', 'MANIFEST.rdoc']
16
16
 
17
- gem.add_development_dependency('test-unit', '>= 2.1.0')
17
+ spec.add_development_dependency('rspec', '~> 3.9')
18
18
 
19
- gem.description = <<-EOF
19
+ spec.metadata = {
20
+ 'homepage_uri' => 'https://github.com/djberg96/hashslice',
21
+ 'bug_tracker_uri' => 'https://github.com/djberg96/hashslice/issues',
22
+ 'changelog_uri' => 'https://github.com/djberg96/hashslice/blob/master/CHANGES',
23
+ 'documentation_uri' => 'https://github.com/djberg96/hashslice/wiki',
24
+ 'source_code_uri' => 'https://github.com/djberg96/hashslice',
25
+ 'wiki_uri' => 'https://github.com/djberg96/hashslice/wiki'
26
+ }
27
+
28
+ spec.description = <<-EOF
20
29
  The hashslice library adds builtin hash slicing to Ruby's Hash class.
21
30
  This lets you reference, or assign to, multiple hash keys simultaneously
22
31
  via the Hash#[] and Hash#[]= methods, respectively.
@@ -3,7 +3,7 @@ class Hash
3
3
  alias hset []=
4
4
 
5
5
  # The version of the hashslice library
6
- VERSION_HASHSLICE = '1.0.8'
6
+ VERSION_HASHSLICE = '1.2.0'.freeze
7
7
 
8
8
  # Retrieve a hash slice. If a single key is provided, returns a single
9
9
  # value. If multiple keys are provided, an array of values is returned.
@@ -22,7 +22,14 @@ class Hash
22
22
  end
23
23
  end
24
24
 
25
- alias slice []
25
+ # Temporarily silence redefinition warning.
26
+ begin
27
+ old_verbose = $VERBOSE
28
+ $VERBOSE = false
29
+ alias slice []
30
+ ensure
31
+ $VERBOSE = old_verbose
32
+ end
26
33
 
27
34
  # Hash slice assignment. You can assign a list of values to a list of keys
28
35
  # in a single operation on a one for one basis.
@@ -46,9 +53,9 @@ class Hash
46
53
  else
47
54
  values = args.pop # Last arg is the value. The rest are keys.
48
55
  values = [values] unless values.is_a?(Array)
49
- args.each_index{ |i| hset(args[i], values[i]) }
50
- end
51
- end
56
+ args.each_index{ |i| hset(args[i], values[i]) }
57
+ end
58
+ end
52
59
 
53
60
  # Returns a sub-hash of the current hash.
54
61
  #
@@ -0,0 +1,80 @@
1
+ #######################################################################
2
+ # hashslice_spec.rb
3
+ #
4
+ # Test suite for the hashslice library. You should run these tests
5
+ # via the 'rake spec' task.
6
+ #######################################################################
7
+ require 'hashslice'
8
+ require 'rspec'
9
+
10
+ RSpec.describe Hash do
11
+ before do
12
+ @hash = {'a' => 1, 'b' => 2}
13
+ end
14
+
15
+ example "version" do
16
+ expect(Hash::VERSION_HASHSLICE).to eq('1.2.0')
17
+ expect(Hash::VERSION_HASHSLICE).to be_frozen
18
+ end
19
+
20
+ example "Hash#[] basic functionality" do
21
+ expect(@hash).to respond_to(:[])
22
+ expect{ @hash[] }.not_to raise_error
23
+ end
24
+
25
+ example "Hash#[] returns the expected value for a single argument" do
26
+ expect(@hash['a']).to eq(1)
27
+ expect(@hash['b']).to eq(2)
28
+ expect(@hash['c']).to eq(nil)
29
+ end
30
+
31
+ example "Hash#[] returns the expected value for multiple arguments" do
32
+ expect(@hash['a', 'b']).to eq([1, 2])
33
+ expect(@hash['b', 'a']).to eq([2, 1])
34
+ expect(@hash['a', 'b', 'c']).to eq([1, 2, nil])
35
+ end
36
+
37
+ example "Hash#[] returns the expected value for duplicate arguments" do
38
+ expect(@hash['a', 'a']).to eq([1, 1])
39
+ expect(@hash['a', 'b', 'a', 'b']).to eq([1, 2, 1, 2])
40
+ expect(@hash['a', 'a', 'c', 'c']).to eq([1, 1, nil, nil])
41
+ end
42
+
43
+ example "Hash#[]= basic functionality" do
44
+ expect(@hash).to respond_to(:[]=)
45
+ expect{ @hash['a'] = 3 }.not_to raise_error
46
+ expect{ @hash['a', 'b'] = 3 }.not_to raise_error
47
+ expect{ @hash['a', 'b'] = [3, 4] }.not_to raise_error
48
+ end
49
+
50
+ example "Hash#[]= with a single key and single value works as expected" do
51
+ expect(@hash['a'] = 3).to eq(3)
52
+ expect(@hash['a']).to eq(3)
53
+ expect(@hash['b'] = [4, 5]).to eq([4, 5])
54
+ expect(@hash['b']).to eq([4, 5])
55
+ end
56
+
57
+ example "Hash#[]= with a multiple keys and single value works as expected" do
58
+ expect(@hash['a', 'b'] = 3).to eq(3)
59
+ expect(@hash['a', 'b']).to eq([3, nil])
60
+ end
61
+
62
+ example "Hash#[]= with a multiple keys and multiple values works as expected" do
63
+ expect(@hash['a', 'b'] = [3, 4]).to eq([3, 4])
64
+ expect(@hash['a', 'b']).to eq([3, 4])
65
+ end
66
+
67
+ example "Hash#[]= with a multiple keys and an odd number of values works as expected" do
68
+ expect{ @hash['a', 'b'] = 3, 4, 5 }.not_to raise_error
69
+ expect(@hash).to eq({'a' => 3, 'b' => 4})
70
+ end
71
+
72
+ example "slice_alias" do
73
+ expect(Hash.instance_method(:slice)).to eql(Hash.instance_method(:[]))
74
+ end
75
+
76
+ example "hash_of returns a sub hash" do
77
+ expect(@hash).to respond_to(:hash_of)
78
+ expect(@hash.hash_of('a', 'b')).to eq({'a' => 1, 'b' => 2})
79
+ end
80
+ end
metadata CHANGED
@@ -1,89 +1,106 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hashslice
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 8
10
- version: 1.0.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Daniel J. Berger
14
8
  - Michael Granger
15
- autorequire:
9
+ autorequire:
16
10
  bindir: bin
17
- cert_chain: []
18
-
19
- date: 2011-08-31 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: test-unit
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 2
32
- - 1
33
- - 0
34
- version: 2.1.0
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
15
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
16
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
17
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
18
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
19
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
20
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6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pRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
37
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
38
+ -----END CERTIFICATE-----
39
+ date: 2020-09-23 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.9'
35
48
  type: :development
36
- version_requirements: *id001
37
- description: " The hashslice library adds builtin hash slicing to Ruby's Hash class.\n This lets you reference, or assign to, multiple hash keys simultaneously\n via the Hash#[] and Hash#[]= methods, respectively.\n"
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ description: |2
56
+ The hashslice library adds builtin hash slicing to Ruby's Hash class.
57
+ This lets you reference, or assign to, multiple hash keys simultaneously
58
+ via the Hash#[] and Hash#[]= methods, respectively.
38
59
  email: djberg96@gmail.com
39
60
  executables: []
40
-
41
61
  extensions: []
42
-
43
- extra_rdoc_files:
44
- - README
45
- - CHANGES
46
- - MANIFEST
47
- files:
48
- - CHANGES
62
+ extra_rdoc_files:
63
+ - README.rdoc
64
+ - CHANGES.rdoc
65
+ - MANIFEST.rdoc
66
+ files:
67
+ - CHANGES.rdoc
68
+ - Gemfile
69
+ - MANIFEST.rdoc
70
+ - README.rdoc
71
+ - Rakefile
72
+ - certs/djberg96_pub.pem
49
73
  - hashslice.gemspec
50
74
  - lib/hashslice.rb
51
- - MANIFEST
52
- - Rakefile
53
- - README
54
- - test/test_hashslice.rb
55
- homepage: http://www.rubyforge.org/projects/shards
56
- licenses:
57
- - Artistic 2.0
58
- post_install_message:
75
+ - spec/hashslice_spec.rb
76
+ homepage: http://github.com/djberg96/hashslice
77
+ licenses:
78
+ - Artistic-2.0
79
+ metadata:
80
+ homepage_uri: https://github.com/djberg96/hashslice
81
+ bug_tracker_uri: https://github.com/djberg96/hashslice/issues
82
+ changelog_uri: https://github.com/djberg96/hashslice/blob/master/CHANGES
83
+ documentation_uri: https://github.com/djberg96/hashslice/wiki
84
+ source_code_uri: https://github.com/djberg96/hashslice
85
+ wiki_uri: https://github.com/djberg96/hashslice/wiki
86
+ post_install_message:
59
87
  rdoc_options: []
60
-
61
- require_paths:
88
+ require_paths:
62
89
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
66
92
  - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
75
97
  - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
81
100
  requirements: []
82
-
83
- rubyforge_project: shards
84
- rubygems_version: 1.8.10
85
- signing_key:
86
- specification_version: 3
101
+ rubygems_version: 3.1.4
102
+ signing_key:
103
+ specification_version: 4
87
104
  summary: Adds hash slicing to Ruby's Hash class
88
- test_files:
89
- - test/test_hashslice.rb
105
+ test_files:
106
+ - spec/hashslice_spec.rb
Binary file
data/MANIFEST DELETED
@@ -1,7 +0,0 @@
1
- * CHANGES
2
- * MANIFEST
3
- * README
4
- * Rakefile
5
- * hashslice.gemspec
6
- * lib/hashslice.rb
7
- * test/test_hashslice.rb
data/README DELETED
@@ -1,49 +0,0 @@
1
- = Description
2
- Slicing for Ruby hashes.
3
-
4
- = Installation
5
- gem install hashslice
6
-
7
- = Synopsis
8
- require 'hashslice'
9
-
10
- hash = {'a' => 1, 'b' => 2, 'c' => 3}
11
-
12
- # Slice reference
13
- hash['a', 'b'] # -> [1, 2]
14
- hash['a'] # -> 1
15
-
16
- # Slice assignment
17
- hash['a', 'b'] = 7, 8
18
-
19
- hash # -> {'a' => 7, 'b' => 8, 'c' => 3}
20
-
21
- # Sub hash
22
- hash.hash_of('a', 'b') # -> {'a' => 1, 'b' => 2}
23
-
24
- = Overview
25
- This library modifies the Hash#[] and Hash#[]= methods so that they can
26
- handle list reference or assignment. It also adds the Hash#hash_of method
27
- that returns a hash slice.
28
-
29
- == Hash#[*keys]
30
- If more than one key is provided then an array is returned. Single
31
- keys work as before, i.e. they return a single value.
32
-
33
- == Hash#[*keys]=(*values)
34
- The values on the right are assigned to the keys on left on a one for one
35
- If there are more values than keys, the extra values are dropped.
36
-
37
- = Copyright
38
- Copyright (c) 2001-2011, The FaerieMUD Consortium and Daniel J. Berger.
39
- All rights reserved.
40
-
41
- = License
42
- This module is free software. You may use, modify, and/or redistribute this
43
- software under the terms of the Artistic License 2.0
44
-
45
- http://www.perlfoundation.org/artistic_license_2_0
46
-
47
- = Authors
48
- Michael Granger (original author)
49
- Daniel Berger (current maintainer)
@@ -1,95 +0,0 @@
1
- #######################################################################
2
- # test_hashslice.rb
3
- #
4
- # Test suite for the hashslice library. You should run these tests
5
- # via the 'rake test' task.
6
- #######################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'hashslice'
11
- require 'test/unit'
12
-
13
- class TC_Hashslice < Test::Unit::TestCase
14
- def setup
15
- @hash = {'a' => 1, 'b' => 2}
16
- end
17
-
18
- def test_version
19
- assert_equal('1.0.8', Hash::VERSION_HASHSLICE)
20
- end
21
-
22
- def test_get_slice_instance_method_basic
23
- assert_respond_to(@hash, :[])
24
- assert_nothing_raised{ @hash['a'] }
25
- assert_nothing_raised{ @hash['a', 'b'] }
26
- assert_kind_of(Integer, @hash['a'])
27
- assert_kind_of(Array, @hash['a', 'b'])
28
- end
29
-
30
- def test_get_slice_instance_method
31
- assert_equal(1, @hash['a'])
32
- assert_equal([1, 2], @hash['a', 'b'])
33
- assert_equal([1, 2, nil], @hash['a', 'b', 'c'])
34
- assert_nil(@hash['bogus'])
35
- end
36
-
37
- def test_get_slice_duplicate_keys
38
- assert_equal([1, 1], @hash['a', 'a'])
39
- assert_equal([1, 2, 1, 2], @hash['a', 'b', 'a', 'b'])
40
- end
41
-
42
- def test_set_slice_instance_method_basic
43
- assert_respond_to(@hash, :[]=)
44
- assert_nothing_raised{ @hash['a'] = 3 }
45
- assert_nothing_raised{ @hash['a', 'b'] = 3 }
46
- assert_nothing_raised{ @hash['a', 'b'] = 3, 4 }
47
- assert_kind_of(Fixnum, @hash['a'] = 3)
48
- assert_kind_of(Fixnum, @hash['a', 'b'] = 3)
49
- assert_kind_of(Fixnum, @hash['a', 'b'] = 3, 4)
50
- end
51
-
52
- # hash[key] = value
53
- def test_set_slice_instance_method_single_key_and_value
54
- assert_nothing_raised{ @hash['a'] = 3 }
55
- assert_nothing_raised{ @hash['b'] = [1, 2] }
56
- assert_equal({'a' => 3, 'b' => [1, 2]}, @hash)
57
- end
58
-
59
- # hash[key1, key2] = value
60
- def test_set_slice_instance_method_multiple_keys_single_value
61
- assert_nothing_raised{ @hash['a', 'b'] = 3 }
62
- assert_equal({'a' => 3, 'b' => nil}, @hash)
63
- end
64
-
65
- # hash[key1, key2] = value1, value2
66
- def test_set_slice_instance_method_multiple_keys_multiple_values
67
- assert_nothing_raised{ @hash['a', 'b'] = 3, 4 }
68
- assert_equal({'a' => 3, 'b' => 4}, @hash)
69
- end
70
-
71
- # hash[key] = value1, value2
72
- def test_set_slice_instance_method_single_key_multiple_values
73
- assert_nothing_raised{ @hash['a'] = 3, 4 }
74
- assert_equal({'a' => [3, 4], 'b' => 2}, @hash)
75
- end
76
-
77
- # hash[key1, key2] = value1, value2, value3
78
- def test_set_slice_instance_method_multiple_keys_odd_values
79
- assert_nothing_raised{ @hash['a', 'b'] = 3, 4, 5 }
80
- assert_equal({'a' => 3, 'b' => 4}, @hash)
81
- end
82
-
83
- def test_slice_alias
84
- assert_true(Hash.instance_method(:slice) == Hash.instance_method(:[]))
85
- end
86
-
87
- def test_hash_of
88
- assert_respond_to(@hash, :hash_of)
89
- assert_equal({'a' => 1, 'b' => 2}, @hash.hash_of('a', 'b'))
90
- end
91
-
92
- def teardown
93
- @hash = nil
94
- end
95
- end