X-Git-Url: http://git.code-monkey.de/?p=ruby-vorbistagger.git;a=blobdiff_plain;f=test%2Ftest_main.rb;h=bbc5b0023a2987e31af883c4573dde96f4605dd5;hp=da3621cc3ef3c159164ea2d811775a6ac9bca0dd;hb=bb2a2dcd813175bc4e1dc5ae087795ec18be8fa6;hpb=310e91e26bebf168b6081e91da123b4a8cfb9b67 diff --git a/test/test_main.rb b/test/test_main.rb index da3621c..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 @@ -206,4 +204,52 @@ EOF b["artist"] = "Foo" assert_equal(-1, a <=> b) end + + def test_modify_existing_key + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + assert_raises(TypeError) do + t.comments.keys.first.replace("new") + end + end + end + + def test_modify_added_key + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + t.comments["Foo"] = "Bar" + + assert_raises(TypeError) do + t.comments.keys.last.replace("new") + 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