X-Git-Url: http://git.code-monkey.de/?p=ruby-vorbistagger.git;a=blobdiff_plain;f=test%2Ftest_main.rb;h=bbc5b0023a2987e31af883c4573dde96f4605dd5;hp=5c6457b8c54a181fff35c680428767f5f9b3f440;hb=bb2a2dcd813175bc4e1dc5ae087795ec18be8fa6;hpb=023eb2d385346cfbcc1ac21d5428e88a042df1f9 diff --git a/test/test_main.rb b/test/test_main.rb index 5c6457b..bbc5b00 100644 --- a/test/test_main.rb +++ b/test/test_main.rb @@ -1,39 +1,21 @@ require "test/unit" require "ogg/vorbis/tagger" require "fileutils" -require "stringio" -require "open3" +require "digest/md5" class MainTest < Test::Unit::TestCase OGG_FILE = "test/test.ogg" def setup - tmp =< "Bolt Thrower", "album" => "...For Victory", @@ -149,7 +145,7 @@ EOF end def test_each_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| b = [] t.comments.each_key do |k| @@ -161,7 +157,7 @@ EOF end def test_each_value - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| b = [] t.comments.each_value do |v| @@ -173,7 +169,7 @@ EOF end def test_inspect - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| tmp=<"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"} EOF @@ -182,9 +178,13 @@ EOF end def test_has_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| assert(t.comments.has_key?("artist")) assert(!t.comments.has_key?("foo")) + + assert(t.comments.key?("artist")) + assert(t.comments.include?("artist")) + assert(t.comments.member?("artist")) end end @@ -192,13 +192,11 @@ EOF a = nil b = nil - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| a = t.comments end - @ogg_buf.seek(0) - - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| b = t.comments end @@ -208,7 +206,7 @@ EOF end def test_modify_existing_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| assert_raises(TypeError) do t.comments.keys.first.replace("new") end @@ -216,7 +214,7 @@ EOF end def test_modify_added_key - Ogg::Vorbis::Tagger.open(@ogg_buf) do |t| + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| t.comments["Foo"] = "Bar" assert_raises(TypeError) do @@ -224,4 +222,34 @@ EOF end end end + + def test_merge + repl = { + "artist" => "Ballista", + "genre" => "Death Metal", + } + + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + t.comments.merge!(repl) + + assert_equal(["artist", "album", "date", "genre"], + t.comments.keys) + assert_equal(["Ballista", "...For Victory", "1994", + "Death Metal"], + t.comments.values) + end + end + + def test_shift + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + assert_equal(["artist", "Bolt Thrower"], t.comments.shift) + assert_equal(["album", "...For Victory"], t.comments.shift) + assert_equal(["date", "1994"], t.comments.shift) + assert_equal(nil, t.comments.shift) + end + end + + def test_close + Ogg::Vorbis::Tagger.new(OGG_FILE).close + end end