<commit_before>require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/marshal_data'

describe "Marshal::load" do
  it "loads a extended_struct having fields with same objects" do
    s = 'hi'
    obj = Struct.new("Ure2", :a, :b).new.extend(Meths)
    obj.a = [:a, s]; obj.b = [:Meths, s]

    Marshal.load("\004\be:\nMethsS:\021Struct::Ure2\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a").should ==
      obj
  end

  it "loads a string having ivar with ref to self" do
    obj = 'hi'
    obj.instance_variable_set(:@self, obj)
    Marshal.load("\004\bI\"\ahi\006:\n@self@\000").should == obj
  end

  it "loads an extended_user_hash with a parameter to initialize" do
    obj = UserHashInitParams.new(:abc).extend(Meths)

    new_obj = Marshal.load "\004\bIe:\nMethsC:\027UserHashInitParams{\000\006:\a@a:\babc"

    new_obj.should == obj
    new_obj_metaclass_ancestors = class << new_obj; ancestors; end
    new_obj_metaclass_ancestors.first.should == UserHashInitParams<commit_msg>Tweak new Marshal spec to pass on MatzRuby<commit_after>require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/marshal_data'

describe "Marshal::load" do
  it "loads a extended_struct having fields with same objects" do
    s = 'hi'
    obj = Struct.new("Ure2", :a, :b).new.extend(Meths)
    obj.a = [:a, s]; obj.b = [:Meths, s]

    Marshal.load("\004\be:\nMethsS:\021Struct::Ure2\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a").should ==
      obj
  end

  it "loads a string having ivar with ref to self" do
    obj = 'hi'
    obj.instance_variable_set(:@self, obj)
    Marshal.load("\004\bI\"\ahi\006:\n@self@\000").should == obj
  end

  it "loads an extended_user_hash with a parameter to initialize" do
    obj = UserHashInitParams.new(:abc).extend(Meths)

    new_obj = Marshal.load "\004\bIe:\nMethsC:\027UserHashInitParams{\000\006:\a@a:\babc"

    new_obj.should == obj
    new_obj_metaclass_ancestors = class << new_obj; ancestors; end
    new_obj_metaclass_ancestors[0].should == Meths
    new_obj_metaclass_ancestors[1].should == UserHashInitParams
{'fraction_non_alphanumeric': 0.157919621749409, 'fraction_numerical': 0.03687943262411347, 'mean_word_length': 3.733780760626398, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4655471', 'n_tokens_mistral': 842, 'n_tokens_neox': 774, 'n_words': 160}