Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 133 lines (116 sloc) 2.822 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
require "jsduck/aggregator"
require "jsduck/source_file"
require "jsduck/meta_tag"
require "jsduck/meta_tag_registry"

describe JsDuck::Aggregator do

  class AuthorTag < JsDuck::MetaTag
    def initialize
      @name = "author"
      @key = :author
    end
  end

  class EmailTag < JsDuck::MetaTag
    def initialize
      @name = "email"
      @key = :email
    end
  end

  class LongTag < JsDuck::MetaTag
    def initialize
      @name = "long"
      @key = :long
      @multiline = true
    end
  end

  # Replace the global MetaTagRegistry instance with a custom one for
  # these tests. Afterwards set it back as it was before.
  before(:all) do
    @old_mtr = JsDuck::MetaTagRegistry.instance
    reg = JsDuck::MetaTagRegistry.new
    reg.register([AuthorTag.new, EmailTag.new, LongTag.new])
    JsDuck::MetaTagRegistry.instance = reg
  end

  after(:all) do
    JsDuck::MetaTagRegistry.instance = @old_mtr
  end


  def parse(string)
    agr = JsDuck::Aggregator.new
    agr.aggregate(JsDuck::SourceFile.new(string))
    agr.result
  end

  describe "class with meta-tags" do
    before do
      @doc = parse(<<-EOS)[0]
/**
* @class MyClass
* @author John Doe
* @author Steve Jobs
* @email Kill Bill
* Comment here.
*/
EOS
    end

    it "detects content of the defined tags" do
      @doc[:meta].should == {
        :author => ["John Doe", "Steve Jobs"],
        :email => ["Kill Bill"],
      }
    end
  end

  describe "class with multiline meta-tag" do
    before do
      @doc = parse(<<-EOS)[0]
/**
* @class MyClass
* Class docs.
* @long Some text
* on multiple
* lines.
* @author Steve Jobs
*/
EOS
    end

    it "detects tag content until next @tag" do
      @doc[:meta].should == {
        :long => ["Some text\non multiple\nlines."],
        :author => ["Steve Jobs"],
      }
    end
  end

  describe "meta-tag content containing {@link}" do
    before do
      @doc = parse(<<-EOS)[0]
/**
* @class MyClass
* @long Me {@link foo bar}
* @author Me {@link foo bar}
*/
EOS
    end

    it "includes {@link} as part of tag content" do
      @doc[:meta].should == {
        :long => ["Me {@link foo bar}"],
        :author => ["Me {@link foo bar}"],
      }
    end
  end

  describe "meta-tag inside class member" do
    before do
      @doc = parse(<<-EOS)[0]
/**
* @method foo
* Some description.
* @author John Doe
*/
EOS
    end

    it "detects the meta tag" do
      @doc[:meta].should == {
        :author => ["John Doe"],
      }
    end

    it "leaves member description as is" do
      @doc[:doc].should == "Some description."
    end
  end
end
Something went wrong with that request. Please try again.