2 require "ogg/vorbis/tagger"
5 class MainTest < Test::Unit::TestCase
6 OGG_FILE = "test/test.ogg"
9 FileUtils.cp("test/sample.ogg", OGG_FILE)
13 FileUtils.rm_f(OGG_FILE)
17 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
18 # make sure the keys are returned in the correct order
19 assert_equal(["artist", "album", "date"], t.comments.keys)
20 assert_equal(["Bolt Thrower", "...For Victory", "1994"],
23 assert_equal(3, t.comments.length)
24 assert_equal(3, t.comments.size)
26 assert_equal("Bolt Thrower", t.comments["artist"])
27 assert_equal("...For Victory", t.comments["album"])
28 assert_equal("1994", t.comments["date"])
32 def test_write_stable_order
33 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
34 assert_equal(3, t.write)
37 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
38 assert_equal(["artist", "album", "date"], t.comments.keys)
42 def test_write_stable_order_change
43 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
44 t.comments["artist"] = "Ballista"
45 assert_equal(3, t.write)
48 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
49 assert_equal(["artist", "album", "date"], t.comments.keys)
54 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
55 t.comments["genre"] = "Death Metal"
56 assert_equal(4, t.write)
59 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
60 assert_equal("Death Metal", t.comments["genre"])
65 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
66 assert_equal("...For Victory", t.comments.delete("album"))
67 assert_nil(t.comments.delete("foo"))
68 assert_equal(2, t.write)
71 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
72 assert_equal(["artist", "date"], t.comments.keys)
77 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
79 assert_equal(0, t.write)
82 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
83 assert(t.comments.empty?)
88 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
89 assert(!t.comments.empty?)
91 t.comments.delete("artist")
92 t.comments.delete("album")
93 t.comments.delete("date")
95 assert_equal(0, t.write)
98 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
99 assert(t.comments.empty?)
104 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
106 "artist" => "Bolt Thrower",
107 "album" => "...For Victory",
112 t.comments.each do |k, v|
121 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
124 t.comments.each_key do |k|
128 assert_equal(["artist", "album", "date"], b)
133 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
136 t.comments.each_value do |v|
140 assert_equal(["Bolt Thrower", "...For Victory", "1994"], b)
145 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
147 {"artist"=>"Bolt Thrower", "album"=>"...For Victory", "date"=>"1994"}
149 assert_equal(tmp.strip, t.comments.inspect)
154 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
155 assert(t.comments.has_key?("artist"))
156 assert(!t.comments.has_key?("foo"))
158 assert(t.comments.key?("artist"))
159 assert(t.comments.include?("artist"))
160 assert(t.comments.member?("artist"))
168 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
172 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
176 assert_equal(0, a <=> b)
178 assert_equal(-1, a <=> b)
181 def test_modify_existing_key
182 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
183 assert_raises(TypeError) do
184 t.comments.keys.first.replace("new")
189 def test_modify_added_key
190 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
191 t.comments["Foo"] = "Bar"
193 assert_raises(TypeError) do
194 t.comments.keys.last.replace("new")
201 "artist" => "Ballista",
202 "genre" => "Death Metal",
205 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
206 t.comments.merge!(repl)
208 assert_equal(["artist", "album", "date", "genre"],
210 assert_equal(["Ballista", "...For Victory", "1994",
217 Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
218 assert_equal(["artist", "Bolt Thrower"], t.comments.shift)
219 assert_equal(["album", "...For Victory"], t.comments.shift)
220 assert_equal(["date", "1994"], t.comments.shift)
221 assert_equal(nil, t.comments.shift)
226 Ogg::Vorbis::Tagger.new(OGG_FILE).close