test/test_accumulator.rb in tracksperanto-2.2.4 vs test/test_accumulator.rb in tracksperanto-2.3.0

- old
+ new

@@ -15,9 +15,52 @@ a = Tracksperanto::Accumulator.new 50_000.times { a.push("A string" => rand) } assert_equal 50_000, a.size end + def test_accumulator_saves_shitload_of_objs + a = Tracksperanto::Accumulator.new + 4.times { a.push("A \tstring") } + a.each {|e| assert_equal "A \tstring", e } + end + + def test_accumulator_empty + a = Tracksperanto::Accumulator.new + assert a.empty? + a.push(1) + assert !a.empty? + end + + def test_accumulator_supports_nested_iteration + a = Tracksperanto::Accumulator.new + ("A".."Z").each{|e| a << e} + + accumulated = [] + seen_g = false + a.each do | first_level | + if first_level == "G" + seen_g = true + # Force a nested iteration and break it midway + a.each do | second_level | + accumulated.push(second_level) + break if second_level == "E" + end + elsif seen_g + assert_equal "H", first_level + return + end + end + end + + def test_random_access + a = Tracksperanto::Accumulator.new + letters = ("A".."Z").map{|e| "#{e}\r\nWow!"}.to_a + letters.map(&a.method(:push)) + + assert_equal "B\r\nWow!", a[1] + assert_equal "E\r\nWow!", a[4] + end + def test_clear_calls_close_on_buffer io = Tracksperanto::BufferIO.new flexmock(io).should_receive(:close!) flexmock(Tracksperanto::BufferIO).should_receive(:new).once.and_return(io) \ No newline at end of file