<commit_before>require File.expand_path("../test_helper", __FILE__)

class ClassTest < Test::Unit::TestCase

  context "A class" do
    setup do
      class A
      end
      class B
        include NewClass
      end
    end

    context "when having included NewClass" do
      should "respond to new_class" do
        assert !A.respond_to?(:new_class)
        assert B.respond_to?(:new_class)
      end

      context "and having a superclass" do
        setup do
          class Greeter
            @@translations = {}
            def self.translate(language, translation)
              @@translations[language.to_sym] = translation
            end
            def self.translation(language)
              @@translations[language.to_sym]
            end
            translate :english, "Hi, I am a {kind}"
            def greet(language = :english)
              self.class.translation(language).gsub("{kind}", self.class.name.match(/[^:]+$/).to_s)
            end
          end
          class C < Greeter
            include NewClass
            when_defined do
              (var(:translations) || {}).each do |language, translation|
                translate language, translation
              end
            end
          end
        end

        should "behave as expected" do
          assert_equal "Hi, I am a C", C.new.greet
        end

        should "be able to return a new class" do
          assert_equal Class, C.new_class.class
        end

        context "the new class" do
          should "have @name and @variables defined" do
            assert C.new_class.instance_variable_defined?(:@name)
            assert_equal(C.name, C.new_class.instance_variable_get(:@name))
            assert_equal("D", C.new_class({}, "D").instance_variable_get(:@name))

            assert C.new_class.instance_variable_defined?(:@variables)
            assert_equal({}, C.new_class.instance_variable_get(:@variables))
            assert_equal({}, C.new_class({}, "D").instance_variable_get(:@variables))
          end

          should "respond to var" do
            assert !C.respond_to?(:var)

            assert C.new_class({:foo => "bar"}).respond_to?(:var)
            assert C.new_class({:foo => "bar"}, "D").respond_to?(:var)
            assert C.new_class.new({:foo => "bar"}).respond_to?(:var)
            assert C.new_class.new({:foo => "bar"}, "D").respond_to?(:var)

            assert_equal "bar", C.new_class({:foo => "bar"}).var(:foo)
            assert_equal "bar", C.new_class({:foo => "bar"}, "D").var(:foo)
            assert_equal "bar", C.new_class({:foo => "bar"}, "D").new.var(:foo)
            assert_equal "bar", C.new_class({:foo => "bar"}, "D").new.var(:foo)
          end

          should "be able to create instances" do
            assert C.new_class.new.is_a?(C)
            assert_equal C.name, C.new_class.new.class.name
            assert_equal C.name, C.new_class.new.class.to_s
            assert_equal "Hi, I am a C", C.new_class.new.greet

            assert C.new_class({}, "D").new.is_a?(C)
            assert_equal "D", C.new_class({}, "D").new.class.name
            assert_equal "D", C.new_class({}, "D").new.class.to_s
            assert_equal "Hi, I am a D", C.new_class({}, "D").new.greet
          end

          should "call when_defined" do
            klass = C.new_class({:translations => {:dutch => "Hallo, ik ben een {kind}"}})
            assert_equal "Hi, I am a C", klass.new.greet
            assert_equal "Hallo, ik ben een C", klass.new.greet(:dutch)

            klass = C.new_class({:translations => {:dutch => "Hallo, ik ben een {kind}"}}, "D")
            assert_equal "Hi, I am a D", klass.new.greet
            assert_equal "Hallo, ik ben een D", klass.new.greet(:dutch)
          end
        end
      end
    end
  end

end<commit_msg>Corrected class_test.rb<commit_after>require File.expand_path("../test_helper", __FILE__)

class ClassTest < Test::Unit::TestCase

  context "A class" do
    setup do
      class A
      end
      class B
        include NewClass
      end
    end

    context "when having included NewClass" do
      should "respond to new_class" do
        assert !A.respond_to?(:new_class)
        assert B.respond_to?(:new_class)
      end

      context "and having a superclass" do
        setup do
          class Greeter
            @@translations = {}
            def self.translate(language, translation)
              @@translations[language.to_sym] = translation
            end
            def self.translation(language)
              @@translations[language.to_sym]
            end
            translate :english, "Hi, I am a {kind}"
            def greet(language = :english)
              self.class.translation(language).gsub("{kind}", self.class.name.match(/[^:]+$/).to_s)
            end
          end
          class C < Greeter
            include NewClass
            when_defined do
              (var(:translations) || {}).each do |language, translation|
                translate language, translation
              end
            end
          end
        end

        should "behave as expected" do
          assert_equal "Hi, I am a C", C.new.greet
        end

        should "be able to return a new class" do
          assert_equal Class, C.new_class.class
        end

        context "the new class" do
          should "have @name and @variables defined" do
            assert C.new_class.instance_variable_defined?(:@name)
            assert_equal(C.name, C.new_class.instance_variable_get(:@name))
            assert_equal("D", C.new_class({}, "D").instance_variable_get(:@name))

            assert C.new_class.instance_variable_defined?(:@variables)
            assert_equal({}, C.new_class.instance_variable_get(:@variables))
            assert_equal({}, C.new_class({}, "D").instance_variable_get(:@variables))
          end

          should "respond to var" do
            assert !C.respond_to?(:var)

            assert C.new_class({:foo => "bar"}).respond_to?(:var)
            assert C.new_class({:foo => "bar"}, "D").respond_to?(:var)
            assert C.new_class({:foo => "bar"}).new.respond_to?(:var)
            assert C.new_class({:foo => "bar"}, "D").new.respond_to?(:var)

            assert_equal "bar", C.new_class({:foo => "bar"}).var(:foo)
            assert_equal "bar", C.new_class({:foo => "bar"}, "D").var(:foo)
            assert_equal "bar", C.new_class({:foo => "bar"}, "D").new.var(:foo)
            assert_equal "bar", C.new_class({:foo => "bar"}, "D").new.var(:foo)
          end

          should "be able to create instances" do
            assert C.new_class.new.is_a?(C)
            assert_equal C.name, C.new_class.new.class.name
            assert_equal C.name, C.new_class.new.class.to_s
            assert_equal "Hi, I am a C", C.new_class.new.greet

            assert C.new_class({}, "D").new.is_a?(C)
            assert_equal "D", C.new_class({}, "D").new.class.name
            assert_equal "D", C.new_class({}, "D").new.class.to_s
            assert_equal "Hi, I am a D", C.new_class({}, "D").new.greet
          end

          should "call when_defined" do
            klass = C.new_class({:translations => {:dutch => "Hallo, ik ben een {kind}"}})
            assert_equal "Hi, I am a C", klass.new.greet
            assert_equal "Hallo, ik ben een C", klass.new.greet(:dutch)

            klass = C.new_class({:translations => {:dutch => "Hallo, ik ben een {kind}"}}, "D")
            assert_equal "Hi, I am a D", klass.new.greet
            assert_equal "Hallo, ik ben een D", klass.new.greet(:dutch)
          end
        end
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.13393558523173604, 'fraction_numerical': 0.0, 'mean_word_length': 1.9851504493942946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '4379047', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2312, 'n_words': 564}