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

Converted auto-propert-type tests to RSpec.

parent 41aa9859
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -129,6 +129,60 @@ describe JsDuck::Aggregator do
    it_should_behave_like "cfg or property default type"
  end

  shared_examples_for "auto type" do
    it "should imply correct type" do
      @doc[:type].should == @type
    end
  end

  describe "@property with number in code" do
    before do
      @doc = parse("/** @property */ foo: 123")[0]
      @type = "Number"
    end
    it_should_behave_like "auto type"
  end

  describe "@property with regex in code" do
    before do
      @doc = parse("/** @property */ foo: /foo/i")[0]
      @type = "RegExp"
    end
    it_should_behave_like "auto type"
  end

  describe "@property with true in code" do
    before do
      @doc = parse("/** @property */ foo: true")[0]
      @type = "Boolean"
    end
    it_should_behave_like "auto type"
  end

  describe "@property with false in code" do
    before do
      @doc = parse("/** @property */ foo: false")[0]
      @type = "Boolean"
    end
    it_should_behave_like "auto type"
  end

  describe "@property with function in code" do
    before do
      @doc = parse("/** @property */ function foo() {}")[0]
      @type = "Function"
    end
    it_should_behave_like "auto type"
  end

  describe "@property with lambda in code" do
    before do
      @doc = parse("/** @property */ foo = function() {}")[0]
      @type = "Function"
    end
    it_should_behave_like "auto type"
  end

  describe "@property with @type" do
    before do
      @doc = parse(<<-EOS)[0]

test/tc_jsduck.rb

deleted100644 → 0
+0 −29
Original line number Diff line number Diff line
require "jsduck"
require "test/unit"

class TestJsDuck < Test::Unit::TestCase

  def test_implicit_property_type
    comment = "
/**
 * @property
 */
"
    docs = JsDuck.parse(comment + "foo: 'haha',")
    assert_equal("String", docs[0][:type])
    docs = JsDuck.parse(comment + "foo: 123,")
    assert_equal("Number", docs[0][:type])
    docs = JsDuck.parse(comment + "foo: /^123/,")
    assert_equal("RegExp", docs[0][:type])
    docs = JsDuck.parse(comment + "foo: true,")
    assert_equal("Boolean", docs[0][:type])
    docs = JsDuck.parse(comment + "foo: false,")
    assert_equal("Boolean", docs[0][:type])
    docs = JsDuck.parse(comment + "foo: function(){},")
    assert_equal("Function", docs[0][:type])
    docs = JsDuck.parse(comment + "function foo(){},")
    assert_equal("Function", docs[0][:type])
  end

end