Commit 6d601fb2 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Detect optional parameters marked with (Optional).

Previously it was required that (optional) is always lowercase.
parent 31022fe9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -317,7 +317,7 @@ module JsDuck
          :name => ex[:name] || im[:name] || "",
          :doc => doc,
          # convert to boolean for JavaScript export, otherwise it's 0 or nil
          :optional => !!(doc =~ /\(optional\)/),
          :optional => !!(doc =~ /\(optional\)/i),
        }
      end
      params
+31 −0
Original line number Diff line number Diff line
@@ -236,6 +236,37 @@ describe JsDuck::Aggregator do
    it_should_behave_like "parameter types"
  end

  describe "method with optional parameters" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some function
         * @param {String} x (optional) my comment 1
         * @param {Number} y (Optional) my comment 2
         * @param {Number} y my comment 3 (optional)
         * @param {Number} z optional my comment 4
         */
        function foo(x, y) {}
      EOS
    end

    it "recognizes (optional) at the beginning of comment" do
      @doc[:params][0][:optional].should == true
    end

    it "recognizes mixed case (Optional) at the beginning of comment" do
      @doc[:params][1][:optional].should == true
    end

    it "recognizes (optional) anywhere inside comment" do
      @doc[:params][2][:optional].should == true
    end

    it "doesn't recognize 'optional' without parens" do
      @doc[:params][3][:optional].should == false
    end
  end

  describe "@return documenting return value" do
    before do
      @doc = parse(<<-EOS)[0]