From 462e1e0aaf6a29c698c8683a22e55f9ac9f51127 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Tue, 5 Oct 2010 12:40:54 +0300 Subject: [PATCH] Tests for all different function patterns. --- jsduck.rb | 4 +++- tc_jsduck.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/jsduck.rb b/jsduck.rb index 2342a2f8..0fec5ebe 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 ed1dbe00..25290287 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 -- GitLab