Sha256: 5a9958a43ef613f831ebfa374413370a40bbf557595853fceb8f83058afa6b14

Contents?: true

Size: 1.93 KB

Versions: 5

Compression:

Stored size: 1.93 KB

Contents

require File.dirname(__FILE__) + "/spec_helper"

describe YARD::Handlers::C::ClassHandler do
  it "should register classes" do
    parse_init 'cFoo = rb_define_class("Foo", rb_cObject);'
    Registry.at('Foo').type.should == :class
  end

  it "should register classes under namespaces" do
    parse_init 'cFoo = rb_define_class_under(cBar, "Foo", rb_cObject);'
    Registry.at('Bar::Foo').type.should == :class
  end

  it "should remember symbol defined with class" do
    parse_init(<<-eof)
      cXYZ = rb_define_class("Foo", rb_cObject);
      rb_define_method(cXYZ, "bar", bar, 0);
    eof
    Registry.at('Foo').type.should == :class
    Registry.at('Foo#bar').should_not be_nil
  end

  it "should lookup superclass symbol name" do
    parse_init(<<-eof)
      cXYZ = rb_define_class("Foo", rb_cObject);
      cBar = rb_define_class("Bar", cXYZ);
    eof
    Registry.at('Bar').superclass.should == Registry.at('Foo')
  end

  it "should user superclass symbol name as proxy if not found" do
    parse_init(<<-eof)
      // cXYZ = rb_define_class("Foo", rb_cObject);
      cBar = rb_define_class("Bar", cXYZ);
    eof
    Registry.at('Bar').superclass.should == P('XYZ')
  end

  it "should not associate declaration comments as class docstring" do
    parse_init(<<-eof)
      /* Docstring! */
      cFoo = rb_define_class("Foo", cObject);
    eof
    Registry.at('Foo').docstring.should be_blank
  end

  it "should associate a file with the declaration" do
    parse_init(<<-eof)
      cFoo = rb_define_class("Foo", cObject);
    eof
    Registry.at('Foo').file.should == '(stdin)'
    Registry.at('Foo').line.should == 2
  end

  it "should properly handle Proxy superclasses" do
    parse_init <<-eof
      cFoo = rb_define_class_under(mFoo, "Bar", rb_cBar);
    eof
    Registry.at('Foo::Bar').type.should == :class
    Registry.at('Foo::Bar').superclass.should == P('Bar')
    P('Bar').should be_a(CodeObjects::Proxy)
    P('Bar').type.should == :class
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
challah-0.6.2 vendor/bundle/gems/yard-0.8.1/spec/handlers/c/class_handler_spec.rb
challah-0.6.1 vendor/bundle/gems/yard-0.8.1/spec/handlers/c/class_handler_spec.rb
challah-0.6.0 vendor/bundle/gems/yard-0.8.1/spec/handlers/c/class_handler_spec.rb
yard-0.8.1 spec/handlers/c/class_handler_spec.rb
yard-0.8.0 spec/handlers/c/class_handler_spec.rb