diff options
| author | Seba Gamboa <[email protected]> | 2015-09-25 18:01:14 -0300 |
|---|---|---|
| committer | Seba Gamboa <[email protected]> | 2015-09-25 18:01:14 -0300 |
| commit | 3a60c88a3b3dbd334e4769a6283fb90c0495c25b (patch) | |
| tree | de3d8ec187771d6e2d5f42da864c19ee6d69d890 /spec/handlers/c/source | |
| parent | 82e906d74dcc943d737ced7a6ebfee1e71a74aaf (diff) | |
| download | yard-mruby-3a60c88a3b3dbd334e4769a6283fb90c0495c25b.tar.gz yard-mruby-3a60c88a3b3dbd334e4769a6283fb90c0495c25b.zip | |
Sorting tons of stuff around
Diffstat (limited to 'spec/handlers/c/source')
| -rw-r--r-- | spec/handlers/c/source/class_handler_spec.rb | 41 | ||||
| -rw-r--r-- | spec/handlers/c/source/method_handler_spec.rb | 48 | ||||
| -rw-r--r-- | spec/handlers/c/source/module_handler_spec.rb | 30 | ||||
| -rw-r--r-- | spec/handlers/c/source/spec_helper.rb | 13 |
4 files changed, 132 insertions, 0 deletions
diff --git a/spec/handlers/c/source/class_handler_spec.rb b/spec/handlers/c/source/class_handler_spec.rb new file mode 100644 index 0000000..bfac3b6 --- /dev/null +++ b/spec/handlers/c/source/class_handler_spec.rb @@ -0,0 +1,41 @@ +require_relative 'spec_helper' + +describe YARD::MRuby::Handlers::C::Source::ClassHandler do + it "should register classes" do + parse_init 'cFoo = mrb_define_class(mrb, "Foo", mrb->object_class);' + + expect(Registry.at('Foo').type).to be :class + end + + it "should register classes under namespaces" do + parse_init 'cFoo = mrb_define_class_under(mrb, cBar, "Foo", rb_cObject);' + expect(Registry.at('Bar::Foo').type).to be :class + end + + it "should remember symbol defined with class" do + parse_init(<<-eof) + cXYZ = mrb_define_class(mrb, "Foo", mrb->object_class); + mrb_define_method(mrb, cXYZ, "bar", bar, MRB_ARGS_NONE()); + eof + expect(Registry.at('Foo').type).to be :class + expect(Registry.at('Foo#bar')).not_to be_nil + end + + it "should lookup superclass symbol name" do + parse_init(<<-eof) + cXYZ = mrb_define_class(mrb,"Foo", mrb->object_class); + cBar = mrb_define_class(mrb,"Bar", cXYZ); + eof + expect(Registry.at('Bar').superclass).to eq Registry.at('Foo') + end + + it "should associate declaration comments as class docstring" do + parse_init(<<-eof) + /* Docstring! */ + cFoo = mrb_define_class(mrb, "Foo", mrb->object_class); + eof + + expect(Registry.at('Foo').docstring).not_to be_blank + end + +end diff --git a/spec/handlers/c/source/method_handler_spec.rb b/spec/handlers/c/source/method_handler_spec.rb new file mode 100644 index 0000000..713e390 --- /dev/null +++ b/spec/handlers/c/source/method_handler_spec.rb @@ -0,0 +1,48 @@ +require_relative 'spec_helper' + +describe YARD::MRuby::Handlers::C::Source::MethodHandler do + it "should register methods" do + parse_init <<-eof + mFoo = mrb_define_module(mrb, "Foo"); + mrb_define_method(mrb, mFoo, "bar", bar, MRB_ARGS_NONE()); + eof + expect(Registry.at('Foo#bar')).not_to be_nil + expect(Registry.at('Foo#bar').visibility).to be :public + end + + it "should register singleton methods" do + parse_init <<-eof + mFoo = mrb_define_module("Foo"); + mrb_define_singleton_method(mrb, mFoo, "bar", bar, MRB_ARGS_NONE()); + eof + expect(Registry.at('Foo.bar')).not_to be_nil + expect(Registry.at('Foo.bar').visibility).to be :public + end + + it "should register module functions" do + parse <<-eof + /* DOCSTRING + * @return [String] foo! + */ + static mrb_value bar(mrb_state *mrb, mrb_value self) { x(); y(); z(); } + + void mrb_foo_gem_init(mrb_state *mrb) { + mFoo = mrb_define_module(mrb, "Foo"); + mrb_define_module_function(mrb, mFoo, "bar", bar, MRB_ARGS_NONE()); + } + eof + bar_c = Registry.at('Foo.bar') + bar_i = Registry.at('Foo#bar') + + expect(bar_c).to be_module_function + expect(bar_c.visibility).to be :public + expect(bar_c.docstring).to eq "DOCSTRING" + expect(bar_c.tag(:return).object).to eq bar_c + expect(bar_c.source).to eq "static mrb_value bar(mrb_state *mrb, mrb_value self) { x(); y(); z(); }" + expect(bar_i).not_to be_module_function + expect(bar_i.visibility).to be :private + expect(bar_i.docstring).to eq "DOCSTRING" + expect(bar_i.tag(:return).object).to eq bar_i + expect(bar_i.source).to eq bar_c.source + end +end diff --git a/spec/handlers/c/source/module_handler_spec.rb b/spec/handlers/c/source/module_handler_spec.rb new file mode 100644 index 0000000..fd08ae6 --- /dev/null +++ b/spec/handlers/c/source/module_handler_spec.rb @@ -0,0 +1,30 @@ +require_relative 'spec_helper' + +describe YARD::MRuby::Handlers::C::Source::ModuleHandler do + it "should register modules" do + parse_init 'mFoo = mrb_define_module(mrb, "Foo");' + expect(Registry.at('Foo').type).to be :module + end + + it "should register modules under namespaces" do + parse_init 'mFoo = mrb_define_module_under(mrb, mBar, "Foo");' + expect(Registry.at('Bar::Foo').type).to be :module + end + + it "should remember symbol defined with module" do + parse_init(<<-eof) + cXYZ = mrb_define_module(mrb, "Foo"); + mrb_define_method(mrb, cXYZ, "bar", bar, 0); + eof + expect(Registry.at('Foo').type).to be :module + expect(Registry.at('Foo#bar')).not_to be_nil + end + + it "should associate declaration comments as module docstring" do + parse_init(<<-eof) + /* Docstring! */ + mFoo = mrb_define_module(mrb, "Foo"); + eof + expect(Registry.at('Foo').docstring).not_to be_blank + end +end diff --git a/spec/handlers/c/source/spec_helper.rb b/spec/handlers/c/source/spec_helper.rb new file mode 100644 index 0000000..76844a4 --- /dev/null +++ b/spec/handlers/c/source/spec_helper.rb @@ -0,0 +1,13 @@ +require_relative '../spec_helper' + +def parse(src, file = '(stdin)') + YARD::Registry.clear + parser = YARD::Parser::SourceParser.new(:source) + parser.file = file + parser.parse(StringIO.new(src)) +end + +def parse_init(src) + YARD::Registry.clear + YARD.parse_string("void mrb_foo_gem_init(mrb_state *mrb) {\n#{src}\n}", :source) +end |
