test/test.rb in daybreak-0.0.4 vs test/test.rb in daybreak-0.1.0
- old
+ new
@@ -75,9 +75,43 @@
@db.empty!
db2 = Daybreak::DB.new DB_PATH
assert_equal nil, db2['19']
end
+ it "should compact subclassed dbs" do
+ class StringDB < Daybreak::DB
+ def serialize(it)
+ it.to_s
+ end
+
+ def parse(it)
+ it
+ end
+ end
+
+ db = StringDB.new 'string.db'
+ db[1] = 'one'
+ db[2] = 'two'
+ db.delete 2
+ db.compact!
+ assert_equal db[1], 'one'
+ assert_equal db[2], nil
+ db.empty!
+ db.close!
+ end
+
+ it "should handle deletions" do
+ @db[1] = 'one'
+ @db[2] = 'two'
+ @db.delete 'two'
+ assert !@db.has_key?('two')
+ assert_equal @db['two'], nil
+
+ db2 = Daybreak::DB.new DB_PATH
+ assert !db2.has_key?('two')
+ assert_equal db2['two'], nil
+ end
+
after do
@db.empty!
@db.close!
end
end