<commit_before>require File.dirname(__FILE__) + '/../../../spec_helper'
require 'stringio'
require 'zlib'

describe "GzipReader#rewind" do

  before :each do
    @data = '<KEY>'
    @zip = "\037\213\b\000,\334\321G\000\00334261MLJNI\005\000\235\005\000$\n\000\000\000"
    @io = StringIO.new @zip
  end

  it "resets the position of the stream pointer" do
    gz = Zlib::GzipReader.new @io
    gz.read
    gz.pos.should == @data.length

    gz.rewind
    gz.pos.should == 0
  end

  it "resets the position of the stream pointer to data previously read" do
    gz = Zlib::GzipReader.new @io
    first_read = gz.read
    gz.rewind
    first_read.should == gz.read
  end

  it "invokes seek method on the associated IO object" do
    # first, prepare the mock object:
    (obj = mock("io")).should_receive(:get_io).any_number_of_times.and_return(@io)
    def obj.read(args); get_io.read(args); end
    obj.should_receive(:seek).and_return(0)

    gz = Zlib::GzipReader.new(obj)
    gz.rewind()
    gz.pos.should == 0
  end
end<commit_msg>Tweaks to GzipReader#rewind specs.<commit_after>require File.dirname(__FILE__) + '/../../../spec_helper'
require 'stringio'
require 'zlib'

describe "GzipReader#rewind" do

  before :each do
    @data = '12345abcde'
    @zip = "\037\213\b\000,\334\321G\000\00334261MLJNI\005\000\235\005\000$\n\000\000\000"
    @io = StringIO.new @zip
    ScratchPad.clear
  end

  it "resets the position of the stream pointer" do
    gz = Zlib::GzipReader.new @io
    gz.read
    gz.pos.should == @data.length

    gz.rewind
    gz.pos.should == 0
    gz.lineno.should == 0
  end

  it "resets the position of the stream pointer to data previously read" do
    gz = Zlib::GzipReader.new @io
    first_read = gz.read
    gz.rewind
    first_read.should == gz.read
  end

  it "invokes seek method on the associated IO object" do
    # first, prepare the mock object:
    (obj = mock("io")).should_receive(:get_io).any_number_of_times.and_return(@io)
    def obj.read(args); get_io.read(args); end
    def obj.seek(pos, whence = 0)
      ScratchPad.record :seek
      get_io.seek(pos, whence)
    end

    gz = Zlib::GzipReader.new(obj)
    gz.rewind()

    ScratchPad.recorded.should == :seek
    gz.pos.should == 0
    gz.read.should == "12345abcde"
  end
end
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.05131578947368421, 'mean_word_length': 2.953206239168111, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6598338', 'n_tokens_mistral': 951, 'n_tokens_neox': 826, 'n_words': 199}