Sha256: 9f1beec5d2b32d514aec717600d1dadd462704f75a8fe25f8c1c357bc2fa3a4a

Contents?: true

Size: 1.98 KB

Versions: 21

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true
require File.dirname(__FILE__) + "/spec_helper"

RSpec.describe YARD::Handlers::C::ClassHandler do
  it "registers modules" do
    parse_init 'mFoo = rb_define_module("Foo");'
    expect(Registry.at('Foo').type).to eq :module
  end

  it "registers classes under namespaces" do
    parse_init <<-EOF
      mBar = rb_define_module("Bar");
      mFoo = rb_define_module_under(mBar, "Foo");
    EOF
    expect(Registry.at('Bar::Foo').type).to eq :module
  end

  it "remembers symbol defined with class" do
    parse_init(<<-eof)
      cXYZ = rb_define_module("Foo");
      rb_define_method(cXYZ, "bar", bar, 0);
    eof
    expect(Registry.at('Foo').type).to eq :module
    expect(Registry.at('Foo#bar')).not_to be nil
  end

  it "does not associate declaration comments as module docstring" do
    parse_init(<<-eof)
      /* Docstring! */
      mFoo = rb_define_module("Foo");
    eof
    expect(Registry.at('Foo').docstring).to be_blank
  end

  it "associates a file with the declaration" do
    parse_init(<<-eof)
      mFoo = rb_define_module("Foo");
    eof
    expect(Registry.at('Foo').file).to eq '(stdin)'
    expect(Registry.at('Foo').line).to eq 2
  end

  it "resolves namespace variable names across multiple files" do
    parse_multi_file_init(
      'mBar = rb_define_module_under(mFoo, "Bar");',
      'mFoo = rb_define_module("Foo");'
    )

    expect(Registry.at('Foo::Bar').type).to eq :module
  end

  it "raises undoc error if a class is defined under a namespace that cannot be resolved" do
    with_parser(:c) do
      undoc_error <<-eof
        void Init_Foo() {
          mFoo = rb_define_class_under(invalid, "Foo", rb_cObject);
        }
      eof
    end
  end unless ENV['LEGACY']

  it "raises undoc error if a module is defined under a namespace that cannot be resolved" do
    with_parser(:c) do
      undoc_error <<-eof
        void Init_Foo() {
          mFoo = rb_define_module_under(invalid, "Foo");
        }
      eof
    end
  end unless ENV['LEGACY']
end

Version data entries

21 entries across 20 versions & 4 rubygems

Version Path
yard-0.9.24 spec/handlers/c/module_handler_spec.rb
yard-0.9.23 spec/handlers/c/module_handler_spec.rb
yard-0.9.22 spec/handlers/c/module_handler_spec.rb
yard-0.9.21 spec/handlers/c/module_handler_spec.rb
yard-0.9.20 spec/handlers/c/module_handler_spec.rb
yard-0.9.19 spec/handlers/c/module_handler_spec.rb
yard-0.9.16 spec/handlers/c/module_handler_spec.rb
yard-0.9.15 spec/handlers/c/module_handler_spec.rb
yard-0.9.14 spec/handlers/c/module_handler_spec.rb
yard-0.9.13 spec/handlers/c/module_handler_spec.rb
yard-0.9.12 spec/handlers/c/module_handler_spec.rb
yard-0.9.11 spec/handlers/c/module_handler_spec.rb
yard-0.9.10 spec/handlers/c/module_handler_spec.rb
yard-0.9.9 spec/handlers/c/module_handler_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/spec/handlers/c/module_handler_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/spec/handlers/c/module_handler_spec.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/spec/handlers/c/module_handler_spec.rb
yard-0.9.8 spec/handlers/c/module_handler_spec.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/spec/handlers/c/module_handler_spec.rb
yard-0.9.7 spec/handlers/c/module_handler_spec.rb