Commit 0ab57c23 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Split @cfg and @property specs into two files.

Eliminate the aggregator_cfgs_and_properties_spec.rb and place the
@cfg tests to one file and @property tests to another.

Also remove some redundant tests.
parent e59b4d63
Loading
Loading
Loading
Loading
+121 −0
Original line number Diff line number Diff line
@@ -9,6 +9,127 @@ describe JsDuck::Aggregator do
    agr.result
  end

  shared_examples_for "example cfg" do
    it "creates cfg" do
      @doc[:tagname].should == :cfg
    end

    it "detects name" do
      @doc[:name].should == "foo"
    end

    it "detects type" do
      @doc[:type].should == "String"
    end

    it "takes documentation from doc-comment" do
      @doc[:doc].should == "Some documentation."
    end
  end

  describe "explicit @cfg" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {String} foo
         * Some documentation.
         */
      EOS
    end
    it_should_behave_like "example cfg"
  end

  describe "implicit @cfg" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg
         * Some documentation.
         */
        foo: "asdf" })
      EOS
    end
    it_should_behave_like "example cfg"
  end

  describe "typeless @cfg" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg
         * Some documentation.
         */
        foo: func() })
      EOS
    end

    it "default type is Object" do
      @doc[:type].should == "Object"
    end
  end

  describe "null @cfg" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg
         * Some documentation.
         */
        foo: null })
      EOS
    end

    it "default type is Object" do
      @doc[:type].should == "Object"
    end
  end

  describe "@cfg with dash in name" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {String} foo-bar
         * Some documentation.
         */
      EOS
    end

    it "detects the name" do
      @doc[:name].should == "foo-bar"
    end
  end

  describe "@cfg with uppercase name" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg {String} Foo
         */
        Foo: 12 })
      EOS
    end

    it "is detected as config" do
      @doc[:tagname].should == :cfg
    end
  end

  describe "@cfg with uppercase name after description" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * Docs here
         * @cfg {String} Foo
         */
        Foo: 12 })
      EOS
    end

    it "is detected as config" do
      @doc[:tagname].should == :cfg
    end
  end

  def parse_config_code(propertyName)
    parse(<<-EOS)[0][:members][:cfg]
      /**
+50 −183
Original line number Diff line number Diff line
@@ -9,52 +9,22 @@ describe JsDuck::Aggregator do
    agr.result
  end

  shared_examples_for "cfg" do
    it "creates cfg" do
      @doc[:tagname].should == :cfg
    end
  end

  shared_examples_for "property" do
  shared_examples_for "example property" do
    it "creates property" do
      @doc[:tagname].should == :property
    end
  end

  shared_examples_for "cfg or property" do
    it "takes documentation from doc-comment" do
      @doc[:doc].should == "Some documentation."
    end

    it "detects name" do
      @doc[:name].should == "foo"
    end
  end

  shared_examples_for "cfg or property default type" do
    it "default type is Object" do
      @doc[:type].should == "Object"
    end
  end

  shared_examples_for "cfg or property String type" do
    it "detects type" do
      @doc[:type].should == "String"
    end
  end

  describe "explicit @cfg" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {String} foo
         * Some documentation.
         */
      EOS
    it "takes documentation from doc-comment" do
      @doc[:doc].should == "Some documentation."
    end
    it_should_behave_like "cfg"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property String type"
  end

  describe "explicit @property" do
@@ -66,122 +36,122 @@ describe JsDuck::Aggregator do
         */
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property String type"
    it_should_behave_like "example property"
  end

  describe "implicit @cfg" do
  describe "implicit @property" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg
         * Some documentation.
         */
        foo: "asdf" })
      EOS
    end
    it_should_behave_like "cfg"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property String type"
    it_should_behave_like "example property"
  end

  describe "implicit @property" do
  describe "typeless @property" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @property
         * Some documentation.
         */
        foo: "asdf" })
        foo: func() })
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property String type"

    it "default type is Object" do
      @doc[:type].should == "Object"
    end
  end

  describe "typeless @cfg" do
  describe "@property with @type" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg
        /**
         * @property foo
         * @type String
         * Some documentation.
         */
        foo: func() })
      EOS
    end
    it_should_behave_like "cfg"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property default type"
    it_should_behave_like "example property"
  end

  describe "null @cfg" do
  describe "@type without @property" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg
         * @type String
         * Some documentation.
         */
        foo: null })
        MY_CONSTANT: true })
      EOS
    end
    it_should_behave_like "cfg"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property default type"

    it "detects property" do
      @doc[:tagname].should == :property
    end
    it "detects name" do
      @doc[:name].should == "MY_CONSTANT"
    end
  end

  describe "typeless @property" do
  describe "@property with 'this' in ident chain" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
        /**
         * @property
         * Some documentation.
         */
        foo: func() })
        this.foo = ""
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property default type"
    it_should_behave_like "example property"
  end

  describe "@cfg with dash in name" do
  describe "doc-comment before variable without assignment" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {String} foo-bar
         * Some documentation.
         */
        var foo;
      EOS
    end
    it "detects the name" do
      @doc[:name].should == "foo-bar"
    it "should detect the variable name" do
      @doc[:name].should == "foo"
    end
  end

  describe "@cfg with uppercase name" do
  describe "doc-comment before multiple variables" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg {String} Foo
        /**
         * Some documentation.
         */
        Foo: 12 })
        var foo, bar, baz;
      EOS
    end
    it_should_behave_like "cfg"
    it "should detect the first variable name" do
      @doc[:name].should == "foo"
    end
  end

  describe "@cfg with uppercase name after description" do
  describe "doc-comment before function call" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * Docs here
         * @cfg {String} Foo
        /**
         * Some documentation.
         */
        Foo: 12 })
        Ext.createAlias(MyClass, "foo", "bar");
      EOS
    end
    it_should_behave_like "cfg"
    it "should fail detecting name of the property" do
      @doc[:name].should == ""
    end
  end

  shared_examples_for "auto type" do
@@ -238,107 +208,4 @@ describe JsDuck::Aggregator do
    it_should_behave_like "auto type"
  end

  describe "@property with @type" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @property foo
         * @type String
         * Some documentation.
         */
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property String type"
  end

  describe "@type without @property" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @type String
         * Some documentation.
         */
        MY_CONSTANT: true })
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property String type"
    it "detects name" do
      @doc[:name].should == "MY_CONSTANT"
    end
  end

  describe "@property with 'this' in ident chain" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @property
         * Some documentation.
         */
        this.foo = ""
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property"
    it_should_behave_like "cfg or property String type"
  end

  describe "comma-first style" do
    before do
      @doc = parse(<<-EOS)[0]
      ({ blah: 100
        /**
         * Some documentation.
         */
        ,foo: "" })
      EOS
    end
    it_should_behave_like "property"
    it_should_behave_like "cfg or property"
  end

  describe "doc-comment before variable without assignment" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some documentation.
         */
        var foo;
      EOS
    end
    it "should detect the variable name" do
      @doc[:name].should == "foo"
    end
  end

  describe "doc-comment before multiple variables" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some documentation.
         */
        var foo, bar, baz;
      EOS
    end
    it "should detect the first variable name" do
      @doc[:name].should == "foo"
    end
  end

  describe "doc-comment before function call" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some documentation.
         */
        Ext.createAlias(MyClass, "foo", "bar");
      EOS
    end
    it "should fail detecting name of the property" do
      @doc[:name].should == ""
    end
  end

end