<commit_before>require 'std/core_ext/object'
require 'std/core_ext/array'
require 'std/core_ext/hash'
require 'std/core_ext/string'
require 'std/core_ext/nil_class'
require 'std/set'

class MyTestObject
  class Point
    attr_accessor :x
    attr_accessor :y

    def initialize(x = 0, y = 0)
      @x = x
      @y = y
    end
  end

  attr_accessor :position

  def initialize
    @position = Point.new
  end
end

describe Object do
  context '#safe_dup' do
    it 'should safely duplicate an object' do
      # numbers are not normally dup-able, so this should touch the rescue branch
      expect(1.safe_dup).to eq(1)
      expect('Foobar'.safe_dup).to eq('Foobar')
    end
  end

  context '#blank?' do
    it 'determines if an object is blank' do
      obj = Object.new
      expect(obj).not_to be_blank
      expect(nil).to be_blank
      expect([]).to be_blank
      expect({}).to be_blank
      expect(Moon::Set.new).to be_blank
      expect('').to be_blank
      expect('     ').to be_blank
      expect("\n \t \r").to be_blank
    end
  end

  context '#present?' do
    it 'determines if an object is present' do
      obj = Object.new
      expect(obj).to be_present
      expect(nil).not_to be_present
      expect([]).not_to be_present
      expect({}).not_to be_present
      expect(Moon::Set.new).not_to be_present
      expect('').not_to be_present
      expect('     ').not_to be_present
      expect("\n \t \r").not_to be_present
    end
  end

  context '#presence' do
    it 'returns the presence of an object' do
      obj = Object.new
      expect(obj.presence).to eq(obj)
      expect([].presence).to eq(nil)
      expect({}.presence).to eq(nil)
      expect(Moon::Set.new.presence).to eq(nil)
      expect(''.presence).to eq(nil)
      expect([1, 2].presence).to eq([1, 2])
      expect({ a: 1 }.presence).to eq(a: 1)
      expect('a'.presence).to eq('a')
    end
  end

  context '#try' do
    it 'should invoke a method on the object' do
      obj = Object.new
      expect(obj.try(:to_s)).to eq(obj.to_s)
      expect(obj.try(:something_that_doesnt_exist)).to eq(nil)
    end
  end

  context '#dotsend' do
    it 'should recursively call into an object' do
      obj = MyTestObject.new
      obj.position.x = 12
      obj.position.y = 2
      # first with a symbol, for regular sends
      expect(obj.dotsend(:position)).to equal(obj.position)
      # then with a dot notation string
      expect(obj.dotsend('position.x')).to eq(obj.position.x)<commit_msg>spec: std/spec: Updated Object spec<commit_after>require 'std/core_ext/object'
require 'std/core_ext/array'
require 'std/core_ext/hash'
require 'std/core_ext/string'
require 'std/core_ext/nil_class'
require 'std/set'

module Fixtures
  class MyTestObject
    class Point
      attr_accessor :x
      attr_accessor :y

      def initialize(x = 0, y = 0)
        @x = x
        @y = y
      end
    end

    attr_accessor :position

    def initialize
      @position = Point.new
    end
  end
end

describe Object do
  context '#safe_dup' do
    it 'should safely duplicate an object' do
      # numbers are not normally dup-able, so this should touch the rescue branch
      expect(1.safe_dup).to eq(1)
      expect('Foobar'.safe_dup).to eq('Foobar')
    end
  end

  context '#blank?' do
    it 'determines if an object is blank' do
      obj = Object.new
      expect(obj).not_to be_blank
      expect(nil).to be_blank
      expect([]).to be_blank
      expect({}).to be_blank
      expect(Moon::Set.new).to be_blank
      expect('').to be_blank
      expect('     ').to be_blank
      expect("\n \t \r").to be_blank
    end
  end

  context '#present?' do
    it 'determines if an object is present' do
      obj = Object.new
      expect(obj).to be_present
      expect(nil).not_to be_present
      expect([]).not_to be_present
      expect({}).not_to be_present
      expect(Moon::Set.new).not_to be_present
      expect('').not_to be_present
      expect('     ').not_to be_present
      expect("\n \t \r").not_to be_present
    end
  end

  context '#presence' do
    it 'returns the presence of an object' do
      obj = Object.new
      expect(obj.presence).to eq(obj)
      expect([].presence).to eq(nil)
      expect({}.presence).to eq(nil)
      expect(Moon::Set.new.presence).to eq(nil)
      expect(''.presence).to eq(nil)
      expect([1, 2].presence).to eq([1, 2])
      expect({ a: 1 }.presence).to eq(a: 1)
      expect('a'.presence).to eq('a')
    end
  end

  context '#try' do
    it 'should invoke a method on the object' do
      obj = Object.new
      expect(obj.try(:to_s)).to eq(obj.to_s)
      expect(obj.try(:something_that_doesnt_exist)).to eq(nil)
    end
  end

  context '#dotsend' do
    it 'should recursively call into an object' do
      obj = Fixtures::MyTestObject.new
      obj.position.x = 12
      obj.position.y = 2
      # first with a symbol, for regular sends
      expect(obj.dotsend(:position)).to equal(obj.position)
      # then with a dot notation string
      expect(obj.dotsend('position.x')).to eq(obj.position.x)
{'fraction_non_alphanumeric': 0.12133808392715756, 'fraction_numerical': 0.005146476642913698, 'mean_word_length': 2.5710247349823323, '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': '6880210', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1676, 'n_words': 464}