Commit 361a9d54 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Improve consequtive comments merging algorithm.

Previusly this would have been merged into one comment:

    // some
    // comment

    // more text

Now it's treated as two comments - only the first two will get merged,
but not the last one below that's separated by a line.
parent 51fdb209
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -61,10 +61,10 @@ module JsDuck
    end

    # Two comments can be merged if they are both line-comments and
    # they are separated only by whitespace
    # they are separated only by whitespace (but no newlines)
    def mergeable?(c1, c2)
      if c1["type"] == "Line" && c2["type"] == "Line"
        /\A\s*\Z/ =~ @input.slice((c1["range"][1]+1)..(c2["range"][0]-1))
        /\A[ \t]*\Z/ =~ @input.slice((c1["range"][1])..(c2["range"][0]-1))
      else
        false
      end
+7 −5
Original line number Diff line number Diff line
@@ -157,21 +157,23 @@ describe JsDuck::JsParser do
    it_should_behave_like "three comments merged"
  end

  describe "parsing two separated line comments before one function" do
  describe "parsing three separated line comments before one function" do
    before do
      @docs = parse(<<-EOS)
        // Very
        // Three

        // Long
        // Separate


        // Comment
        // Comments
        function b() {
        }
      EOS
    end

    it_should_behave_like "three comments merged"
    it "gets treated as three separate comments" do
      @docs.length.should == 3
    end
  end

  describe "parsing 2 x two line comments before one function" do