test/rbbt/util/test_persistence.rb in rbbt-util-2.1.0 vs test/rbbt/util/test_persistence.rb in rbbt-util-3.0.2
- old
+ new
@@ -8,11 +8,11 @@
TmpFile.with_file do |f|
Persistence.persist("token_file", :Test, :string, :persistence_file => f) do string end
assert File.exists? f
assert_equal string, Open.read(f)
- rm f
+ FileUtils.rm f
end
end
def test_yaml
object = [1,2,2]
@@ -20,11 +20,11 @@
Persistence.persist("token_file", :Test, :yaml, :persistence_file => f) do object end
assert File.exists? f
assert_equal object, YAML.load(File.open(f))
assert_equal YAML.dump(object), Open.read(f)
- rm f
+ FileUtils.rm f
end
end
def test_marshal
object = [1,2,2]
@@ -32,28 +32,28 @@
Persistence.persist("token_file", :Test, :marshal, :persistence_file => f) do object end
assert File.exists? f
assert_equal object, Marshal.load(File.open(f))
assert_equal Marshal.dump(object), Open.read(f)
- rm f
+ FileUtils.rm f
end
end
def test_tsv
object = {:a => 1, :b => 2}
TmpFile.with_file do |f|
Persistence.persist("token_file", :Test, :tsv_extra, :persistence_file => f) do
- [object, {:fields => ["Number"], :key_field => "Letter", :type => :list, :filename => "foo"}]
+ [object, {:fields => ["Number"], :key_field => "Letter", :type => :single, :cast => :to_i, :filename => "foo"}]
end
assert File.exists? f
new, extra = Persistence.persist("token_file", :Test, :tsv_extra, :persistence_file => f)
assert_equal 1, new["a"]
assert_equal "Letter", new.key_field
- rm f
+ FileUtils.rm f
end
end
def test_tsv2
content =<<-EOF
@@ -113,9 +113,44 @@
end
tsv.each do |key,values|
assert_equal values, tsv2[key]
end
end
+ end
+
+ def test_integer
+ content =<<-EOF
+#Id ValueA
+row1 1
+row2 2
+ EOF
+
+ TmpFile.with_file(content) do |filename|
+ tsv = TSV.new(filename, :single, :sep => /\s+/, :cast => :to_i, :persistence => true)
+ assert_equal 1, tsv["row1"]
+ end
+ end
+
+ def test_integer
+ content =<<-EOF
+row1 1 2 3 4 5
+row2 2 4 6 8
+ EOF
+
+ TmpFile.with_file(content) do |filename|
+ tsv = TSV.new(filename, :flat, :sep => /\s+/, :cast => :to_i, :persistence => true)
+ assert_equal [1,2,3,4,5], tsv["row1"]
+ end
+ end
+
+ def test_persist_dir
+ string = Persistence.persist("Test", :Test, :string, :persistence_dir => Rbbt.tmp.test.persistence) do
+ "Test"
+ end
+
+ assert Dir.glob(Rbbt.tmp.test.persistence.find + '*').length == 1
+
+ assert_equal "Test", string
end
end