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

Auto-detect 'false' as default value.

Previously when default value was 'false' it got ignored completely
as a result of just checking the truthiness of default value.  Now
explicitly checking that the value is not nil.
parent 8b585f85
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -383,7 +383,7 @@ module JsDuck
    end

    def make_default(ast)
      ast && to_value(ast) ? to_s(ast) : nil
      ast && to_value(ast) != nil ? to_s(ast) : nil
    end

    def make_value_type(ast)
+14 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ describe JsDuck::Aggregator do
    end
  end

  describe "cfg with explicit boolean default value" do
  describe "cfg with explicit boolean true default value" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
@@ -187,6 +187,19 @@ describe JsDuck::Aggregator do
    end
  end

  describe "cfg with explicit boolean false default value" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {Number} [foo=false] Something
         */
      EOS
    end
    it "has default value" do
      @doc[:default].should == "false"
    end
  end

  describe "cfg with explicit array default value" do
    before do
      @doc = parse(<<-EOS)[0]
+12 −0
Original line number Diff line number Diff line
@@ -109,6 +109,18 @@ describe "JsDuck::Ast detects property with" do
      detect("/** */ foo = 15;")[:default].should == "15"
    end

    it "assignment with number 0" do
      detect("/** */ foo = 0;")[:default].should == "0"
    end

    it "assignment with boolean true" do
      detect("/** */ foo = true;")[:default].should == "true"
    end

    it "assignment with boolean false" do
      detect("/** */ foo = false;")[:default].should == "false"
    end

    it "assignment with regex" do
      detect("/** */ foo = /abc/;")[:default].should == "/abc/"
    end