<commit_before>require "minitest/autorun"
require "minitest/pride"
require "attr_extras"

class Example
  attr_initialize :foo, :bar
  attr_private :foo, :bar
end

class PattrExample
  pattr_initialize :foo, :bar
end

class QueryExample
  attr_id_query :baz?, :boink?
  attr_query :flurp?
  attr_accessor :baz_id, :flurp
end

class MethodObjectExample
  method_object :fooable?,
    :foo

  def fooable?
    foo
  end
end

class ExampleWithHash
  pattr_initialize :foo, [:bar, :baz]
end

describe Object, ".method_object" do
  it "creates a class method that instantiates and runs that instance method" do
    assert MethodObjectExample.fooable?(true)
    refute MethodObjectExample.fooable?(false)
  end
end

describe Object, ".attr_initialize" do
  it "creates an initializer setting those instance variables" do
    example = Example.new("Foo", "Bar")
    example.instance_variable_get("@foo").must_equal "Foo"
    example.instance_variable_get("@bar").must_equal "Bar"
  end

  it "requires all arguments" do
    lambda { Example.new("Foo") }.must_raise ArgumentError
  end

  it "can set ivars from a hash" do
    example = ExampleWithHash.new("Foo", :bar => "Bar", :baz => "Baz")
    example.instance_variable_get("@foo").must_equal "Foo"
    example.instance_variable_get("@bar").must_equal "Bar"
    example.instance_variable_get("@baz").must_equal "Baz"
  end
end

describe Object, ".attr_private" do
  it "creates private readers" do
    example = Example.new("Foo", "Bar")
    example.send(:foo).must_equal "Foo"
    example.send(:bar).must_equal "Bar"
    lambda { example.foo }.must_raise NoMethodError
  end
end

describe Object, ".pattr_initialize" do
  it "creates both initializer and private readers" do
    example = PattrExample.new("Foo", "Bar")
    example.send(:foo).must_equal "Foo"
  end

  it "works with hash ivars" do
    example = ExampleWithHash.new("Foo", :bar => "Bar")
    example.send(:bar).must_equal "Bar"
  end
end

describe Object, ".attr_id_query" do
  it "creates id query methods" do
    example = QueryExample.new
    refute example.baz?
    example.baz_id = 123
    assert example.baz?
  end

  it "requires a trailing questionmark" do
    lambda { Object.attr_id_query(:foo) }.must_raise RuntimeError
  end
end

describe Object, ".attr_query" do
  it "creates attribute query methods" do
    example = QueryExample.new
    refute example.flurp?
    example.flurp = "!"
    assert example.flurp?
  end

  it "requires a trailing questionmark" do
    lambda { Object.attr_query(:foo) }.must_raise RuntimeError
  end
end
<commit_msg>Define minimal classes within each spec, not globally at top.<commit_after>require "minitest/autorun"
require "minitest/pride"
require "attr_extras"

describe Object, ".method_object" do
  let(:klass) do
    Class.new do
      method_object :fooable?,
        :foo

      def fooable?
        foo
      end
    end
  end

  it "creates a class method that instantiates and runs that instance method" do
    assert klass.fooable?(true)
    refute klass.fooable?(false)
  end
end

describe Object, ".attr_initialize" do
  let(:klass) do
    Class.new do
      attr_initialize :foo, :bar
    end
  end

  it "creates an initializer setting those instance variables" do
    example = klass.new("Foo", "Bar")
    example.instance_variable_get("@foo").must_equal "Foo"
    example.instance_variable_get("@bar").must_equal "Bar"
  end

  it "requires all arguments" do
    lambda { klass.new("Foo") }.must_raise ArgumentError
  end

  it "can set ivars from a hash" do
    klass = Class.new do
      pattr_initialize :foo, [:bar, :baz]
    end

    example = klass.new("Foo", :bar => "Bar", :baz => "Baz")
    example.instance_variable_get("@foo").must_equal "Foo"
    example.instance_variable_get("@bar").must_equal "Bar"
    example.instance_variable_get("@baz").must_equal "Baz"
  end
end

describe Object, ".attr_private" do
  let(:klass) do
    Class.new do
      attr_private :foo, :bar
    end
  end

  it "creates private readers" do
    example = klass.new
    example.instance_variable_set("@foo", "Foo")
    example.instance_variable_set("@bar", "Bar")
    example.send(:foo).must_equal "Foo"
    example.send(:bar).must_equal "Bar"
    lambda { example.foo }.must_raise NoMethodError
  end
end

describe Object, ".pattr_initialize" do
  it "creates both initializer and private readers" do
    klass = Class.new do
      pattr_initialize :foo, :bar
    end

    example = klass.new("Foo", "Bar")
    example.send(:foo).must_equal "Foo"
  end

  it "works with hash ivars" do
    klass = Class.new do
      pattr_initialize :foo, [:bar, :baz]
    end

    example = klass.new("Foo", :bar => "Bar")
    example.send(:bar).must_equal "Bar"
  end
end

describe Object, ".attr_id_query" do
  it "creates id query methods" do
    klass = Class.new do
      attr_id_query :baz?, :boink?
      attr_accessor :baz_id
    end

    example = klass.new
    refute example.baz?

    example.baz_id = 123
    assert example.baz?
  end

  it "requires a trailing questionmark" do
    lambda { Object.attr_id_query(:foo) }.must_raise RuntimeError
  end
end

describe Object, ".attr_query" do
  it "creates attribute query methods" do
    klass = Class.new do
      attr_query :flurp?
      attr_accessor :flurp
    end

    example = klass.new
    refute example.flurp?
    example.flurp = "!"
    assert example.flurp?
  end

  it "requires a trailing questionmark" do
    lambda { Object.attr_query(:foo) }.must_raise RuntimeError
  end
end

{'fraction_non_alphanumeric': 0.1058652623933176, 'fraction_numerical': 0.0010895224260032686, 'mean_word_length': 3.5184577522559475, 'pattern_counts': {'":': 0, '<': 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': '7286534', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1812, 'n_words': 520}