rufus-tokyo 1.0.3 → 1.0.4

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 (55) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.txt +6 -0
  3. data/Rakefile +91 -0
  4. data/doc/decision_table.numbers +0 -0
  5. data/lib/rufus/edo/README.txt +101 -0
  6. data/lib/rufus/edo/tabcore.rb +1 -3
  7. data/lib/rufus/tokyo.rb +1 -2
  8. data/lib/rufus/tokyo/cabinet/lib.rb +4 -7
  9. data/lib/rufus/tokyo/cabinet/table.rb +10 -13
  10. data/lib/rufus/tokyo/cabinet/util.rb +4 -1
  11. data/lib/rufus/tokyo/hmethods.rb +4 -4
  12. data/lib/rufus/tokyo/outlen.rb +5 -1
  13. data/lib/rufus/tokyo/tyrant/abstract.rb +8 -0
  14. data/lib/rufus/tokyo/tyrant/lib.rb +6 -6
  15. data/lib/rufus/tokyo/tyrant/table.rb +9 -1
  16. data/lib/rufus/tokyo/version.rb +32 -0
  17. data/rufus-tokyo.gemspec +135 -0
  18. data/spec/cabinet_btree_spec.rb +92 -0
  19. data/spec/cabinet_fixed_spec.rb +33 -0
  20. data/spec/cabinet_spec.rb +291 -0
  21. data/spec/cabinetconfig_spec.rb +82 -0
  22. data/spec/dystopia_core_spec.rb +124 -0
  23. data/spec/edo_cabinet_btree_spec.rb +123 -0
  24. data/spec/edo_cabinet_fixed_spec.rb +42 -0
  25. data/spec/edo_cabinet_spec.rb +286 -0
  26. data/spec/edo_ntyrant_spec.rb +224 -0
  27. data/spec/edo_ntyrant_table_spec.rb +296 -0
  28. data/spec/edo_table_spec.rb +292 -0
  29. data/spec/hmethods_spec.rb +73 -0
  30. data/spec/incr.lua +23 -0
  31. data/spec/openable_spec.rb +51 -0
  32. data/spec/shared_abstract_spec.rb +426 -0
  33. data/spec/shared_table_spec.rb +675 -0
  34. data/spec/shared_tyrant_spec.rb +42 -0
  35. data/spec/spec_base.rb +23 -0
  36. data/spec/start_tyrants.sh +28 -0
  37. data/spec/stop_tyrants.sh +9 -0
  38. data/spec/table_spec.rb +267 -0
  39. data/spec/tyrant_spec.rb +218 -0
  40. data/spec/tyrant_table_spec.rb +298 -0
  41. data/spec/util_list_spec.rb +197 -0
  42. data/spec/util_map_spec.rb +130 -0
  43. data/tasks/dev.rb +70 -0
  44. data/test/bm0.rb +353 -0
  45. data/test/bm1_compression.rb +54 -0
  46. data/test/con0.rb +30 -0
  47. data/test/mem.rb +49 -0
  48. data/test/mem1.rb +44 -0
  49. data/test/readme0.rb +17 -0
  50. data/test/readme1.rb +21 -0
  51. data/test/readme2.rb +15 -0
  52. data/test/readme3.rb +24 -0
  53. data/test/readmes_test.sh +17 -0
  54. metadata +81 -21
  55. data/MIGRATED.txt +0 -1
@@ -0,0 +1,32 @@
1
+ #--
2
+ # Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Rufus
27
+ module Tokyo
28
+
29
+ VERSION = '1.0.4'
30
+ end
31
+ end
32
+
@@ -0,0 +1,135 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rufus-tokyo}
8
+ s.version = "1.0.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["John Mettraux", "Zev Blut", "Jeremy Hinegardner", "James Edward Gray II"]
12
+ s.date = %q{2009-12-25}
13
+ s.description = %q{
14
+ Ruby-ffi based lib to access Tokyo Cabinet and Tyrant.
15
+
16
+ The ffi-based structures are available via the Rufus::Tokyo namespace.
17
+ There is a Rufus::Edo namespace that interfaces with Hirabayashi-san's native Ruby interface, and whose API is equal to the Rufus::Tokyo one.
18
+
19
+ Finally rufus-tokyo includes ffi-based interfaces to Tokyo Dystopia (thanks to Jeremy Hinegardner).
20
+ }
21
+ s.email = %q{jmettraux@gmail.com}
22
+ s.extra_rdoc_files = [
23
+ "LICENSE.txt",
24
+ "README.rdoc"
25
+ ]
26
+ s.files = [
27
+ ".gitignore",
28
+ "CHANGELOG.txt",
29
+ "CREDITS.txt",
30
+ "LICENSE.txt",
31
+ "README.rdoc",
32
+ "Rakefile",
33
+ "TODO.txt",
34
+ "doc/decision_table.numbers",
35
+ "lib/rufus-edo.rb",
36
+ "lib/rufus-tokyo.rb",
37
+ "lib/rufus/edo.rb",
38
+ "lib/rufus/edo/README.txt",
39
+ "lib/rufus/edo/cabcore.rb",
40
+ "lib/rufus/edo/cabinet/abstract.rb",
41
+ "lib/rufus/edo/cabinet/table.rb",
42
+ "lib/rufus/edo/error.rb",
43
+ "lib/rufus/edo/ntyrant.rb",
44
+ "lib/rufus/edo/ntyrant/abstract.rb",
45
+ "lib/rufus/edo/ntyrant/table.rb",
46
+ "lib/rufus/edo/tabcore.rb",
47
+ "lib/rufus/tokyo.rb",
48
+ "lib/rufus/tokyo/cabinet/abstract.rb",
49
+ "lib/rufus/tokyo/cabinet/lib.rb",
50
+ "lib/rufus/tokyo/cabinet/table.rb",
51
+ "lib/rufus/tokyo/cabinet/util.rb",
52
+ "lib/rufus/tokyo/config.rb",
53
+ "lib/rufus/tokyo/dystopia.rb",
54
+ "lib/rufus/tokyo/dystopia/core.rb",
55
+ "lib/rufus/tokyo/dystopia/lib.rb",
56
+ "lib/rufus/tokyo/dystopia/words.rb",
57
+ "lib/rufus/tokyo/hmethods.rb",
58
+ "lib/rufus/tokyo/openable.rb",
59
+ "lib/rufus/tokyo/outlen.rb",
60
+ "lib/rufus/tokyo/query.rb",
61
+ "lib/rufus/tokyo/transactions.rb",
62
+ "lib/rufus/tokyo/ttcommons.rb",
63
+ "lib/rufus/tokyo/tyrant.rb",
64
+ "lib/rufus/tokyo/tyrant/abstract.rb",
65
+ "lib/rufus/tokyo/tyrant/ext.rb",
66
+ "lib/rufus/tokyo/tyrant/lib.rb",
67
+ "lib/rufus/tokyo/tyrant/table.rb",
68
+ "lib/rufus/tokyo/utils.rb",
69
+ "lib/rufus/tokyo/version.rb",
70
+ "rufus-tokyo.gemspec",
71
+ "spec/cabinet_btree_spec.rb",
72
+ "spec/cabinet_fixed_spec.rb",
73
+ "spec/cabinet_spec.rb",
74
+ "spec/cabinetconfig_spec.rb",
75
+ "spec/dystopia_core_spec.rb",
76
+ "spec/edo_cabinet_btree_spec.rb",
77
+ "spec/edo_cabinet_fixed_spec.rb",
78
+ "spec/edo_cabinet_spec.rb",
79
+ "spec/edo_ntyrant_spec.rb",
80
+ "spec/edo_ntyrant_table_spec.rb",
81
+ "spec/edo_table_spec.rb",
82
+ "spec/hmethods_spec.rb",
83
+ "spec/incr.lua",
84
+ "spec/openable_spec.rb",
85
+ "spec/shared_abstract_spec.rb",
86
+ "spec/shared_table_spec.rb",
87
+ "spec/shared_tyrant_spec.rb",
88
+ "spec/spec.rb",
89
+ "spec/spec_base.rb",
90
+ "spec/start_tyrants.sh",
91
+ "spec/stop_tyrants.sh",
92
+ "spec/table_spec.rb",
93
+ "spec/tyrant_spec.rb",
94
+ "spec/tyrant_table_spec.rb",
95
+ "spec/util_list_spec.rb",
96
+ "spec/util_map_spec.rb",
97
+ "tasks/dev.rb",
98
+ "test/bm0.rb",
99
+ "test/bm1_compression.rb",
100
+ "test/con0.rb",
101
+ "test/mem.rb",
102
+ "test/mem1.rb",
103
+ "test/readme0.rb",
104
+ "test/readme1.rb",
105
+ "test/readme2.rb",
106
+ "test/readme3.rb",
107
+ "test/readmes_test.sh"
108
+ ]
109
+ s.homepage = %q{http://github.com/jmettraux/rufus-tokyo/}
110
+ s.rdoc_options = ["--charset=UTF-8"]
111
+ s.require_paths = ["lib"]
112
+ s.rubyforge_project = %q{rufus}
113
+ s.rubygems_version = %q{1.3.5}
114
+ s.summary = %q{ruby-ffi based lib to access Tokyo Cabinet, Tyrant and Dystopia}
115
+ s.test_files = [
116
+ "spec/spec.rb"
117
+ ]
118
+
119
+ if s.respond_to? :specification_version then
120
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
121
+ s.specification_version = 3
122
+
123
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
124
+ s.add_runtime_dependency(%q<ffi>, [">= 0"])
125
+ s.add_development_dependency(%q<yard>, [">= 0"])
126
+ else
127
+ s.add_dependency(%q<ffi>, [">= 0"])
128
+ s.add_dependency(%q<yard>, [">= 0"])
129
+ end
130
+ else
131
+ s.add_dependency(%q<ffi>, [">= 0"])
132
+ s.add_dependency(%q<yard>, [">= 0"])
133
+ end
134
+ end
135
+
@@ -0,0 +1,92 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Fri Aug 28 08:58:37 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+
10
+ require 'rufus/tokyo'
11
+
12
+ FileUtils.mkdir('tmp') rescue nil
13
+
14
+ DB_FILE = "tmp/cabinet_btree_spec.tcb"
15
+
16
+
17
+ describe 'Rufus::Tokyo::Cabinet .tcb' do
18
+
19
+ before do
20
+ FileUtils.rm(DB_FILE) if File.exist? DB_FILE
21
+ @db = Rufus::Tokyo::Cabinet.new(DB_FILE)
22
+ end
23
+ after do
24
+ @db.close
25
+ end
26
+
27
+ it 'should accept duplicate values' do
28
+
29
+ @db.putdup('a', 'a0')
30
+ @db.putdup('a', 'a1')
31
+
32
+ @db.getdup('a').should.equal([ 'a0', 'a1' ])
33
+ end
34
+
35
+ it 'should be able to fetch keys for duplicate values' do
36
+ [ %w[John Hornbeck],
37
+ %w[Tim Gourley],
38
+ %w[Grant Schofield],
39
+ %w[James Gray],
40
+ %w[Dana Gray] ].each do |first, last|
41
+ @db.putdup(last, first)
42
+ end
43
+ @db.keys.should.equal(%w[Gourley Gray Hornbeck Schofield])
44
+ @db.keys(:prefix => "G").should.equal(%w[Gourley Gray])
45
+ end
46
+ end
47
+
48
+ describe 'Rufus::Tokyo::Cabinet .tcb methods' do
49
+
50
+ it 'should fail on other structures' do
51
+
52
+ @db = Rufus::Tokyo::Cabinet.new(DB_FILE.sub(/\.tcb\z/, ".tch"))
53
+
54
+ lambda { @db.putdup('a', 'a0') }.should.raise(NoMethodError)
55
+
56
+ @db.close
57
+ end
58
+ end
59
+
60
+ describe 'Rufus::Tokyo::Cabinet .tcb order' do
61
+
62
+ before do
63
+ FileUtils.rm(DB_FILE) if File.exist? DB_FILE
64
+ end
65
+
66
+ it 'should default to a lexical order' do
67
+
68
+ db = Rufus::Tokyo::Cabinet.new(DB_FILE)
69
+ fields = [1, 2, 10, 11, 20, 21]
70
+ fields.each do |n|
71
+ db[n] = n
72
+ end
73
+ db.keys.should.equal(fields.map { |n| n.to_s }.sort)
74
+ db.close
75
+ end
76
+
77
+ it 'should allow an explicit :cmpfunc => :lexical' do
78
+
79
+ db = Rufus::Tokyo::Cabinet.new(DB_FILE, :cmpfunc => :lexical)
80
+ fields = [1, 2, 10, 11, 20, 21]
81
+ fields.each do |n|
82
+ db[n] = n
83
+ end
84
+ db.keys.should.equal(fields.map { |n| n.to_s }.sort)
85
+ db.close
86
+ end
87
+
88
+ #
89
+ # It's not possible to call tcbdbsetcmpfunc() through the abstract API, so
90
+ # changing comparison functions are only supported through the Edo interface.
91
+ #
92
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/spec_base'
2
+
3
+ require 'rufus/tokyo'
4
+
5
+ FileUtils.mkdir('tmp') rescue nil
6
+
7
+
8
+ describe 'Rufus::Tokyo::Cabinet .tcf' do
9
+
10
+ before do
11
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_fixed_spec.tcf', :width => 4)
12
+ @db.clear
13
+ end
14
+ after do
15
+ @db.close
16
+ end
17
+
18
+ it 'should support keys' do
19
+ @db[1] = "one"
20
+ @db[2] = "two"
21
+ @db[3] = "three"
22
+ @db[7] = "seven"
23
+ @db.keys.should.equal(%w[1 2 3 7])
24
+ end
25
+
26
+ it 'should accept a width at creation' do
27
+
28
+ @db[1] = "one"
29
+ @db[2] = "two"
30
+ @db[3] = "three"
31
+ @db.to_a.should.equal([%w[1 one], %w[2 two], %w[3 thre]])
32
+ end
33
+ end
@@ -0,0 +1,291 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Sun Feb 8 15:02:08 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+ require File.dirname(__FILE__) + '/shared_abstract_spec'
10
+
11
+ require 'rufus/tokyo'
12
+
13
+ FileUtils.mkdir('tmp') rescue nil
14
+
15
+
16
+ describe 'a missing Rufus::Tokyo::Cabinet' do
17
+
18
+ it 'should raise an error when opening in read-only mode' do
19
+
20
+ lambda {
21
+ Rufus::Tokyo::Cabinet.new('tmp/naidesuyo.tch', :mode => 'r')
22
+ }.should.raise(Rufus::Tokyo::TokyoError).message.should.equal(
23
+ "failed to open/create db 'tmp/naidesuyo.tch#mode=r' {:mode=>\"r\"}")
24
+ end
25
+ end
26
+
27
+ describe Rufus::Tokyo::Cabinet do
28
+
29
+ before do
30
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
31
+ @db.clear
32
+ end
33
+ after do
34
+ @db.close
35
+ end
36
+
37
+ behaves_like "an abstract structure"
38
+
39
+ it 'should return its path' do
40
+
41
+ @db.path.should.equal('tmp/cabinet_spec.tch')
42
+ end
43
+
44
+ it 'should create its underlying file' do
45
+
46
+ File.exist?('tmp/cabinet_spec.tch').should.equal(true)
47
+ end
48
+ end
49
+
50
+ describe Rufus::Tokyo::Cabinet do
51
+
52
+ before do
53
+ @n = 50
54
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
55
+ @db.clear
56
+ @n.times { |i| @db["person#{i}"] = 'whoever' }
57
+ @n.times { |i| @db["animal#{i}"] = 'whichever' }
58
+ @db["toto#{0.chr}5"] = 'toto'
59
+ end
60
+ after do
61
+ @db.close
62
+ end
63
+
64
+ behaves_like 'abstract structure #keys'
65
+ end
66
+
67
+ describe Rufus::Tokyo::Cabinet do
68
+
69
+ before do
70
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
71
+ @db.clear
72
+ end
73
+ after do
74
+ @db.close
75
+ end
76
+
77
+ behaves_like 'abstract structure with transactions'
78
+ end
79
+
80
+ describe Rufus::Tokyo::Cabinet do
81
+
82
+ it 'should accept a default value' do
83
+
84
+ cab = Rufus::Tokyo::Cabinet.new(
85
+ 'tmp/cabinet_spec_default.tch', :default => '@?!')
86
+ cab['a'] = 'A'
87
+ cab.size.should.equal(1)
88
+ cab['b'].should.equal('@?!')
89
+ cab.close
90
+ end
91
+
92
+ it 'should accept a default value (later)' do
93
+
94
+ cab = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec_default.tch')
95
+ cab.default = '@?!'
96
+ cab['a'] = 'A'
97
+ cab.size.should.equal(1)
98
+ cab['b'].should.equal('@?!')
99
+ cab.close
100
+ end
101
+ end
102
+
103
+ describe Rufus::Tokyo::Cabinet do
104
+
105
+ before do
106
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
107
+ @db.clear
108
+ 3.times { |i| @db[i.to_s] = "val#{i}" }
109
+ end
110
+ after do
111
+ @db.close
112
+ end
113
+
114
+ behaves_like 'abstract structure #lget/lput/ldelete'
115
+ end
116
+
117
+ describe Rufus::Tokyo::Cabinet do
118
+
119
+ before do
120
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
121
+ @db.clear
122
+ end
123
+ after do
124
+ @db.close
125
+ end
126
+
127
+ behaves_like 'abstract structure #add{int|double}'
128
+ end
129
+
130
+ describe Rufus::Tokyo::Cabinet do
131
+
132
+ before do
133
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
134
+ @db.clear
135
+ end
136
+ after do
137
+ @db.close
138
+ end
139
+
140
+ behaves_like 'abstract structure #putkeep'
141
+ behaves_like 'abstract structure #putcat'
142
+ end
143
+
144
+ describe Rufus::Tokyo::Cabinet do
145
+
146
+ it 'should copy correctly' do
147
+
148
+ cab = Rufus::Tokyo::Cabinet.new('tmp/spec_source.tch')
149
+ 5000.times { |i| cab["key #{i}"] = "val #{i}" }
150
+ cab.size.should.equal(5000)
151
+ cab.copy('tmp/spec_target.tch')
152
+ cab.close
153
+
154
+ cab = Rufus::Tokyo::Cabinet.new('tmp/spec_target.tch')
155
+ cab.size.should.equal(5000)
156
+ cab['key 4999'].should.equal('val 4999')
157
+ cab.close
158
+
159
+ FileUtils.rm('tmp/spec_source.tch')
160
+ FileUtils.rm('tmp/spec_target.tch')
161
+ end
162
+
163
+ it 'should copy compactly' do
164
+
165
+ cab = Rufus::Tokyo::Cabinet.new('tmp/spec_source.tch')
166
+ 100.times { |i| cab["key #{i}"] = "val #{i}" }
167
+ 50.times { |i| cab.delete("key #{i}") }
168
+ cab.size.should.equal(50)
169
+ cab.compact_copy('tmp/spec_target.tch')
170
+ cab.close
171
+
172
+ cab = Rufus::Tokyo::Cabinet.new('tmp/spec_target.tch')
173
+ cab.size.should.equal(50)
174
+ cab['key 99'].should.equal('val 99')
175
+ cab.close
176
+
177
+ fs0 = File.size('tmp/spec_source.tch')
178
+ fs1 = File.size('tmp/spec_target.tch')
179
+ (fs0 > fs1).should.equal(true)
180
+
181
+ FileUtils.rm('tmp/spec_source.tch')
182
+ FileUtils.rm('tmp/spec_target.tch')
183
+ end
184
+
185
+ it 'should use open with a block will auto close the db correctly' do
186
+
187
+ res = Rufus::Tokyo::Cabinet.open('tmp/spec_source.tch') do |cab|
188
+ 10.times { |i| cab["key #{i}"] = "val #{i}" }
189
+ cab.size.should.equal(10)
190
+ :result
191
+ end
192
+
193
+ res.should.equal(:result)
194
+
195
+ cab = Rufus::Tokyo::Cabinet.new('tmp/spec_source.tch')
196
+ 10.times do |i|
197
+ cab["key #{i}"].should.equal("val #{i}")
198
+ end
199
+ cab.close
200
+
201
+ FileUtils.rm('tmp/spec_source.tch')
202
+ end
203
+
204
+ it 'should use open without a block just like calling new correctly' do
205
+
206
+ cab = Rufus::Tokyo::Cabinet.open('tmp/spec_source.tch')
207
+ 10.times { |i| cab["key #{i}"] = "val #{i}" }
208
+ cab.size.should.equal(10)
209
+ cab.close
210
+
211
+ cab = Rufus::Tokyo::Cabinet.new('tmp/spec_source.tch')
212
+ 10.times do |i|
213
+ cab["key #{i}"].should.equal("val #{i}")
214
+ end
215
+ cab.close
216
+
217
+ FileUtils.rm('tmp/spec_source.tch')
218
+ end
219
+
220
+ it 'should honour the :type parameter' do
221
+
222
+ cab = Rufus::Tokyo::Cabinet.open('tmp/toto.tch')
223
+ cab.clear
224
+ cab['hello'] = 'world'
225
+ cab.close
226
+
227
+ cab = Rufus::Tokyo::Cabinet.open('tmp/toto', :type => :hash)
228
+ cab['hello'].should.equal('world')
229
+ cab.close
230
+
231
+ FileUtils.rm('tmp/toto.tch')
232
+ end
233
+
234
+ it 'should respond to defrag (or not) (TC >= 1.4.21)' do
235
+
236
+ cab = Rufus::Tokyo::Cabinet.open('tmp/toto.tch')
237
+
238
+ if Rufus::Tokyo::CabinetLib.respond_to?(:tctdbsetdfunit)
239
+ cab.defrag
240
+ true.should.equal(true)
241
+ else
242
+ lambda() { cab.defrag }.should.raise(NotImplementedError)
243
+ end
244
+
245
+ cab.close
246
+ end
247
+ end
248
+
249
+ describe Rufus::Tokyo::Cabinet do
250
+
251
+ before do
252
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch')
253
+ @db.clear
254
+ end
255
+ after do
256
+ @db.close
257
+ end
258
+
259
+ behaves_like 'an abstract structure flattening keys and values'
260
+ end
261
+
262
+ describe 'Rufus::Tokyo::Cabinet with a default value' do
263
+
264
+ before do
265
+ @db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_spec.tch', :default => 'Nemo')
266
+ @db.clear
267
+ @db['known'] = 'Ulysse'
268
+ end
269
+ after do
270
+ @db.close
271
+ end
272
+
273
+ behaves_like 'an abstract structure with a default value'
274
+ end
275
+
276
+ describe 'Rufus::Tokyo::Cabinet with a default_proc' do
277
+
278
+ before do
279
+ @db = Rufus::Tokyo::Cabinet.new(
280
+ 'tmp/cabinet_spec.tch',
281
+ :default_proc => lambda { |db, k| "default:#{k}" })
282
+ @db.clear
283
+ @db['known'] = 'Ulysse'
284
+ end
285
+ after do
286
+ @db.close
287
+ end
288
+
289
+ behaves_like 'an abstract structure with a default_proc'
290
+ end
291
+