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

Detection of singleton in Ast class.

parent cdc48f6f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ module JsDuck
          cls[:uses] = make_requires(cfg["uses"])
          cls[:alternateClassNames] = make_requires(cfg["alternateClassName"])
          cls[:mixins] = make_mixins(cfg["mixins"])
          cls[:singleton] = make_singleton(cfg["singleton"])
        end
      end

@@ -191,6 +192,10 @@ module JsDuck
      return classes.all? {|c| c.is_a? String } ? classes : []
    end

    def make_singleton(cfg_value)
      cfg_value && to_value(cfg_value) == true
    end

    def make_method(name, ast=nil)
      return {
        :tagname => :method,
+30 −0
Original line number Diff line number Diff line
@@ -230,4 +230,34 @@ describe "JsDuck::Ast detects class with" do
      EOS
    end
  end

  describe "singleton in" do
    it "Ext.define() with singleton:true" do
      detect(<<-EOS)[:singleton].should == true
        /** */
        Ext.define('MyClass', {
            singleton: true
        });
      EOS
    end
  end

  describe "no singleton in" do
    it "Ext.define() with singleton:false" do
      detect(<<-EOS)[:singleton].should_not == true
        /** */
        Ext.define('MyClass', {
            singleton: false
        });
      EOS
    end

    it "Ext.define() without singleton" do
      detect(<<-EOS)[:singleton].should_not == true
        /** */
        Ext.define('MyClass', {
        });
      EOS
    end
  end
end