Loading doc_comment.rb +4 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ module JsDuck def initialize(tags) @tags = tags [:class, :function, :event, :cfg].each do |name| [:class, :method, :event, :cfg].each do |name| if @tags[name] then @root_tag = @tags[name] end Loading @@ -15,16 +15,16 @@ module JsDuck # Sets the name property of the default at-tag. # # When name begins with uppercase it's considered to be class # name, otherwise a function name. # name, otherwise a method name. # # When the name consists of several parts like foo.bar.baz, then # the parts should be passed as multiple arguments. def set_default_name(*name_chain) name = name_chain.last tagname = (name[0,1] == name[0,1].upcase) ? :class : :function tagname = (name[0,1] == name[0,1].upcase) ? :class : :method if !@root_tag then @root_tag = {:name => (tagname == :function) ? name : name_chain.join(".")} @root_tag = {:name => (tagname == :method) ? name : name_chain.join(".")} @root_tag[:doc] = @tags[:default][:doc] @tags[tagname] = @root_tag @tags.delete(:default) Loading doc_comment_parser.rb +8 −8 Original line number Diff line number Diff line Loading @@ -51,8 +51,8 @@ module JsDuck at_singleton elsif look(/@event\b/) then at_event elsif look(/@function\b/) then at_function elsif look(/@method\b/) then at_method elsif look(/@constructor\b/) then at_constructor elsif look(/@param\b/) then Loading Loading @@ -129,10 +129,10 @@ module JsDuck skip_white end # matches @function name ... def at_function match(/@function/) set_root_tag(:function, {:doc => ""}) # matches @method name ... def at_method match(/@method/) set_root_tag(:method, {:doc => ""}) skip_horiz_white if look(/\w/) then @current_tag[:name] = ident Loading @@ -141,10 +141,10 @@ module JsDuck end # matches @constructor ... # Which is equivalent of: @function constructor ... # Which is equivalent of: @method constructor ... def at_constructor match(/@constructor/) set_root_tag(:function, {:doc => "", :name => "constructor"}) set_root_tag(:method, {:doc => "", :name => "constructor"}) skip_white end Loading tc_doc_comment_parser.rb +12 −12 Original line number Diff line number Diff line Loading @@ -7,16 +7,16 @@ class TestDocCommentParser < Test::Unit::TestCase return JsDuck::DocCommentParser.new.parse(doc)[0] end def test_function def test_method doc = parse_single("/** * @function foo * @method foo * Some docs. * @param {Number} x doc for x * @param {Integer} y doc for y * @return {String} resulting value */") assert_equal("foo", doc[:function][:name]) assert_equal("Some docs.", doc[:function][:doc]) assert_equal("foo", doc[:method][:name]) assert_equal("Some docs.", doc[:method][:doc]) assert_equal(2, doc[:param].length) Loading @@ -37,8 +37,8 @@ class TestDocCommentParser < Test::Unit::TestCase * @constructor * Some docs. */") assert_equal("constructor", doc[:function][:name]) assert_equal("Some docs.", doc[:function][:doc]) assert_equal("constructor", doc[:method][:name]) assert_equal("Some docs.", doc[:method][:doc]) end def test_class Loading Loading @@ -93,7 +93,7 @@ class TestDocCommentParser < Test::Unit::TestCase def test_long_docs doc = parse_single("/** * @function foo * @method foo * * Some docs. * Loading @@ -106,7 +106,7 @@ class TestDocCommentParser < Test::Unit::TestCase * long * docs. */") assert_equal("Some docs.\n\nNice docs.", doc[:function][:doc]) assert_equal("Some docs.\n\nNice docs.", doc[:method][:doc]) assert_equal("some\nlong\ndocs.", doc[:param][0][:doc]) assert_equal("more\nlong\ndocs.", doc[:return][:doc]) end Loading @@ -124,13 +124,13 @@ class TestDocCommentParser < Test::Unit::TestCase assert_equal(nil, doc[:return][:type]) end def test_nameless_function def test_nameless_method doc = parse_single("/** * @function * @method * Comment for this func. */") assert_equal(nil, doc[:function][:name]) assert_equal("Comment for this func.", doc[:function][:doc]) assert_equal(nil, doc[:method][:name]) assert_equal("Comment for this func.", doc[:method][:doc]) end def test_nameless_class Loading tc_jsduck.rb +25 −25 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ require "test/unit" class TestJsDuck < Test::Unit::TestCase def test_function def test_method docs = JsDuck.parse(" /** * Some function Loading @@ -11,67 +11,67 @@ class TestJsDuck < Test::Unit::TestCase function foo(x) { } ") assert_equal("Some function", docs[0][:function][:doc]) assert_equal("foo", docs[0][:function][:name]) assert_equal("Some function", docs[0][:method][:doc]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_with_var def test_method_with_var docs = JsDuck.parse(" /** */ var foo = function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_without_var def test_method_without_var docs = JsDuck.parse(" /** */ foo = function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_in_object_literal def test_method_in_object_literal docs = JsDuck.parse(" /** */ foo: function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_in_object_literal_string def test_method_in_object_literal_string docs = JsDuck.parse(" /** */ 'foo': function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_in_prototype def test_method_in_prototype docs = JsDuck.parse(" /** */ Some.Long.prototype.foo = function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_private def test_method_private docs = JsDuck.parse(" // no doc-comment for this function function foo() { Loading @@ -80,31 +80,31 @@ function foo() { assert_equal([], docs) end def test_explicit_function_doc def test_explicit_method_doc docs = JsDuck.parse(" /** * @function hello * @method hello * Just some function */ eval('hello = new Function();'); ") assert_equal("hello", docs[0][:function][:name]) assert_equal("Just some function", docs[0][:function][:doc]) assert_equal("hello", docs[0][:method][:name]) assert_equal("Just some function", docs[0][:method][:doc]) end def test_explicit_function_doc_overrides_implicit_code def test_explicit_method_doc_overrides_implicit_code docs = JsDuck.parse(" /** * @function hello * @method hello * Just some function */ function goodby(){} ") assert_equal("hello", docs[0][:function][:name]) assert_equal("Just some function", docs[0][:function][:doc]) assert_equal("hello", docs[0][:method][:name]) assert_equal("Just some function", docs[0][:method][:doc]) end def test_implicit_function_parameters def test_implicit_method_parameters docs = JsDuck.parse(" /** */ Loading @@ -116,7 +116,7 @@ function f(foo, bar, baz){} assert_equal("baz", params[2][:name]) end def test_explicit_function_parameters_override_implicit_ones def test_explicit_method_parameters_override_implicit_ones docs = JsDuck.parse(" /** * @param {String} x Loading Loading @@ -170,7 +170,7 @@ function Bar(){} assert_equal("My class", docs[0][:class][:doc]) end def test_uppercase_function_name_implies_class_name def test_uppercase_method_name_implies_class_name docs = JsDuck.parse(" /** * My class Loading Loading
doc_comment.rb +4 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ module JsDuck def initialize(tags) @tags = tags [:class, :function, :event, :cfg].each do |name| [:class, :method, :event, :cfg].each do |name| if @tags[name] then @root_tag = @tags[name] end Loading @@ -15,16 +15,16 @@ module JsDuck # Sets the name property of the default at-tag. # # When name begins with uppercase it's considered to be class # name, otherwise a function name. # name, otherwise a method name. # # When the name consists of several parts like foo.bar.baz, then # the parts should be passed as multiple arguments. def set_default_name(*name_chain) name = name_chain.last tagname = (name[0,1] == name[0,1].upcase) ? :class : :function tagname = (name[0,1] == name[0,1].upcase) ? :class : :method if !@root_tag then @root_tag = {:name => (tagname == :function) ? name : name_chain.join(".")} @root_tag = {:name => (tagname == :method) ? name : name_chain.join(".")} @root_tag[:doc] = @tags[:default][:doc] @tags[tagname] = @root_tag @tags.delete(:default) Loading
doc_comment_parser.rb +8 −8 Original line number Diff line number Diff line Loading @@ -51,8 +51,8 @@ module JsDuck at_singleton elsif look(/@event\b/) then at_event elsif look(/@function\b/) then at_function elsif look(/@method\b/) then at_method elsif look(/@constructor\b/) then at_constructor elsif look(/@param\b/) then Loading Loading @@ -129,10 +129,10 @@ module JsDuck skip_white end # matches @function name ... def at_function match(/@function/) set_root_tag(:function, {:doc => ""}) # matches @method name ... def at_method match(/@method/) set_root_tag(:method, {:doc => ""}) skip_horiz_white if look(/\w/) then @current_tag[:name] = ident Loading @@ -141,10 +141,10 @@ module JsDuck end # matches @constructor ... # Which is equivalent of: @function constructor ... # Which is equivalent of: @method constructor ... def at_constructor match(/@constructor/) set_root_tag(:function, {:doc => "", :name => "constructor"}) set_root_tag(:method, {:doc => "", :name => "constructor"}) skip_white end Loading
tc_doc_comment_parser.rb +12 −12 Original line number Diff line number Diff line Loading @@ -7,16 +7,16 @@ class TestDocCommentParser < Test::Unit::TestCase return JsDuck::DocCommentParser.new.parse(doc)[0] end def test_function def test_method doc = parse_single("/** * @function foo * @method foo * Some docs. * @param {Number} x doc for x * @param {Integer} y doc for y * @return {String} resulting value */") assert_equal("foo", doc[:function][:name]) assert_equal("Some docs.", doc[:function][:doc]) assert_equal("foo", doc[:method][:name]) assert_equal("Some docs.", doc[:method][:doc]) assert_equal(2, doc[:param].length) Loading @@ -37,8 +37,8 @@ class TestDocCommentParser < Test::Unit::TestCase * @constructor * Some docs. */") assert_equal("constructor", doc[:function][:name]) assert_equal("Some docs.", doc[:function][:doc]) assert_equal("constructor", doc[:method][:name]) assert_equal("Some docs.", doc[:method][:doc]) end def test_class Loading Loading @@ -93,7 +93,7 @@ class TestDocCommentParser < Test::Unit::TestCase def test_long_docs doc = parse_single("/** * @function foo * @method foo * * Some docs. * Loading @@ -106,7 +106,7 @@ class TestDocCommentParser < Test::Unit::TestCase * long * docs. */") assert_equal("Some docs.\n\nNice docs.", doc[:function][:doc]) assert_equal("Some docs.\n\nNice docs.", doc[:method][:doc]) assert_equal("some\nlong\ndocs.", doc[:param][0][:doc]) assert_equal("more\nlong\ndocs.", doc[:return][:doc]) end Loading @@ -124,13 +124,13 @@ class TestDocCommentParser < Test::Unit::TestCase assert_equal(nil, doc[:return][:type]) end def test_nameless_function def test_nameless_method doc = parse_single("/** * @function * @method * Comment for this func. */") assert_equal(nil, doc[:function][:name]) assert_equal("Comment for this func.", doc[:function][:doc]) assert_equal(nil, doc[:method][:name]) assert_equal("Comment for this func.", doc[:method][:doc]) end def test_nameless_class Loading
tc_jsduck.rb +25 −25 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ require "test/unit" class TestJsDuck < Test::Unit::TestCase def test_function def test_method docs = JsDuck.parse(" /** * Some function Loading @@ -11,67 +11,67 @@ class TestJsDuck < Test::Unit::TestCase function foo(x) { } ") assert_equal("Some function", docs[0][:function][:doc]) assert_equal("foo", docs[0][:function][:name]) assert_equal("Some function", docs[0][:method][:doc]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_with_var def test_method_with_var docs = JsDuck.parse(" /** */ var foo = function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_without_var def test_method_without_var docs = JsDuck.parse(" /** */ foo = function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_in_object_literal def test_method_in_object_literal docs = JsDuck.parse(" /** */ foo: function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_in_object_literal_string def test_method_in_object_literal_string docs = JsDuck.parse(" /** */ 'foo': function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_in_prototype def test_method_in_prototype docs = JsDuck.parse(" /** */ Some.Long.prototype.foo = function(x) { } ") assert_equal("foo", docs[0][:function][:name]) assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end def test_function_private def test_method_private docs = JsDuck.parse(" // no doc-comment for this function function foo() { Loading @@ -80,31 +80,31 @@ function foo() { assert_equal([], docs) end def test_explicit_function_doc def test_explicit_method_doc docs = JsDuck.parse(" /** * @function hello * @method hello * Just some function */ eval('hello = new Function();'); ") assert_equal("hello", docs[0][:function][:name]) assert_equal("Just some function", docs[0][:function][:doc]) assert_equal("hello", docs[0][:method][:name]) assert_equal("Just some function", docs[0][:method][:doc]) end def test_explicit_function_doc_overrides_implicit_code def test_explicit_method_doc_overrides_implicit_code docs = JsDuck.parse(" /** * @function hello * @method hello * Just some function */ function goodby(){} ") assert_equal("hello", docs[0][:function][:name]) assert_equal("Just some function", docs[0][:function][:doc]) assert_equal("hello", docs[0][:method][:name]) assert_equal("Just some function", docs[0][:method][:doc]) end def test_implicit_function_parameters def test_implicit_method_parameters docs = JsDuck.parse(" /** */ Loading @@ -116,7 +116,7 @@ function f(foo, bar, baz){} assert_equal("baz", params[2][:name]) end def test_explicit_function_parameters_override_implicit_ones def test_explicit_method_parameters_override_implicit_ones docs = JsDuck.parse(" /** * @param {String} x Loading Loading @@ -170,7 +170,7 @@ function Bar(){} assert_equal("My class", docs[0][:class][:doc]) end def test_uppercase_function_name_implies_class_name def test_uppercase_method_name_implies_class_name docs = JsDuck.parse(" /** * My class Loading