<commit_before>require 'spec_helper'
require 'typed_attr'

describe TypedAttr do
  context "typecheck" do
    it "should not raise if it does match" do
      typecheck "1234", String
    end

    it "should raise TypeError if it does not match" do
      expect do
        typecheck 1234, String
      end.to raise_error(TypeError)
    end

    it "should handle multiple checks" do
      expect do
        typecheck 1234, Integer, Positive
      end.to_not raise_error

      expect do
        typecheck 1234, Integer, Negative
      end.to raise_error(TypeError)

      expect do
        typecheck 1234, String, Positive
      end.to raise_error(TypeError)
    end
  end

  context "typed_attr" do
    let(:cls) do
      Class.new do
        typed_attr String, :a, Numeric, :b
      end
    end

    it "should handle ()" do
      obj = cls.new
      obj.a.should == nil
      obj.b.should == nil
    end

    it "should handle (String)" do
      obj = cls.new("String")
      obj.a.should == "String"
      obj.b.should == nil
    end

    it "should handle (String, Fixnum)" do
      obj = cls.new("String", 123)
      obj.a.should == "String"
      obj.b.should == 123
    end

    it "should handle (String, Fixnum, ANYTHING)" do
      obj = cls.new("String", 123, Object.new)
      obj.a.should == "String"
      obj.b.should == 123
    end
  end
end<commit_msg>More tests.<commit_after>require 'spec_helper'
require 'typed_attr'

describe TypedAttr do
  context "typecheck" do
    it "should not raise if it does match" do
      typecheck "1234", String
    end

    it "should raise TypeError if it does not match" do
      expect do
        typecheck 1234, String
      end.to raise_error(TypeError)
    end

    it "should handle multiple checks" do
      expect do
        typecheck 1234, Integer, Positive
      end.to_not raise_error

      expect do
        typecheck 1234, Integer, Negative
      end.to raise_error(TypeError)

      expect do
        typecheck 1234, String, Positive
      end.to raise_error(TypeError)
    end
  end

  context "typed_attr" do
    Old = Class.new do
      typed_attr String, :a, Numeric, :b
    end
    New = Class.new do
      typed_attr a: String, b: Numeric
    end

    [ Old, New ].each do | cls |
      context "#{cls} syntax" do
    it "should handle ()" do
      obj = cls.new
      obj.a.should == nil
      obj.b.should == nil
    end

    it "should handle (String)" do
      obj = cls.new("String")
      obj.a.should == "String"
      obj.b.should == nil
    end

    it "should handle (String, Fixnum)" do
      obj = cls.new("String", 123)
      obj.a.should == "String"
      obj.b.should == 123
    end

    it "should handle (String, Fixnum, ANYTHING)" do
      obj = cls.new("String", 123, Object.new)
      obj.a.should == "String"
      obj.b.should == 123
    end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09395738735592037, 'fraction_numerical': 0.022354173943415996, 'mean_word_length': 2.086206896551724, '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': '6059525', 'n_tokens_mistral': 983, 'n_tokens_neox': 914, 'n_words': 302}