<commit_before># encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')

class Dummy2
  def to_json
    "hawtness"
  end
end

describe "Yajl JSON encoder" do
  FILES = Dir[File.dirname(__FILE__)+'/../../benchmark/subjects/*.json']
  
  FILES.each do |file|
    it "should encode #{File.basename(file)} to an IO" do
      # we don't care about testing the stream subject as it has multiple JSON strings in it
      if File.basename(file) != 'twitter_stream.json'
        input = File.new(File.expand_path(file), 'r')
        io = StringIO.new
        encoder = Yajl::Encoder.new
        hash = Yajl::Parser.parse(input)
        encoder.encode(hash, io)
        io.rewind
        hash2 = Yajl::Parser.parse(io)
        io.close
        input.close
        hash.should == hash2
      end
    end
  end
  
  FILES.each do |file|
    it "should encode #{File.basename(file)} and return a String" do
      # we don't care about testing the stream subject as it has multiple JSON strings in it
      if File.basename(file) != 'twitter_stream.json'
        input = File.new(File.expand_path(file), 'r')
        encoder = Yajl::Encoder.new
        hash = Yajl::Parser.parse(input)
        output = encoder.encode(hash)
        hash2 = Yajl::Parser.parse(output)
        input.close
        hash.should == hash2
      end
    end
  end
  
  FILES.each do |file|
    it "should encode #{File.basename(file)} call the passed block, passing it a String" do
      # we don't care about testing the stream subject as it has multiple JSON strings in it
      if File.basename(file) != 'twitter_stream.json'
        input = File.new(File.expand_path(file), 'r')
        encoder = Yajl::Encoder.new
        hash = Yajl::Parser.parse(input)
        output = ''
        encoder.encode(hash) do |json_str|
          output = json_str
        end
        hash2 = Yajl::Parser.parse(output)
        input.close<commit_msg>fixing encoding test for new streaming encode support<commit_after># encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')

class Dummy2
  def to_json
    "hawtness"
  end
end

describe "Yajl JSON encoder" do
  FILES = Dir[File.dirname(__FILE__)+'/../../benchmark/subjects/*.json']
  
  FILES.each do |file|
    it "should encode #{File.basename(file)} to an IO" do
      # we don't care about testing the stream subject as it has multiple JSON strings in it
      if File.basename(file) != 'twitter_stream.json'
        input = File.new(File.expand_path(file), 'r')
        io = StringIO.new
        encoder = Yajl::Encoder.new
        hash = Yajl::Parser.parse(input)
        encoder.encode(hash, io)
        io.rewind
        hash2 = Yajl::Parser.parse(io)
        io.close
        input.close
        hash.should == hash2
      end
    end
  end
  
  FILES.each do |file|
    it "should encode #{File.basename(file)} and return a String" do
      # we don't care about testing the stream subject as it has multiple JSON strings in it
      if File.basename(file) != 'twitter_stream.json'
        input = File.new(File.expand_path(file), 'r')
        encoder = Yajl::Encoder.new
        hash = Yajl::Parser.parse(input)
        output = encoder.encode(hash)
        hash2 = Yajl::Parser.parse(output)
        input.close
        hash.should == hash2
      end
    end
  end
  
  FILES.each do |file|
    it "should encode #{File.basename(file)} call the passed block, passing it a String" do
      # we don't care about testing the stream subject as it has multiple JSON strings in it
      if File.basename(file) != 'twitter_stream.json'
        input = File.new(File.expand_path(file), 'r')
        encoder = Yajl::Encoder.new
        hash = Yajl::Parser.parse(input)
        output = ''
        encoder.encode(hash) do |json_str|
          output << json_str
        end
        hash2 = Yajl::Parser.parse(output)
        input.close
{'fraction_non_alphanumeric': 0.11088348271446863, 'fraction_numerical': 0.003585147247119078, 'mean_word_length': 2.4444444444444446, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2861697', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1210, 'n_words': 348}