Commit a47f25f6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Added support for @singleton.

Both @singleton and @extends now imply that the preceding description
must be a description of a class.
parent 5e292172
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ module JsDuck
          at_class
        elsif look(/@extends\b/) then
          at_extends
        elsif look(/@singleton\b/) then
          at_singleton
        elsif look(/@event\b/) then
          at_event
        elsif look(/@function\b/) then
@@ -95,7 +97,7 @@ module JsDuck
    def at_extends
      match(/@extends/)
      unless @tags[:class]
        @tags[:class] = {:doc => ""}
        @tags[:class] = @tags[:default]
      end
      @current_tag = @tags[:class]
      skip_horiz_white
@@ -105,6 +107,17 @@ module JsDuck
      skip_white
    end

    # matches @singleton
    def at_singleton
      match(/@singleton/)
      unless @tags[:class]
        @tags[:class] = @tags[:default]
      end
      @current_tag = @tags[:class]
      @current_tag[:singleton] = true
      skip_white
    end

    # matches @event name ...
    def at_event
      match(/@event/)
+20 −0
Original line number Diff line number Diff line
@@ -46,10 +46,30 @@ class TestDocCommentParser < Test::Unit::TestCase
 * @class my.package.Foo
 * @extends my.Bar
 * Some docs.
 * @singleton
 */")
    assert_equal("my.package.Foo", doc[:class][:name])
    assert_equal("my.Bar", doc[:class][:extends])
    assert_equal("Some docs.", doc[:class][:doc])
    assert_equal(true, doc[:class][:singleton])
  end

  def test_extends_implies_class
    doc = parse_single("/**
 * Class description
 * @extends my.Bar
 */")
    assert_equal("my.Bar", doc[:class][:extends])
    assert_equal("Class description", doc[:class][:doc])
  end

  def test_singleton_implies_class
    doc = parse_single("/**
 * Class description
 * @singleton
 */")
    assert_equal(true, doc[:class][:singleton])
    assert_equal("Class description", doc[:class][:doc])
  end

  def test_event