<commit_before># This started life as yajl-ruby's json_gem_compatibility/compatibility_spec.rb file.
# Kinda looks like they stole it from the JSON gem.  I updated the syntax a lot.

require 'spec_helper'

class Dummy; end

describe "JSON Gem Compat API" do

  # Magic to make the before loading tests actually run before loading
  RSpec.configure do |config|
    config.order_groups_and_examples do |list|
      list.sort_by { |item| item.description }
    end
  end

  context "A: before loading the compat library" do
    it "should not mixin #to_json on random objects" do
      d = Dummy.new
      expect(d.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json to a string" do
      expect("".respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json to a fixnum" do
      expect(1.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a float" do
      expect("1.5".to_f.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on an array" do
      expect([].respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a hash" do
      expect({:foo => "bar"}.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a trueclass" do
      expect(true.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a falseclass" do
      expect(false.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a nilclass" do
      expect(nil.respond_to?(:to_json)).to be_false
    end
  end

  context "B: when in compat mode" do

    before(:all) do
      require 'ffi_yajl/json_gem'
    end

    it "should define JSON class" do
      expect(defined?(JSON)).to be_true
    end

    it "should implement JSON#parse" do
      expect(JSON.respond_to?(:parse)).to be_true
    end

    it "should implement JSON#generate" do
      expect(JSON.respond_to?(:generate)).to be_true
    end

    it "should implement JSON#pretty_generate" do
      expect(JSON.respond_to?(:pretty_generate)).to be_true
    end

    it "should implement JSON#load" do
      expect(JSON.respond_to?(:load)).to be_true
    end

    it "should implement JSON#dump" do
      expect(JSON.respond_to?(:dump)).to be_true
    end

    context "when setting symbolize_keys via JSON.default_options" do
      before(:all) { saved_default = JSON.default_options[:symbolize_keys] }
      after(:all) { JSON.default_options[:symbolize_keys] = saved_default }

      it "the default behavior should be to not symbolize keys" do
        expect(JSON.parse('{"foo": 1234}')).to eq({"foo" => 1234})
      end

      it "changing the default_options should change the behavior to true" do
        pending("implement symbolize keys")
        JSON.default_options[:symbolize_keys] = true
        expect(JSON.parse('{"foo": 1234}')).to eq({:foo => 1234})
      end
    end

    context "when setting symbolize_names via JSON.default_options" do
      before(:all) { saved_default = JSON.default_options[:symbolize_names] }
      after(:all) { JSON.default_options[:symbolize_names] = saved_default }

      it "the default behavior should be to not symbolize keys" do<commit_msg>fix variable scope<commit_after># This started life as yajl-ruby's json_gem_compatibility/compatibility_spec.rb file.
# Kinda looks like they stole it from the JSON gem.  I updated the syntax a lot.

require 'spec_helper'

class Dummy; end

describe "JSON Gem Compat API" do

  # Magic to make the before loading tests actually run before loading
  RSpec.configure do |config|
    config.order_groups_and_examples do |list|
      list.sort_by { |item| item.description }
    end
  end

  context "A: before loading the compat library" do
    it "should not mixin #to_json on random objects" do
      d = Dummy.new
      expect(d.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json to a string" do
      expect("".respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json to a fixnum" do
      expect(1.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a float" do
      expect("1.5".to_f.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on an array" do
      expect([].respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a hash" do
      expect({:foo => "bar"}.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a trueclass" do
      expect(true.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a falseclass" do
      expect(false.respond_to?(:to_json)).to be_false
    end

    it "should not mixin #to_json on a nilclass" do
      expect(nil.respond_to?(:to_json)).to be_false
    end
  end

  context "B: when in compat mode" do

    before(:all) do
      require 'ffi_yajl/json_gem'
    end

    it "should define JSON class" do
      expect(defined?(JSON)).to be_true
    end

    it "should implement JSON#parse" do
      expect(JSON.respond_to?(:parse)).to be_true
    end

    it "should implement JSON#generate" do
      expect(JSON.respond_to?(:generate)).to be_true
    end

    it "should implement JSON#pretty_generate" do
      expect(JSON.respond_to?(:pretty_generate)).to be_true
    end

    it "should implement JSON#load" do
      expect(JSON.respond_to?(:load)).to be_true
    end

    it "should implement JSON#dump" do
      expect(JSON.respond_to?(:dump)).to be_true
    end

    context "when setting symbolize_keys via JSON.default_options" do
      before(:all) { @saved_default = JSON.default_options[:symbolize_keys] }
      after(:all) { JSON.default_options[:symbolize_keys] = @saved_default }

      it "the default behavior should be to not symbolize keys" do
        expect(JSON.parse('{"foo": 1234}')).to eq({"foo" => 1234})
      end

      it "changing the default_options should change the behavior to true" do
        pending("implement symbolize keys")
        JSON.default_options[:symbolize_keys] = true
        expect(JSON.parse('{"foo": 1234}')).to eq({:foo => 1234})
      end
    end

    context "when setting symbolize_names via JSON.default_options" do
      before(:all) { saved_default = JSON.default_options[:symbolize_names] }
      after(:all) { JSON.default_options[:symbolize_names] = saved_default }

      it "the default behavior should be to not symbolize keys" do
{'fraction_non_alphanumeric': 0.10073060780351313, 'fraction_numerical': 0.005907041815638116, 'mean_word_length': 3.1806367771280053, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 9, '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': '3492974', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2030, 'n_words': 627}