summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/yard/handlers.rb2
-rw-r--r--lib/yard/handlers/c.rb5
-rw-r--r--lib/yard/handlers/c/mruby_base.rb12
-rw-r--r--lib/yard/handlers/c/mruby_class_handler.rb (renamed from lib/yard/mruby/handlers/source/class_handler.rb)8
-rw-r--r--lib/yard/handlers/c/mruby_method_handler.rb (renamed from lib/yard/mruby/handlers/source/method_handler.rb)5
-rw-r--r--lib/yard/handlers/c/mruby_module_handler.rb (renamed from lib/yard/mruby/handlers/source/module_handler.rb)0
-rw-r--r--lib/yard/handlers/header.rb (renamed from lib/yard/mruby/handlers/header.rb)0
-rw-r--r--lib/yard/handlers/header/base.rb (renamed from lib/yard/mruby/handlers/header/base.rb)0
-rw-r--r--lib/yard/handlers/header/define_handler.rb (renamed from lib/yard/mruby/handlers/header/define_handler.rb)0
-rw-r--r--lib/yard/handlers/header/function_handler.rb (renamed from lib/yard/mruby/handlers/header/function_handler.rb)0
-rw-r--r--lib/yard/handlers/header/header_handler.rb (renamed from lib/yard/mruby/handlers/header/header_handler.rb)0
-rw-r--r--lib/yard/mruby.rb2
-rw-r--r--lib/yard/mruby/handlers.rb2
-rw-r--r--lib/yard/mruby/handlers/source.rb5
-rw-r--r--lib/yard/mruby/handlers/source/base.rb18
-rw-r--r--spec/handlers/c/mruby_class_handler_spec.rb32
-rw-r--r--spec/handlers/c/spec_helper.rb13
-rw-r--r--spec/handlers/spec_helper.rb31
-rw-r--r--spec/spec_helper.rb93
-rw-r--r--spec/yard/mruby_spec.rb11
20 files changed, 195 insertions, 44 deletions
diff --git a/lib/yard/handlers.rb b/lib/yard/handlers.rb
new file mode 100644
index 0000000..41a1f73
--- /dev/null
+++ b/lib/yard/handlers.rb
@@ -0,0 +1,2 @@
+require_relative 'handlers/c'
+#require_relative 'handlers/header'
diff --git a/lib/yard/handlers/c.rb b/lib/yard/handlers/c.rb
new file mode 100644
index 0000000..61c4943
--- /dev/null
+++ b/lib/yard/handlers/c.rb
@@ -0,0 +1,5 @@
+require_relative 'c/mruby_base'
+require_relative 'c/mruby_class_handler'
+# require_relative 'c/mruby_module_handler'
+require_relative 'c/mruby_method_handler'
+
diff --git a/lib/yard/handlers/c/mruby_base.rb b/lib/yard/handlers/c/mruby_base.rb
new file mode 100644
index 0000000..83c237a
--- /dev/null
+++ b/lib/yard/handlers/c/mruby_base.rb
@@ -0,0 +1,12 @@
+module YARD::Handlers::C
+ class MRubyBase < Base
+ DEFAULT_NAMESPACES = {
+ 'mrb->object_class' => 'Object'
+ }
+
+ def namespace_for_variable(var)
+ return DEFAULT_NAMESPACES[var] if DEFAULT_NAMESPACES[var]
+ super
+ end
+ end
+end
diff --git a/lib/yard/mruby/handlers/source/class_handler.rb b/lib/yard/handlers/c/mruby_class_handler.rb
index 185aaa6..9e3d1f5 100644
--- a/lib/yard/mruby/handlers/source/class_handler.rb
+++ b/lib/yard/handlers/c/mruby_class_handler.rb
@@ -1,7 +1,7 @@
-module YARD::MRuby::Handlers::Source
- class ClassHandler < Base
+module YARD::Handlers::C
+ class MRubyClassHandler < MRubyBase
- TOP_LEVEL_CLASS = /\*([\w]+)\s*=\s*mrb_define_class\s*
+ TOP_LEVEL_CLASS = /([\w]+)\s*=\s*mrb_define_class\s*
\(
\s*\w+\s*,
\s*"(\w+)"\s*,
@@ -9,7 +9,7 @@ module YARD::MRuby::Handlers::Source
\)
/mx
- NAMESPACED_CLASS = /\*([\w]+)\s*=\s*mrb_define_class_under\s*
+ NAMESPACED_CLASS = /([\w]+)\s*=\s*mrb_define_class_under\s*
\(
\s*\w+\s*,
\s*(\w+)\s*,
diff --git a/lib/yard/mruby/handlers/source/method_handler.rb b/lib/yard/handlers/c/mruby_method_handler.rb
index f3eab8c..01fb345 100644
--- a/lib/yard/mruby/handlers/source/method_handler.rb
+++ b/lib/yard/handlers/c/mruby_method_handler.rb
@@ -1,5 +1,5 @@
-module YARD::MRuby::Handlers::Source
- class MethodHandler < Base
+module YARD::Handlers::C
+ class MRubyMethodHandler < MRubyBase
MATCH1 = /mrb_define_method\s*
\(
\s*\w+\s*,
@@ -12,7 +12,6 @@ module YARD::MRuby::Handlers::Source
statement_class BodyStatement
process do
- puts statement.inspect
statement.source.scan(MATCH1) do |var_name, name, func_name|
handle_method(nil, var_name, name, func_name)
end
diff --git a/lib/yard/mruby/handlers/source/module_handler.rb b/lib/yard/handlers/c/mruby_module_handler.rb
index c9243ac..c9243ac 100644
--- a/lib/yard/mruby/handlers/source/module_handler.rb
+++ b/lib/yard/handlers/c/mruby_module_handler.rb
diff --git a/lib/yard/mruby/handlers/header.rb b/lib/yard/handlers/header.rb
index bb39563..bb39563 100644
--- a/lib/yard/mruby/handlers/header.rb
+++ b/lib/yard/handlers/header.rb
diff --git a/lib/yard/mruby/handlers/header/base.rb b/lib/yard/handlers/header/base.rb
index 35859f7..35859f7 100644
--- a/lib/yard/mruby/handlers/header/base.rb
+++ b/lib/yard/handlers/header/base.rb
diff --git a/lib/yard/mruby/handlers/header/define_handler.rb b/lib/yard/handlers/header/define_handler.rb
index e69de29..e69de29 100644
--- a/lib/yard/mruby/handlers/header/define_handler.rb
+++ b/lib/yard/handlers/header/define_handler.rb
diff --git a/lib/yard/mruby/handlers/header/function_handler.rb b/lib/yard/handlers/header/function_handler.rb
index e69de29..e69de29 100644
--- a/lib/yard/mruby/handlers/header/function_handler.rb
+++ b/lib/yard/handlers/header/function_handler.rb
diff --git a/lib/yard/mruby/handlers/header/header_handler.rb b/lib/yard/handlers/header/header_handler.rb
index e69de29..e69de29 100644
--- a/lib/yard/mruby/handlers/header/header_handler.rb
+++ b/lib/yard/handlers/header/header_handler.rb
diff --git a/lib/yard/mruby.rb b/lib/yard/mruby.rb
index d94cd78..683d3c5 100644
--- a/lib/yard/mruby.rb
+++ b/lib/yard/mruby.rb
@@ -1,3 +1,3 @@
require_relative "mruby/version"
require_relative "mruby/code_objects"
-require_relative "mruby/handlers"
+require_relative "handlers"
diff --git a/lib/yard/mruby/handlers.rb b/lib/yard/mruby/handlers.rb
deleted file mode 100644
index cb0c898..0000000
--- a/lib/yard/mruby/handlers.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-require_relative 'handlers/source'
-require_relative 'handlers/header'
diff --git a/lib/yard/mruby/handlers/source.rb b/lib/yard/mruby/handlers/source.rb
deleted file mode 100644
index af8b0db..0000000
--- a/lib/yard/mruby/handlers/source.rb
+++ /dev/null
@@ -1,5 +0,0 @@
- require_relative 'source/base'
- require_relative 'source/class_handler'
- require_relative 'source/module_handler'
- require_relative 'source/method_handler'
-
diff --git a/lib/yard/mruby/handlers/source/base.rb b/lib/yard/mruby/handlers/source/base.rb
deleted file mode 100644
index 4578079..0000000
--- a/lib/yard/mruby/handlers/source/base.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-module YARD
- module MRuby
- module Handlers
- module Source
- class Base < YARD::Handlers::C::Base
- DEFAULT_NAMESPACES = {
- 'mrb->object_class' => 'Object'
- }
-
- def namespace_for_variable(var)
- return DEFAULT_NAMESPACES[var] if DEFAULT_NAMESPACES[var]
- super
- end
- end
- end
- end
- end
-end
diff --git a/spec/handlers/c/mruby_class_handler_spec.rb b/spec/handlers/c/mruby_class_handler_spec.rb
new file mode 100644
index 0000000..521ad62
--- /dev/null
+++ b/spec/handlers/c/mruby_class_handler_spec.rb
@@ -0,0 +1,32 @@
+require_relative 'spec_helper'
+
+describe YARD::Handlers::C::MRubyClassHandler 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
+
+end
diff --git a/spec/handlers/c/spec_helper.rb b/spec/handlers/c/spec_helper.rb
new file mode 100644
index 0000000..9424e3e
--- /dev/null
+++ b/spec/handlers/c/spec_helper.rb
@@ -0,0 +1,13 @@
+require_relative '../spec_helper'
+
+def parse(src, file = '(stdin)')
+ YARD::Registry.clear
+ parser = YARD::Parser::SourceParser.new(:c)
+ 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}", :c)
+end
diff --git a/spec/handlers/spec_helper.rb b/spec/handlers/spec_helper.rb
new file mode 100644
index 0000000..1eba194
--- /dev/null
+++ b/spec/handlers/spec_helper.rb
@@ -0,0 +1,31 @@
+require_relative '../spec_helper'
+require 'stringio'
+
+def undoc_error(code)
+ lambda { StubbedSourceParser.parse_string(code) }.should raise_error(Parser::UndocumentableError)
+end
+
+def with_parser(parser_type, &block)
+ tmp = StubbedSourceParser.parser_type
+ StubbedSourceParser.parser_type = parser_type
+ yield
+ StubbedSourceParser.parser_type = tmp
+end
+
+class StubbedProcessor < YARD::Handlers::Processor
+ def process(statements)
+ statements.each_with_index do |stmt, index|
+ find_handlers(stmt).each do |handler|
+ handler.new(self, stmt).process
+ end
+ end
+ end
+end
+
+class StubbedSourceParser < YARD::Parser::SourceParser
+ StubbedSourceParser.parser_type = :ruby
+ def post_process
+ post = StubbedProcessor.new(self)
+ post.process(@parser.enumerator)
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9a01ce9..dab8698 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,2 +1,95 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
+
+require 'yard'
require 'yard/mruby'
+
+def parse_file(file, thisfile = __FILE__, log_level = log.level, ext = '.rb.txt')
+ Registry.clear
+ path = File.join(File.dirname(thisfile), 'examples', file.to_s + ext)
+ YARD::Parser::SourceParser.parse(path, [], log_level)
+end
+
+def described_in_docs(klass, meth, file = nil)
+ YARD::Tags::Library.define_tag "RSpec Specification", :it, :with_raw_title_and_text
+
+ # Parse the file (could be multiple files)
+ if file
+ filename = File.join(YARD::ROOT, file)
+ YARD::Parser::SourceParser.new.parse(filename)
+ else
+ underscore = klass.class_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase.gsub('::', '/')
+ $".find_all {|p| p.include? underscore }.each do |filename|
+ next unless File.exist? filename
+ YARD::Parser::SourceParser.new.parse(filename)
+ end
+ end
+
+ # Get the object
+ objname = klass.name + (meth[0,1] == '#' ? meth : '::' + meth)
+ obj = Registry.at(objname)
+ raise "Cannot find object #{objname} described by spec." unless obj
+ raise "#{obj.path} has no @it tags to spec." unless obj.has_tag? :it
+
+ # Run examples
+ describe(klass, meth) do
+ obj.tags(:it).each do |it|
+ path = File.relative_path(YARD::ROOT, obj.file)
+ it(it.name + " (from #{path}:#{obj.line})") do
+ begin
+ eval(it.text)
+ rescue => e
+ e.set_backtrace(["#{path}:#{obj.line}:in @it tag specification"])
+ raise e
+ end
+ end
+ end
+ end
+end
+
+def docspec(objname = self.class.description, klass = self.class.described_type)
+ # Parse the file (could be multiple files)
+ underscore = klass.class_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase.gsub('::', '/')
+ $".find_all {|p| p.include? underscore }.each do |filename|
+ filename = File.join(YARD::ROOT, filename)
+ next unless File.exist? filename
+ YARD::Parser::SourceParser.new.parse(filename)
+ end
+
+ # Get the object
+ objname = klass.name + objname if objname =~ /^[^A-Z]/
+ obj = Registry.at(objname)
+ raise "Cannot find object #{objname} described by spec." unless obj
+ raise "#{obj.path} has no @example tags to spec." unless obj.has_tag? :example
+
+ # Run examples
+ obj.tags(:example).each do |exs|
+ exs.text.split(/\n/).each do |ex|
+ begin
+ hash = eval("{ #{ex} }")
+ hash.keys.first.should == hash.values.first
+ rescue => e
+ raise e, "#{e.message}\nInvalid spec example in #{objname}:\n\n\t#{ex}\n"
+ end
+ end
+ end
+end
+
+module Kernel
+ require 'cgi'
+
+ def p(*args)
+ puts args.map {|arg| CGI.escapeHTML(arg.inspect) }.join("<br/>\n")
+ args.first
+ end
+
+ def puts(str = '')
+ STDOUT.puts str + "<br/>\n"
+ str
+ end
+end if ENV['TM_APP_PATH']
+
+RSpec.configure do |config|
+ config.before(:each) { log.io = StringIO.new }
+end
+
+Registry = YARD::Registry
diff --git a/spec/yard/mruby_spec.rb b/spec/yard/mruby_spec.rb
deleted file mode 100644
index 3b6f756..0000000
--- a/spec/yard/mruby_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'spec_helper'
-
-describe Yard::Mruby do
- it 'has a version number' do
- expect(Yard::Mruby::VERSION).not_to be nil
- end
-
- it 'does something useful' do
- expect(false).to eq(true)
- end
-end