2 require "ogg/vorbis/tagger"
6 class MainTest < Test::Unit::TestCase
7 OGG_FILE = "test/test.ogg"
11 -c "artist=Bolt Thrower" -c "album=...For Victory" -c "date=1994"
14 f = File.open(OGG_FILE, "w")
15 cmd = "oggenc -q 0 #{tmp.strip} -r -"
17 Open3.popen3(cmd) do |sin, sout, _|
24 end while !tmp.length.zero?
31 FileUtils.rm_f(OGG_FILE)
35 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
36 # make sure the keys are returned in the correct order
37 assert_equal(["artist", "album", "date"], t.comments.keys)
38 assert_equal(["Bolt Thrower", "...For Victory", "1994"],
41 assert_equal(3, t.comments.length)
42 assert_equal(3, t.comments.size)
44 assert_equal("Bolt Thrower", t.comments["artist"])
45 assert_equal("...For Victory", t.comments["album"])
46 assert_equal("1994", t.comments["date"])
50 def test_write_stable_order
51 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
52 assert_equal(3, t.write)
55 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
56 assert_equal(["artist", "album", "date"], t.comments.keys)
60 def test_write_stable_order_change
61 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
62 t.comments["artist"] = "Ballista"
63 assert_equal(3, t.write)
66 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
67 assert_equal(["artist", "album", "date"], t.comments.keys)
72 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
73 t.comments["genre"] = "Death Metal"
74 assert_equal(4, t.write)
77 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
78 assert_equal("Death Metal", t.comments["genre"])
83 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
84 assert_equal("...For Victory", t.comments.delete("album"))
85 assert_nil(t.comments.delete("foo"))
86 assert_equal(2, t.write)
89 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
90 assert_equal(["artist", "date"], t.comments.keys)
95 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
97 assert_equal(0, t.write)
100 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
101 assert(t.comments.empty?)
106 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
107 assert(!t.comments.empty?)
109 t.comments.delete("artist")
110 t.comments.delete("album")
111 t.comments.delete("date")
113 assert_equal(0, t.write)
116 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
117 assert(t.comments.empty?)
122 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
124 "artist" => "Bolt Thrower",
125 "album" => "...For Victory",
130 t.comments.each do |k, v|
139 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
142 t.comments.each_key do |k|
146 assert_equal(["artist", "album", "date"], b)
151 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
154 t.comments.each_value do |v|
158 assert_equal(["Bolt Thrower", "...For Victory", "1994"], b)
163 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
165 {"artist"=>"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"}
167 assert_equal(tmp.strip, t.comments.inspect)
172 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
173 assert(t.comments.has_key?("artist"))
174 assert(!t.comments.has_key?("foo"))
176 assert(t.comments.key?("artist"))
177 assert(t.comments.include?("artist"))
178 assert(t.comments.member?("artist"))
186 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
190 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
194 assert_equal(0, a <=> b)
196 assert_equal(-1, a <=> b)
199 def test_modify_existing_key
200 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
201 assert_raises(TypeError) do
202 t.comments.keys.first.replace("new")
207 def test_modify_added_key
208 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
209 t.comments["Foo"] = "Bar"
211 assert_raises(TypeError) do
212 t.comments.keys.last.replace("new")
219 "artist" => "Ballista",
220 "genre" => "Death Metal",
223 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
224 t.comments.merge!(repl)
226 assert_equal(["artist", "album", "date", "genre"],
228 assert_equal(["Ballista", "...For Victory", "1994",
235 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
236 assert_equal(["artist", "Bolt Thrower"], t.comments.shift)
237 assert_equal(["album", "...For Victory"], t.comments.shift)
238 assert_equal(["date", "1994"], t.comments.shift)
239 assert_equal(nil, t.comments.shift)