Commit 462e1e0a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Tests for all different function patterns.

parent ff438d9e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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
+58 −2
Original line number Diff line number Diff line
@@ -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