diff --git a/jsduck.rb b/jsduck.rb index 2342a2f8dde316ce020c78f7f3a933edde73640f..0fec5ebe6226a9cd573d9fc8502363676674a8dc 100755 --- a/jsduck.rb +++ b/jsduck.rb @@ -158,7 +158,9 @@ module JsDuck lex.next # var name = function(){ doc.function = lex.next - elsif lex.look(:keyword, ":", "function") || lex.look(:string, ":", "function") then + elsif lex.look(:keyword, "=", "function") || + lex.look(:keyword, ":", "function") || + lex.look(:string, ":", "function") then # name: function(){ doc.function = lex.next end diff --git a/tc_jsduck.rb b/tc_jsduck.rb index ed1dbe00f33f9786cf04d9e73d4f04a258b40398..25290287b7ef64c3f161e1562dff83d1e76c6e90 100644 --- a/tc_jsduck.rb +++ b/tc_jsduck.rb @@ -15,9 +15,65 @@ class TestJsDuck < Test::Unit::TestCase assert_equal([], JsDuck.parse("/* ") ) end - def test_single_doc_comment - assert_equal("Hello", JsDuck.parse("/**\nHello\n*/")[0].doc ) + def test_function + docs = JsDuck.parse(" +/** + * Some function + */ +function foo() { +} +") + assert_equal("Some function", docs[0].doc) + assert_equal("foo", docs[0].function) end + def test_function_with_var + docs = JsDuck.parse(" +/** + */ +var foo = function() { +} +") + assert_equal("foo", docs[0].function) + end + + def test_function_without_var + docs = JsDuck.parse(" +/** + */ +foo = function() { +} +") + assert_equal("foo", docs[0].function) + end + + def test_function_in_object_literal + docs = JsDuck.parse(" +/** + */ +foo: function() { +} +") + assert_equal("foo", docs[0].function) + end + + def test_function_in_object_literal_string + docs = JsDuck.parse(" +/** + */ +'foo': function() { +} +") + assert_equal("foo", docs[0].function) + end + + def test_function_private + docs = JsDuck.parse(" +// no doc-comment for this function +function foo() { +} +") + assert_equal(0, docs.length) + end end