<commit_before># encoding: utf-8

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'ascii85'

describe Ascii85 do

  before( :all ) do
    @string_has_encoding = "String".methods.include?(:encoding)
  end

  TEST_CASES = {

    ""          => "",
    " "         => "<~+9~>",

    "\0" * 1    => "<~!!~>",
    "\0" * 2    => "<~!!!~>",
    "\0" * 3    => "<~!!!!~>",
    "\0" * 4    => "<~z~>",
    "\0" * 5    => "<~z!!~>",
    "A\0\0\0\0" => "<~5l^lb!!~>", # No z-abbreviation!

    "A"         => "<~5l~>",
    "AB"        => "<~5sb~>",
    "ABC"       => "<~5sdp~>",
    "ABCD"      => "<~5sdq,~>",
    "ABCDE"     => "<~5sdq,70~>",
    "ABCDEF"    => "<~5sdq,77I~>",
    "ABCDEFG"   => "<~5sdq,77Kc~>",
    "ABCDEFGH"  => "<~5sdq,77Kd<~>",
    "ABCDEFGHI" => "<~5sdq,77Kd<8H~>",
    "Ascii85"   => "<~6$$OMBfIs~>",

    'Antidisestablishmentarianism' => '<~6#LdYA8-*rF*(i"Ch[s(D.RU,@<-\'jDJ=0/~>',

    # Dōmo arigatō, Mr. Roboto (according to Wikipedia)
    'どうもありがとうミスターロボット' =>
        "<~j+42iJVN3:K&_E6j+<0KJW/W?W8iG`j+EuaK\"9on^Z0sZj+FJoK:LtSKB%T?~>",

    [Math::PI].pack('G') => "<~5RAV2<(&;T~>",
    [Math::E].pack('G')  => "<~5R\"n0M\\K6,~>"
  }

  it "#decode should be the inverse of #encode" do

    # Generate a random string
    test_str = ""
    (1 + rand(255)).times do
      test_str += rand(256).chr
    end

    encoded = Ascii85::encode(test_str)
    decoded = Ascii85::decode(encoded)

    decoded.should == test_str
  end

  describe "#encode" do

    it "should encode all specified test-cases correctly" do
      TEST_CASES.each_pair do |input, encoded|
        Ascii85::encode(input).should == encoded
      end
    end

    it "[Ruby 1.9] should encode Strings in different encodings correctly" do
      if @string_has_encoding
        input_EUC_JP  = 'どうもありがとうミスターロボット'.encode('EUC-JP')
        input_Ascii85 = input_EUC_JP.force_encoding('ASCII-8BIT')

        Ascii85::encode(input_EUC_JP).should == Ascii85::encode(input_Ascii85)
      end
    end

    it "should produce output lines no longer than specified" do
      test_str = '0123456789' * 30

      #
      # No wrap
      #
      Ascii85::encode(test_str, false).count("\n").should == 0

      #
      # x characters per line, except for the last one
      #
      x = 2 + rand(255) # < test_str.length
      encoded = Ascii85::encode(test_str, x)

      # Determine the length of all lines
      count_arr = []
      encoded.each_line do |line|
        count_arr << line.chomp.length
      end

      # The last line is allowed to be shorter than x, so remove it
      count_arr.pop if count_arr.last <= x

      # If the end-marker is on a line of its own, the next-to-last line is<commit_msg>spec: Fix misleading variable name<commit_after># encoding: utf-8

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'ascii85'

describe Ascii85 do

  before( :all ) do
    @string_has_encoding = "String".methods.include?(:encoding)
  end

  TEST_CASES = {

    ""          => "",
    " "         => "<~+9~>",

    "\0" * 1    => "<~!!~>",
    "\0" * 2    => "<~!!!~>",
    "\0" * 3    => "<~!!!!~>",
    "\0" * 4    => "<~z~>",
    "\0" * 5    => "<~z!!~>",
    "A\0\0\0\0" => "<~5l^lb!!~>", # No z-abbreviation!

    "A"         => "<~5l~>",
    "AB"        => "<~5sb~>",
    "ABC"       => "<~5sdp~>",
    "ABCD"      => "<~5sdq,~>",
    "ABCDE"     => "<~5sdq,70~>",
    "ABCDEF"    => "<~5sdq,77I~>",
    "ABCDEFG"   => "<~5sdq,77Kc~>",
    "ABCDEFGH"  => "<~5sdq,77Kd<~>",
    "ABCDEFGHI" => "<~5sdq,77Kd<8H~>",
    "Ascii85"   => "<~6$$OMBfIs~>",

    'Antidisestablishmentarianism' => '<~6#LdYA8-*rF*(i"Ch[s(D.RU,@<-\'jDJ=0/~>',

    # Dōmo arigatō, Mr. Roboto (according to Wikipedia)
    'どうもありがとうミスターロボット' =>
        "<~j+42iJVN3:K&_E6j+<0KJW/W?W8iG`j+EuaK\"9on^Z0sZj+FJoK:LtSKB%T?~>",

    [Math::PI].pack('G') => "<~5RAV2<(&;T~>",
    [Math::E].pack('G')  => "<~5R\"n0M\\K6,~>"
  }

  it "#decode should be the inverse of #encode" do

    # Generate a random string
    test_str = ""
    (1 + rand(255)).times do
      test_str += rand(256).chr
    end

    encoded = Ascii85::encode(test_str)
    decoded = Ascii85::decode(encoded)

    decoded.should == test_str
  end

  describe "#encode" do

    it "should encode all specified test-cases correctly" do
      TEST_CASES.each_pair do |input, encoded|
        Ascii85::encode(input).should == encoded
      end
    end

    it "[Ruby 1.9] should encode Strings in different encodings correctly" do
      if @string_has_encoding
        input_EUC_JP = 'どうもありがとうミスターロボット'.encode('EUC-JP')
        input_binary = input_EUC_JP.force_encoding('ASCII-8BIT')

        Ascii85::encode(input_EUC_JP).should == Ascii85::encode(input_binary)
      end
    end

    it "should produce output lines no longer than specified" do
      test_str = '0123456789' * 30

      #
      # No wrap
      #
      Ascii85::encode(test_str, false).count("\n").should == 0

      #
      # x characters per line, except for the last one
      #
      x = 2 + rand(255) # < test_str.length
      encoded = Ascii85::encode(test_str, x)

      # Determine the length of all lines
      count_arr = []
      encoded.each_line do |line|
        count_arr << line.chomp.length
      end

      # The last line is allowed to be shorter than x, so remove it
      count_arr.pop if count_arr.last <= x

      # If the end-marker is on a line of its own, the next-to-last line is
{'fraction_non_alphanumeric': 0.19348306332842416, 'fraction_numerical': 0.03792341678939617, 'mean_word_length': 2.478233034571063, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 89, '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': '1030460', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2126, 'n_words': 433}