<commit_before>require "minitest/spec"
require "minitest/autorun"
require "zopfli"
require "stringio"
require "zlib"

describe Zopfli do
  it "works fine" do
    fixture = fixtures("alice29.txt").read

    Zopfli.deflate(fixture).must_equal(Zopfli.deflate(fixture, format: :zlib))
  end

  it "zlib format works" do
    fixture = fixtures("alice29.txt").read

    deflated = Zopfli.deflate fixture, format: :zlib

    uncompressed = Zlib::Inflate.inflate deflated

    uncompressed.must_equal fixture
  end

  it "gzip format works" do
    fixture = fixtures("alice29.txt").read

    gzipped = Zopfli.deflate fixture, format: :gzip

    uncompressed = nil
    Zlib::GzipReader.wrap(StringIO.new gzipped) { |gz|
      uncompressed = gz.read
    }

    uncompressed.must_equal fixture
  end

  it "deflate format works" do
    fixture = fixtures("alice29.txt").read

    deflate = Zopfli.deflate fixture, format: :deflate
    skip "How to test"
  end

  def fixtures(name)
    File.open(File.join File.dirname(__FILE__), "fixtures", name)
  end
end<commit_msg>tidy up<commit_after>require "minitest/spec"
require "minitest/autorun"
require "zopfli"
require "stringio"
require "zlib"

describe Zopfli do
  it "works fine" do
    fixture = fixtures("alice29.txt").read

    Zopfli.deflate(fixture).must_equal(Zopfli.deflate(fixture, format: :zlib))
  end

  it "zlib format works" do
    fixture = fixtures("alice29.txt").read

    deflated = Zopfli.deflate fixture, format: :zlib

    uncompressed = Zlib::Inflate.inflate deflated

    uncompressed.must_equal fixture
  end

  it "gzip format works" do
    fixture = fixtures("alice29.txt").read

    deflated = Zopfli.deflate fixture, format: :gzip

    uncompressed = Zlib::GzipReader.wrap(StringIO.new(deflated), &:read)

    uncompressed.must_equal fixture
  end

  it "deflate format works" do
    fixture = fixtures("alice29.txt").read

    Zopfli.deflate fixture, format: :deflate

    skip "How to test"
  end

  def fixtures(name)
    File.open(File.join(File.dirname(__FILE__), "fixtures", name))
  end
end
{'fraction_non_alphanumeric': 0.10857973824527388, 'fraction_numerical': 0.007755695588948134, 'mean_word_length': 3.7777777777777777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '636857', 'n_tokens_mistral': 789, 'n_tokens_neox': 735, 'n_words': 170}