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.6 spec/handlers/c/module_handler_spec.rb